2014-11-25 22:43:48 +01:00
|
|
|
var ajaxCallCount = 0;
|
|
|
|
|
|
|
|
function increaseAjaxCallCount() {
|
|
|
|
ajaxCallCount++;
|
|
|
|
if (ajaxCallCount - 1 === 0) {
|
|
|
|
updateLoadingAnimation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function decreaseAjaxCallCount() {
|
|
|
|
if (ajaxCallCount > 0) {
|
|
|
|
ajaxCallCount--;
|
|
|
|
updateLoadingAnimation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateLoadingAnimation() {
|
|
|
|
if (ajaxCallCount === 0) {
|
|
|
|
$("#add_form_loading").css("visibility", "hidden");
|
|
|
|
} else {
|
|
|
|
$("#add_form_loading").css("visibility", "visible");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-14 14:24:13 +02:00
|
|
|
$(document).ready(function () {
|
2014-11-25 22:43:48 +01:00
|
|
|
$(".submit").click(function () {
|
|
|
|
increaseAjaxCallCount();
|
2015-07-14 14:24:13 +02:00
|
|
|
|
|
|
|
var endpoint = 'bookmark';
|
|
|
|
var method = 'POST';
|
|
|
|
var id = '';
|
|
|
|
if($('#bookmarkID').length > 0) {
|
|
|
|
endpoint += '/'+ $('#bookmarkID').val();
|
|
|
|
method = 'PUT';
|
|
|
|
id = '&record_id=' + $('#bookmarkID').val();
|
|
|
|
}
|
|
|
|
|
|
|
|
var tags = '';
|
|
|
|
$('.tagit-choice .tagit-label').each(function() {
|
|
|
|
tags += '&item[tags][]='+$(this).text();
|
|
|
|
});
|
|
|
|
var dataString = 'url=' + $("input#url").val() + '&description=' +
|
|
|
|
$("textarea#description").val() + '&title=' + $("input#title").val() + tags + id;
|
2014-11-25 22:43:48 +01:00
|
|
|
$.ajax({
|
2015-07-14 14:24:13 +02:00
|
|
|
type: method,
|
|
|
|
url: endpoint,
|
2014-11-25 22:43:48 +01:00
|
|
|
data: dataString,
|
|
|
|
complete: function () {
|
|
|
|
decreaseAjaxCallCount();
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
if (data.status === 'success') {
|
2015-08-24 15:04:03 -04:00
|
|
|
OC.dialogs.message("Bookmark added.", "Success", undefined, [], undefined, true)
|
|
|
|
_.delay(function() {
|
|
|
|
window.close();
|
|
|
|
}, 1e3);
|
2014-11-25 22:43:48 +01:00
|
|
|
} else {
|
|
|
|
OC.dialogs.alert(t("bookmarks", "Some Error happened."),
|
|
|
|
t("bookmarks", "Error"), null, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
2015-07-14 14:24:13 +02:00
|
|
|
|
|
|
|
$.get('tag', function (data) {
|
|
|
|
$('.tags').tagit({
|
|
|
|
allowSpaces: true,
|
|
|
|
availableTags: data,
|
|
|
|
placeholderText: t('bookmark', 'Tags')
|
|
|
|
});
|
|
|
|
});
|
2014-11-25 22:43:48 +01:00
|
|
|
});
|