2014-11-25 22:43:48 +01:00
|
|
|
var bookmarksPage = 0;
|
|
|
|
var bookmarksLoading = false;
|
2012-08-13 21:58:46 +02:00
|
|
|
var dialog;
|
2014-11-25 22:43:48 +01:00
|
|
|
var bookmarksSorting = 'bookmarks_sorting_recent';
|
2013-02-19 00:04:29 +01:00
|
|
|
var fullTags = [];
|
2014-11-25 22:43:48 +01:00
|
|
|
var ajaxCallCount = 0;
|
|
|
|
|
2015-12-18 23:59:00 +01:00
|
|
|
var allTagsCollection;
|
|
|
|
var availableTagsCollection;
|
|
|
|
var selectedTagsCollection;
|
|
|
|
var availableTagsList;
|
|
|
|
var selectedTagsList;
|
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
$(document).ready(function () {
|
2015-12-18 23:59:00 +01:00
|
|
|
allTagsCollection = new OCA.Bookmarks.TagCollection();
|
|
|
|
availableTagsCollection = new OCA.Bookmarks.TagCollection();
|
|
|
|
selectedTagsCollection = new OCA.Bookmarks.TagCollection();
|
|
|
|
availableTagsList = new OCA.Bookmarks.TagListView({
|
|
|
|
model: availableTagsCollection,
|
|
|
|
id: 'availableTagsList'
|
|
|
|
});
|
|
|
|
selectedTagsList = new OCA.Bookmarks.TagListView({
|
|
|
|
model: selectedTagsCollection,
|
|
|
|
id: 'selectedTagsList'
|
|
|
|
});
|
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
getTags();
|
2012-11-05 22:12:00 +01:00
|
|
|
watchUrlField();
|
2012-11-03 22:46:42 +01:00
|
|
|
$('#bm_import').change(attachSettingEvent);
|
2012-11-05 22:12:00 +01:00
|
|
|
$('#add_url').on('keydown keyup change click', watchUrlField);
|
2014-11-25 22:43:48 +01:00
|
|
|
$('#app-settings').on('click keydown', toggleSettings);
|
2012-11-03 22:46:42 +01:00
|
|
|
$('#bm_export').click(exportBm);
|
2014-11-25 22:43:48 +01:00
|
|
|
$('#emptycontent-setting').click(function () {
|
|
|
|
if (!$('#app-settings').hasClass('open')) {
|
|
|
|
$('#app-settings').click();
|
2012-11-07 00:52:14 +01:00
|
|
|
}
|
|
|
|
});
|
2012-11-06 22:05:30 +01:00
|
|
|
$('.bookmarks_list').scroll(updateOnBottom).empty();
|
2012-06-28 11:40:42 +02:00
|
|
|
$('#tag_filter input').tagit({
|
|
|
|
allowSpaces: true,
|
|
|
|
availableTags: fullTags,
|
2012-11-07 00:05:52 +01:00
|
|
|
onTagFinishRemoved: filterTagsChanged,
|
2014-06-12 18:20:16 +02:00
|
|
|
placeholderText: t('bookmarks', 'Filter by tag')
|
2012-06-28 11:40:42 +02:00
|
|
|
}).tagit('option', 'onTagAdded', filterTagsChanged);
|
2015-12-17 23:48:12 +01:00
|
|
|
$('.navigationAllBookmarks').click(resetTagFilter);
|
|
|
|
|
2011-08-15 22:05:07 +02:00
|
|
|
getBookmarks();
|
|
|
|
});
|
2012-07-03 14:14:30 +02:00
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
function getTags() {
|
|
|
|
jQuery.ajax({
|
|
|
|
url: 'tag',
|
|
|
|
success: function (result) {
|
|
|
|
fullTags = result;
|
2015-12-18 23:59:00 +01:00
|
|
|
console.warn(fullTags);
|
2014-11-25 22:43:48 +01:00
|
|
|
},
|
|
|
|
async: false
|
|
|
|
});
|
|
|
|
}
|
2012-07-31 22:48:11 +02:00
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
var formatString = (function () {
|
|
|
|
var replacer = function (context) {
|
|
|
|
return function (s, name) {
|
2012-07-31 22:48:11 +02:00
|
|
|
return context[name];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
return function (input, context) {
|
2012-07-31 22:48:11 +02:00
|
|
|
return input.replace(/\{(\w+)\}/g, replacer(context));
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
function increaseAjaxCallCount() {
|
|
|
|
ajaxCallCount++;
|
|
|
|
if (ajaxCallCount - 1 === 0) {
|
|
|
|
updateLoadingAnimation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function decreaseAjaxCallCount() {
|
|
|
|
if (ajaxCallCount > 0) {
|
|
|
|
ajaxCallCount--;
|
|
|
|
updateLoadingAnimation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateLoadingAnimation() {
|
|
|
|
if (ajaxCallCount === 0) {
|
2015-07-10 14:26:22 +02:00
|
|
|
$('#bookmark_add_submit').removeClass('icon-loading-small');
|
|
|
|
$('#bookmark_add_submit').addClass('icon-add');
|
2014-11-25 22:43:48 +01:00
|
|
|
} else {
|
2015-07-10 14:26:22 +02:00
|
|
|
$('#bookmark_add_submit').removeClass('icon-add');
|
|
|
|
$('#bookmark_add_submit').addClass('icon-loading-small');
|
2014-11-25 22:43:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function watchClickInSetting(e) {
|
|
|
|
if ($('#app-settings').find($(e.target)).length === 0) {
|
2012-11-05 23:53:46 +01:00
|
|
|
toggleSettings();
|
|
|
|
}
|
|
|
|
}
|
2014-11-05 10:07:39 +01:00
|
|
|
|
|
|
|
function checkURL(url) {
|
2014-11-25 22:43:48 +01:00
|
|
|
if (url.substring(0, 3) === "htt") {
|
2014-11-05 10:07:39 +01:00
|
|
|
return url;
|
|
|
|
}
|
2014-11-25 22:43:48 +01:00
|
|
|
return "http://" + url;
|
2014-11-05 10:07:39 +01:00
|
|
|
}
|
|
|
|
|
2012-11-05 23:53:46 +01:00
|
|
|
function toggleSettings() {
|
2014-11-25 22:43:48 +01:00
|
|
|
if ($('#app-settings').hasClass('open')) { //Close
|
|
|
|
$('#app-settings').switchClass("open", "");
|
2012-11-22 19:21:43 +01:00
|
|
|
$('body').unbind('click', watchClickInSetting);
|
2012-11-05 23:53:46 +01:00
|
|
|
}
|
2014-11-25 22:43:48 +01:00
|
|
|
else {
|
|
|
|
$('#app-settings').switchClass("", "open");
|
|
|
|
$('body').bind('click', watchClickInSetting);
|
2012-11-05 23:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
2012-06-29 14:12:29 +02:00
|
|
|
function addFilterTag(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
$('#tag_filter input').tagit('createTag', $(this).text());
|
2012-06-28 11:40:42 +02:00
|
|
|
}
|
|
|
|
|
2015-12-17 23:48:12 +01:00
|
|
|
function resetTagFilter() {
|
|
|
|
$('#tag_filter input').tagit('removeAll');
|
|
|
|
}
|
|
|
|
|
2012-06-28 00:43:11 +02:00
|
|
|
function updateTagsList(tag) {
|
2015-12-17 23:48:12 +01:00
|
|
|
var selectedTags = $('#tag_filter input').tagit('assignedTags');
|
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
var html = tmpl("tag_tmpl", tag);
|
2012-10-21 13:37:30 +02:00
|
|
|
$('.tag_list').append(html);
|
2015-12-17 23:48:12 +01:00
|
|
|
$('.tag_list li').each(function(){
|
|
|
|
var tagName = $(this).find('a span').text();
|
|
|
|
var inArrayResult = $.inArray(tagName, selectedTags);
|
2015-12-18 23:59:00 +01:00
|
|
|
// console.warn(inArrayResult);
|
|
|
|
// console.warn(tagName);
|
|
|
|
// console.log(this);
|
2015-12-17 23:48:12 +01:00
|
|
|
if(inArrayResult > -1) {
|
|
|
|
$(this).addClass('active');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
var $entry = $('.navigationTagTemplate')
|
|
|
|
.clone();
|
|
|
|
$entry
|
|
|
|
.removeClass('hidden')
|
|
|
|
.removeClass('navigationTagTemplate')
|
|
|
|
.addClass('navigationTagEntry');
|
|
|
|
$entry.find('a').text(tag.tag);
|
|
|
|
$entry.find('.count').text(tag.nbr);
|
|
|
|
$entry.appendTo($('#navigation-list'));
|
2012-06-28 00:43:11 +02:00
|
|
|
}
|
2012-06-28 11:40:42 +02:00
|
|
|
|
|
|
|
function filterTagsChanged()
|
|
|
|
{
|
2014-11-25 22:43:48 +01:00
|
|
|
$('#bookmarkFilterTag').val($('#tag_filter input').val());
|
2012-06-28 11:40:42 +02:00
|
|
|
$('.bookmarks_list').empty();
|
2014-11-25 22:43:48 +01:00
|
|
|
bookmarksPage = 0;
|
2012-06-28 11:40:42 +02:00
|
|
|
getBookmarks();
|
|
|
|
}
|
2011-08-15 22:05:07 +02:00
|
|
|
function getBookmarks() {
|
2014-11-25 22:43:48 +01:00
|
|
|
if (bookmarksLoading) {
|
2011-08-15 22:05:07 +02:00
|
|
|
//have patience :)
|
|
|
|
return;
|
2012-07-02 15:24:26 +02:00
|
|
|
}
|
2014-11-25 22:43:48 +01:00
|
|
|
increaseAjaxCallCount();
|
|
|
|
bookmarksLoading = true;
|
2012-07-02 15:49:20 +02:00
|
|
|
//Update Rel Tags if first page
|
2014-11-25 22:43:48 +01:00
|
|
|
if (bookmarksPage === 0) {
|
2012-06-29 15:50:19 +02:00
|
|
|
|
2012-07-02 15:49:20 +02:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
2014-11-25 22:43:48 +01:00
|
|
|
url: 'bookmark',
|
|
|
|
data: {type: 'rel_tags', tag: $('#bookmarkFilterTag').val(), page: bookmarksPage, sort: bookmarksSorting},
|
|
|
|
success: function (tags) {
|
2012-07-02 15:49:20 +02:00
|
|
|
$('.tag_list').empty();
|
2014-11-25 22:43:48 +01:00
|
|
|
for (var i in tags.data) {
|
2012-07-02 15:49:20 +02:00
|
|
|
updateTagsList(tags.data[i]);
|
|
|
|
}
|
|
|
|
$('.tag_list .tag_edit').click(renameTag);
|
|
|
|
$('.tag_list .tag_delete').click(deleteTag);
|
2015-12-17 23:48:12 +01:00
|
|
|
$('.navigationTagEntry a').click(addFilterTag);
|
2012-06-29 15:50:19 +02:00
|
|
|
|
2015-12-17 23:48:12 +01:00
|
|
|
$('.with-menu a').bind('click', addFilterTag);
|
2012-07-02 15:49:20 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-08-15 22:05:07 +02:00
|
|
|
$.ajax({
|
2012-07-02 15:24:26 +02:00
|
|
|
type: 'GET',
|
2014-11-25 22:43:48 +01:00
|
|
|
url: 'bookmark',
|
|
|
|
data: {type: 'bookmark', tag: $('#bookmarkFilterTag').val(), page: bookmarksPage, sort: bookmarksSorting},
|
|
|
|
complete: function () {
|
|
|
|
decreaseAjaxCallCount();
|
|
|
|
},
|
|
|
|
success: function (bookmarks) {
|
2012-03-01 20:46:34 +01:00
|
|
|
if (bookmarks.data.length) {
|
2014-11-25 22:43:48 +01:00
|
|
|
bookmarksPage += 1;
|
2012-03-01 20:46:34 +01:00
|
|
|
}
|
2011-08-15 22:05:07 +02:00
|
|
|
$('.bookmark_link').unbind('click', recordClick);
|
|
|
|
$('.bookmark_delete').unbind('click', delBookmark);
|
2012-06-29 14:12:29 +02:00
|
|
|
$('.bookmark_edit').unbind('click', editBookmark);
|
2012-04-15 15:53:30 +02:00
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
for (var i in bookmarks.data) {
|
2011-08-15 22:05:07 +02:00
|
|
|
updateBookmarksList(bookmarks.data[i]);
|
|
|
|
}
|
2012-11-05 21:48:28 +01:00
|
|
|
checkEmpty();
|
2011-10-08 13:54:45 +02:00
|
|
|
|
2011-08-15 22:05:07 +02:00
|
|
|
$('.bookmark_link').click(recordClick);
|
|
|
|
$('.bookmark_delete').click(delBookmark);
|
2012-06-29 14:12:29 +02:00
|
|
|
$('.bookmark_edit').click(editBookmark);
|
2012-04-15 15:53:30 +02:00
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
bookmarksLoading = false;
|
2012-03-01 20:46:34 +01:00
|
|
|
if (bookmarks.data.length) {
|
2014-11-25 22:43:48 +01:00
|
|
|
updateOnBottom();
|
2012-03-01 20:46:34 +01:00
|
|
|
}
|
2011-08-15 22:05:07 +02:00
|
|
|
}
|
2012-04-15 15:53:30 +02:00
|
|
|
});
|
2011-08-15 22:05:07 +02:00
|
|
|
}
|
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
function watchUrlField() {
|
2012-11-05 22:12:00 +01:00
|
|
|
var form = $('#add_form');
|
|
|
|
var el = $('#add_url');
|
|
|
|
var button = $('#bookmark_add_submit');
|
|
|
|
form.unbind('submit');
|
2014-11-25 22:43:48 +01:00
|
|
|
if (!acceptUrl(el.val())) {
|
|
|
|
form.bind('submit', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2012-11-05 22:12:00 +01:00
|
|
|
button.addClass('disabled');
|
|
|
|
}
|
2014-11-25 22:43:48 +01:00
|
|
|
else {
|
2012-11-05 22:12:00 +01:00
|
|
|
button.removeClass('disabled');
|
2014-11-25 22:43:48 +01:00
|
|
|
form.bind('submit', addBookmark);
|
2012-11-05 22:12:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function acceptUrl(url) {
|
2014-11-25 22:43:48 +01:00
|
|
|
return url.replace(/^\s+/g, '').replace(/\s+$/g, '') !== '';
|
2012-11-05 22:12:00 +01:00
|
|
|
}
|
|
|
|
|
2012-06-29 14:12:29 +02:00
|
|
|
function addBookmark(event) {
|
2012-11-04 23:55:03 +01:00
|
|
|
event.preventDefault();
|
2014-11-25 22:43:48 +01:00
|
|
|
var url = $('#add_url').val();
|
2012-11-05 22:12:00 +01:00
|
|
|
//If trim is empty
|
2014-11-25 22:43:48 +01:00
|
|
|
if (!acceptUrl(url)) {
|
2012-11-05 22:12:00 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-11-25 22:43:48 +01:00
|
|
|
|
2012-08-13 21:58:46 +02:00
|
|
|
$('#add_url').val('');
|
2014-11-25 22:43:48 +01:00
|
|
|
var bookmark = {url: url, description: '', title: '', from_own: 0, added_date: new Date()};
|
|
|
|
increaseAjaxCallCount();
|
2012-08-13 21:58:46 +02:00
|
|
|
$.ajax({
|
2012-09-02 17:18:36 +02:00
|
|
|
type: 'POST',
|
2014-11-25 22:43:48 +01:00
|
|
|
url: 'bookmark',
|
2012-09-02 17:18:36 +02:00
|
|
|
data: bookmark,
|
2014-11-25 22:43:48 +01:00
|
|
|
complete: function () {
|
|
|
|
decreaseAjaxCallCount();
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
if (data.status === 'success') {
|
2013-01-16 23:47:26 +01:00
|
|
|
// First remove old BM if exists
|
|
|
|
$('.bookmark_single').filterAttr('data-id', data.item.id).remove();
|
2014-11-25 22:43:48 +01:00
|
|
|
|
|
|
|
var bookmark = $.extend({}, bookmark, data.item);
|
2012-09-02 17:18:36 +02:00
|
|
|
updateBookmarksList(bookmark, 'prepend');
|
2012-11-05 21:48:28 +01:00
|
|
|
checkEmpty();
|
2012-11-05 22:22:42 +01:00
|
|
|
watchUrlField();
|
2012-08-13 21:58:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-08-15 22:05:07 +02:00
|
|
|
}
|
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
function delBookmark() {
|
2011-10-08 13:54:45 +02:00
|
|
|
var record = $(this).parent().parent();
|
2014-11-25 22:43:48 +01:00
|
|
|
OC.dialogs.confirm(t('bookmarks', 'Are you sure you want to remove this bookmark?'),
|
|
|
|
t('bookmarks', 'Warning'), function (answer) {
|
|
|
|
if (answer) {
|
|
|
|
$.ajax({
|
|
|
|
type: 'DELETE',
|
|
|
|
url: 'bookmark/' + record.data('id'),
|
|
|
|
success: function (data) {
|
|
|
|
if (data.status === 'success') {
|
|
|
|
record.remove();
|
|
|
|
checkEmpty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2012-02-22 23:28:36 +01:00
|
|
|
}
|
2011-08-15 22:05:07 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-11-05 21:48:28 +01:00
|
|
|
function checkEmpty() {
|
2014-11-25 22:43:48 +01:00
|
|
|
if ($('.bookmarks_list').children().length === 0) {
|
|
|
|
$("#emptycontent").show();
|
2013-02-17 22:45:57 +01:00
|
|
|
$("#bm_export").addClass('disabled');
|
2013-02-07 00:33:47 +01:00
|
|
|
$('.bookmarks_list').hide();
|
2012-11-05 21:48:28 +01:00
|
|
|
} else {
|
2014-11-25 22:43:48 +01:00
|
|
|
$("#emptycontent").hide();
|
2013-02-17 22:45:57 +01:00
|
|
|
$("#bm_export").removeClass('disabled');
|
2013-02-07 00:33:47 +01:00
|
|
|
$('.bookmarks_list').show();
|
2012-11-05 21:48:28 +01:00
|
|
|
}
|
|
|
|
}
|
2014-11-25 22:43:48 +01:00
|
|
|
function editBookmark() {
|
|
|
|
if ($('.bookmark_single_form').length) {
|
2012-09-02 17:53:33 +02:00
|
|
|
$('.bookmark_single_form .reset').click();
|
|
|
|
}
|
2011-09-13 13:08:11 +02:00
|
|
|
var record = $(this).parent().parent();
|
2014-11-25 22:43:48 +01:00
|
|
|
var bookmark = record.data('record');
|
|
|
|
var html = tmpl("item_form_tmpl", bookmark);
|
|
|
|
|
2012-09-01 16:18:39 +02:00
|
|
|
record.after(html);
|
|
|
|
record.hide();
|
2014-11-25 22:43:48 +01:00
|
|
|
var rec_form = record.next().find('form');
|
2012-09-01 16:18:39 +02:00
|
|
|
rec_form.find('.bookmark_form_tags ul').tagit({
|
2014-11-25 22:43:48 +01:00
|
|
|
allowSpaces: true,
|
|
|
|
availableTags: fullTags,
|
|
|
|
placeholderText: t('bookmarks', 'Tags')
|
|
|
|
});
|
|
|
|
|
|
|
|
rec_form.find('.reset').bind('click', cancelBookmark);
|
|
|
|
rec_form.bind('submit', function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var form_values = $(this).serialize();
|
|
|
|
$.ajax({
|
|
|
|
type: 'PUT',
|
|
|
|
url: $(this).attr('action') + "/" + this.elements['record_id'].value,
|
|
|
|
data: form_values,
|
|
|
|
success: function (data) {
|
|
|
|
if (data.status === 'success') {
|
|
|
|
//@TODO : do better reaction than reloading the page
|
|
|
|
filterTagsChanged();
|
|
|
|
} else { // On failure
|
|
|
|
//@TODO : show error message?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2011-09-13 13:08:11 +02:00
|
|
|
}
|
2012-05-14 03:10:07 +02:00
|
|
|
|
2012-09-01 16:18:39 +02:00
|
|
|
function cancelBookmark(event) {
|
|
|
|
event.preventDefault();
|
2014-11-25 22:43:48 +01:00
|
|
|
var rec_form = $(this).closest('form').parent();
|
2012-09-01 16:18:39 +02:00
|
|
|
rec_form.prev().show();
|
|
|
|
rec_form.remove();
|
|
|
|
}
|
2012-09-02 17:18:36 +02:00
|
|
|
|
2012-10-11 21:45:05 +02:00
|
|
|
function updateBookmarksList(bookmark, position) {
|
|
|
|
position = typeof position !== 'undefined' ? position : 'append';
|
2014-11-25 22:43:48 +01:00
|
|
|
bookmark = $.extend({title: '', description: '', added_date: new Date('now'), tags: []}, bookmark);
|
|
|
|
var tags = bookmark.tags;
|
2011-08-19 13:48:08 +02:00
|
|
|
var taglist = '';
|
2014-11-25 22:43:48 +01:00
|
|
|
for (var i = 0, len = tags.length; i < len; ++i) {
|
|
|
|
if (tags[i] !== '')
|
2013-01-15 10:28:02 +01:00
|
|
|
taglist = taglist + '<a class="bookmark_tag" href="#">' + escapeHTML(tags[i]) + '</a> ';
|
2011-08-15 22:05:07 +02:00
|
|
|
}
|
2014-11-25 22:43:48 +01:00
|
|
|
if (!hasProtocol(bookmark.url)) {
|
2011-08-25 13:23:52 +02:00
|
|
|
bookmark.url = 'http://' + bookmark.url;
|
|
|
|
}
|
2014-11-25 22:43:48 +01:00
|
|
|
|
|
|
|
if (bookmark.added) {
|
|
|
|
bookmark.added_date.setTime(parseInt(bookmark.added) * 1000);
|
2012-09-02 17:18:36 +02:00
|
|
|
}
|
2013-06-28 23:54:54 +02:00
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
if (!bookmark.title)
|
|
|
|
bookmark.title = '';
|
2013-06-28 23:54:54 +02:00
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
var html = tmpl("item_tmpl", bookmark);
|
|
|
|
if (position === "prepend") {
|
2012-11-05 22:22:42 +01:00
|
|
|
$('.bookmarks_list').prepend(html);
|
|
|
|
} else {
|
2012-10-21 13:37:30 +02:00
|
|
|
$('.bookmarks_list').append(html);
|
2012-07-02 00:12:59 +02:00
|
|
|
}
|
2014-11-25 22:43:48 +01:00
|
|
|
var line = $('div[data-id="' + bookmark.id + '"]');
|
2012-11-05 22:22:42 +01:00
|
|
|
line.data('record', bookmark);
|
2014-11-25 22:43:48 +01:00
|
|
|
if (taglist !== '') {
|
2012-11-05 22:22:42 +01:00
|
|
|
line.append('<p class="bookmark_tags">' + taglist + '</p>');
|
2012-02-01 22:02:06 +01:00
|
|
|
}
|
2012-11-05 22:22:42 +01:00
|
|
|
line.find('a.bookmark_tag').bind('click', addFilterTag);
|
|
|
|
line.find('.bookmark_link').click(recordClick);
|
|
|
|
line.find('.bookmark_delete').click(delBookmark);
|
|
|
|
line.find('.bookmark_edit').click(editBookmark);
|
2014-11-25 22:43:48 +01:00
|
|
|
|
2011-08-15 22:05:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateOnBottom() {
|
|
|
|
//check wether user is on bottom of the page
|
2012-03-01 20:46:34 +01:00
|
|
|
var top = $('.bookmarks_list>:last-child').position().top;
|
|
|
|
var height = $('.bookmarks_list').height();
|
|
|
|
// use a bit of margin to begin loading before we are really at the
|
|
|
|
// bottom
|
|
|
|
if (top < height * 1.2) {
|
2012-07-01 23:08:41 +02:00
|
|
|
getBookmarks();
|
2011-08-15 22:05:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
function recordClick() {
|
2011-08-15 22:05:07 +02:00
|
|
|
$.ajax({
|
2012-06-10 23:38:26 +02:00
|
|
|
type: 'POST',
|
2014-11-25 22:43:48 +01:00
|
|
|
url: 'bookmark/click',
|
2012-11-06 22:49:58 +01:00
|
|
|
data: 'url=' + encodeURIComponent($(this).attr('href'))
|
2012-04-15 15:53:30 +02:00
|
|
|
});
|
2011-08-15 22:05:07 +02:00
|
|
|
}
|
|
|
|
|
2011-08-25 13:23:52 +02:00
|
|
|
function hasProtocol(url) {
|
2014-11-25 22:43:48 +01:00
|
|
|
var regexp = /(ftp|http|https|sftp)/;
|
|
|
|
return regexp.test(url);
|
2011-08-25 13:23:52 +02:00
|
|
|
}
|
2012-06-29 15:50:19 +02:00
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
function renameTag() {
|
|
|
|
if ($('input[name="tag_new_name"]').length)
|
|
|
|
return; // Do nothing if a tag is currenlty edited
|
|
|
|
var tagElement = $(this).closest('li');
|
|
|
|
tagElement.append('<form><input name="tag_new_name" type="text"></form>');
|
|
|
|
var form = tagElement.find('form');
|
|
|
|
//tag_el.find('.tags_actions').hide();
|
|
|
|
var tagName = tagElement.find('.tag').hide().text();
|
|
|
|
tagElement.find('input').val(tagName).focus().bind('blur', function () {
|
2012-08-11 00:13:43 +02:00
|
|
|
form.trigger('submit');
|
|
|
|
});
|
2014-11-25 22:43:48 +01:00
|
|
|
form.bind('submit', submitTagName);
|
2012-06-29 15:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function submitTagName(event) {
|
2012-08-11 00:13:43 +02:00
|
|
|
event.preventDefault();
|
2014-11-25 22:43:48 +01:00
|
|
|
var tagElement = $(this).closest('li');
|
|
|
|
var newTagName = tagElement.find('input').val();
|
|
|
|
var oldTagName = tagElement.find('.tag').show().text();
|
|
|
|
//tag_el.find('.tag_edit').show();
|
|
|
|
//tag_el.find('.tags_actions').show();
|
|
|
|
tagElement.find('input').unbind('blur');
|
|
|
|
tagElement.find('form').unbind('submit').remove();
|
|
|
|
|
|
|
|
if (newTagName !== oldTagName && newTagName !== '') {
|
2012-08-11 00:13:43 +02:00
|
|
|
//submit
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
2014-11-25 22:43:48 +01:00
|
|
|
url: 'tag',
|
|
|
|
data: {old_name: oldTagName, new_name: newTagName},
|
|
|
|
success: function (bookmarks) {
|
|
|
|
if (bookmarks.status === 'success') {
|
2012-08-11 00:13:43 +02:00
|
|
|
filterTagsChanged();
|
|
|
|
}
|
2012-06-29 15:50:19 +02:00
|
|
|
}
|
2012-08-11 00:13:43 +02:00
|
|
|
});
|
|
|
|
}
|
2012-06-29 15:50:19 +02:00
|
|
|
}
|
|
|
|
|
2014-11-25 22:43:48 +01:00
|
|
|
function deleteTag() {
|
|
|
|
var tag_el = $(this).closest('li');
|
2012-06-29 15:50:19 +02:00
|
|
|
var old_tag_name = tag_el.find('.tag').show().text();
|
2012-08-13 19:24:34 +02:00
|
|
|
OC.dialogs.confirm(t('bookmarks', 'Are you sure you want to remove this tag from every entry?'),
|
2014-11-25 22:43:48 +01:00
|
|
|
t('bookmarks', 'Warning'), function (answer) {
|
|
|
|
if (answer) {
|
2012-06-29 15:50:19 +02:00
|
|
|
$.ajax({
|
2014-11-25 22:43:48 +01:00
|
|
|
type: 'DELETE',
|
|
|
|
url: 'tag',
|
|
|
|
data: {old_name: old_tag_name},
|
|
|
|
success: function (bookmarks) {
|
|
|
|
if (bookmarks.status === 'success') {
|
2012-06-29 15:50:19 +02:00
|
|
|
filterTagsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2012-07-31 22:48:11 +02:00
|
|
|
}
|