From 68457ed3a26012e9e72e7ca95bfd7b9c101cdd8b Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 21:00:07 +0800 Subject: Update to make history delete and pin function call to new APIs --- public/js/cover.js | 86 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 28 deletions(-) (limited to 'public/js/cover.js') diff --git a/public/js/cover.js b/public/js/cover.js index f3533826..429925a0 100644 --- a/public/js/cover.js +++ b/public/js/cover.js @@ -166,19 +166,32 @@ function parseHistoryCallback(list, notehistory) { pinned = false; item._values.pinned = false; } - getHistory(function (notehistory) { - for(var i = 0; i < notehistory.length; i++) { - if (notehistory[i].id == id) { - notehistory[i].pinned = pinned; - break; - } - } - saveHistory(notehistory); - if (pinned) - $this.addClass('active'); - else - $this.removeClass('active'); - }); + checkIfAuth(function () { + postHistoryToServer(id, { + pinned: pinned + }, function (err, result) { + if (!err) { + if (pinned) + $this.addClass('active'); + else + $this.removeClass('active'); + } + }); + }, function () { + getHistory(function (notehistory) { + for(var i = 0; i < notehistory.length; i++) { + if (notehistory[i].id == id) { + notehistory[i].pinned = pinned; + break; + } + } + saveHistory(notehistory); + if (pinned) + $this.addClass('active'); + else + $this.removeClass('active'); + }); + }) }); buildTagsFilter(filtertags); } @@ -199,23 +212,40 @@ var clearHistory = false; var deleteId = null; function deleteHistory() { - if (clearHistory) { - saveHistory([]); - historyList.clear(); - checkHistoryList(); - deleteId = null; - } else { - if (!deleteId) return; - getHistory(function (notehistory) { - var newnotehistory = removeHistory(deleteId, notehistory); - saveHistory(newnotehistory); - historyList.remove('id', deleteId); - checkHistoryList(); + checkIfAuth(function () { + deleteServerHistory(deleteId, function (err, result) { + if (!err) { + if (clearHistory) { + historyList.clear(); + checkHistoryList(); + } else { + historyList.remove('id', deleteId); + checkHistoryList(); + } + } + $('.delete-modal').modal('hide'); deleteId = null; + clearHistory = false; }); - } - $('.delete-modal').modal('hide'); - clearHistory = false; + }, function () { + if (clearHistory) { + saveHistory([]); + historyList.clear(); + checkHistoryList(); + deleteId = null; + } else { + if (!deleteId) return; + getHistory(function (notehistory) { + var newnotehistory = removeHistory(deleteId, notehistory); + saveHistory(newnotehistory); + historyList.remove('id', deleteId); + checkHistoryList(); + deleteId = null; + }); + } + $('.delete-modal').modal('hide'); + clearHistory = false; + }); } $(".ui-delete-modal-confirm").click(function () { -- cgit v1.2.3 From cd9f8fe36b707ff5a9f8f7be4d55145ddee97f3a Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Tue, 11 Oct 2016 16:48:42 +0800 Subject: Update to support pagination for history list --- public/js/cover.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'public/js/cover.js') diff --git a/public/js/cover.js b/public/js/cover.js index 429925a0..25434ed9 100644 --- a/public/js/cover.js +++ b/public/js/cover.js @@ -18,7 +18,11 @@ var options = { \ \ \ - ' + ', + page: 18, + plugins: [ + ListPagination({}) + ] }; var historyList = new List('history', options); -- cgit v1.2.3