-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
83 lines (72 loc) · 2.5 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var boards = [];
var tags = [];
$(document).ready(function() {
$('.js-example-basic-multiple').select2();
//make the AJAX request, dataType is set to json
//meaning we are expecting JSON data in response from the server
$.ajax({
type: "GET",
url: "https://www.pintag.app/api/v1/boards?user_email=dondraper@s.cooper.com&user_token=3kJG55W4tTe5TnqKf1WS",
//if received a response from the server
success: function(response) {
//array of boards
console.log(response);
response["boards"].forEach((item) => {
boards.push(item);
});
response["tags"].forEach((item) => {
tags.push(item);
});
var boardNames = [];
var tagNames = [];
for (var i = 0; i < boards.length; i++) {//begin for loop
boardNames.push(`<option value="${boards[i].id}">` + boards[i].name + "</option>")
}
for (var i = 0; i < tags.length; i++) {//begin for loop
tagNames.push(`<option value="${tags[i].id}">` + tags[i].name + "</option>")
}
document.getElementById("board").innerHTML = boardNames.join("");
document.getElementById("tags").innerHTML = tagNames.join("");
},
});
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
let url = tabs[0].url;
console.log(url);
document.getElementById("link").value = url;
});
//Stops the submit request
$("#myAjaxRequestForm").submit(function(e) {
e.preventDefault();
});
//checks for the button click event
$("#myButton").click(function(e) {
dataArray = $("#myAjaxRequestForm").serializeArray();
board_id = parseInt(dataArray[0].value);
console.log(dataArray);
dataArray.shift();
newHash = {};
tags = [];
dataArray.map((item) => {
if (item.name == "tags") {
tags.push(item.value);
newHash[item.name] = tags;
} else {
newHash[item.name] = item.value;
}
});
var body = {"content": newHash};
console.log(body);
//make the AJAX request, dataType is set to json
//meaning we are expecting JSON data in response from the server
$.ajax({
type: "POST",
url: `https://www.pintag.app/api/v1/boards/${board_id}/contents?user_email=dondraper@s.cooper.com&user_token=3kJG55W4tTe5TnqKf1WS`,
data: body,
//if received a response from the server
success: function(response) {
console.log(response);
$("#ajaxResponse").append("saved successfully!");
},
});
});
});