Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function attachEvents() {
- const id = "kid_rkFRw1QGl";
- const user = "guest";
- const pass = "guest";
- const b64 = btoa(`${user}:${pass}`);
- const headers = {Authorization: `Basic ${b64}`};
- const url = 'https://baas.kinvey.com/apdata/${id}/biggestCatches';
- $('.add').click(function () {
- let el = '#addForm';
- let angler = $(el).find(`.angler`).val();
- let weight = $(el).find(`.weight`).val();
- let species = $(el).find(`.species`).val();
- let location = $(el).find(`.location`).val();
- let bait = $(el).find(`.bait`).val();
- let captureTime = $(el).find(`.captureTime`).val();
- let data = JSON.stringify({
- "angler": angler,
- "weight": weight,
- "species": species,
- "location": location,
- "bait": bait,
- "captureTime": captureTime
- });
- $.ajax({
- method: 'POST',
- url: url,
- data: data,
- headers: headers,
- contentType: 'application/json'
- })
- .then(load)
- .catch(err);
- function clear() {
- $(el).find(`.angler`).val('');
- $(el).find(`.weight`).val('');
- $(el).find(`.species`).val('');
- $(el).find(`.location`).val('');
- $(el).find(`.bait`).val('');
- $(el).find(`.captureTime`).val('');
- }
- });
- $('.load').click(load);
- function load() {
- $('#catches').empty();
- $.ajax({
- method: 'GET',
- url: url,
- contentType: 'application/json'
- })
- .then(ape)
- .catch(err);
- }
- function ape(dt) {
- for (let v of dt) {
- let HTML = getCatchHtml(v);
- HTML.find('.delete').click(del);
- HTML.find('.update').click(up);
- $('#catches').append(HTML);
- }
- }
- function del() {
- let p = $(this).parent();
- let i = parent.attr('data-id');
- $.ajax({
- method: "DELETE",
- url: url + i,
- headers: headers,
- contentType: 'application/json'
- })
- .then();
- p.remove();
- }
- function up() {
- let p = $(this).parent();
- let i = p.attr('data-id');
- let cap = createNewCapture(p);
- $.ajax({
- method: "PUT",
- url: url + i,
- headers: headers,
- data: cap,
- contentType: 'application/json'
- })
- .then()
- }
- function err() {
- console.log('ERROR');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement