|
1
|
|
|
var ajaxCallCount = 0; |
|
2
|
|
|
|
|
3
|
|
|
function increaseAjaxCallCount() { |
|
4
|
|
|
ajaxCallCount++; |
|
5
|
|
|
if (ajaxCallCount - 1 === 0) { |
|
6
|
|
|
updateLoadingAnimation(); |
|
7
|
|
|
} |
|
8
|
|
|
} |
|
9
|
|
|
|
|
10
|
|
|
function decreaseAjaxCallCount() { |
|
11
|
|
|
if (ajaxCallCount > 0) { |
|
12
|
|
|
ajaxCallCount--; |
|
13
|
|
|
updateLoadingAnimation(); |
|
14
|
|
|
} |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
function updateLoadingAnimation() { |
|
18
|
|
|
if (ajaxCallCount === 0) { |
|
19
|
|
|
$("#add_form_loading").css("visibility", "hidden"); |
|
20
|
|
|
} else { |
|
21
|
|
|
$("#add_form_loading").css("visibility", "visible"); |
|
22
|
|
|
} |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
$(document).ready(function () { |
|
26
|
|
|
$(".submit").click(function () { |
|
27
|
|
|
increaseAjaxCallCount(); |
|
28
|
|
|
|
|
29
|
|
|
var endpoint = 'bookmark'; |
|
30
|
|
|
var method = 'POST'; |
|
31
|
|
|
var id = ''; |
|
32
|
|
|
if($('#bookmarkID').length > 0) { |
|
33
|
|
|
endpoint += '/'+ $('#bookmarkID').val(); |
|
34
|
|
|
method = 'PUT'; |
|
35
|
|
|
id = '&record_id=' + $('#bookmarkID').val(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
var tags = ''; |
|
39
|
|
|
$('.tagit-choice .tagit-label').each(function() { |
|
40
|
|
|
tags += '&item[tags][]='+$(this).text(); |
|
41
|
|
|
}); |
|
42
|
|
|
var dataString = 'url=' + $("input#url").val() + '&description=' + |
|
43
|
|
|
$("textarea#description").val() + '&title=' + $("input#title").val() + tags + id; |
|
44
|
|
|
$.ajax({ |
|
45
|
|
|
type: method, |
|
46
|
|
|
url: endpoint, |
|
47
|
|
|
data: dataString, |
|
48
|
|
|
complete: function () { |
|
49
|
|
|
decreaseAjaxCallCount(); |
|
50
|
|
|
}, |
|
51
|
|
|
success: function (data) { |
|
52
|
|
|
if (data.status === 'success') { |
|
53
|
|
|
OC.dialogs.message("Bookmark added.", "Success", undefined, [], undefined, true) |
|
|
|
|
|
|
54
|
|
|
_.delay(function() { |
|
55
|
|
|
window.close(); |
|
56
|
|
|
}, 1e3); |
|
57
|
|
|
} else { |
|
58
|
|
|
OC.dialogs.alert(t("bookmarks", "Some Error happened."), |
|
59
|
|
|
t("bookmarks", "Error"), null, true); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
}); |
|
63
|
|
|
return false; |
|
64
|
|
|
}); |
|
65
|
|
|
|
|
66
|
|
|
$.get('tag', function (data) { |
|
67
|
|
|
$('.tags').tagit({ |
|
68
|
|
|
allowSpaces: true, |
|
69
|
|
|
availableTags: data, |
|
70
|
|
|
placeholderText: t('bookmark', 'Tags') |
|
71
|
|
|
}); |
|
72
|
|
|
}); |
|
73
|
|
|
}); |
|
74
|
|
|
|
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.
Further Readings: