Skip to content

Commit 68457ed

Browse files
committed
Update to make history delete and pin function call to new APIs
1 parent 7a46c9f commit 68457ed

1 file changed

Lines changed: 58 additions & 28 deletions

File tree

public/js/cover.js

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,32 @@ function parseHistoryCallback(list, notehistory) {
166166
pinned = false;
167167
item._values.pinned = false;
168168
}
169-
getHistory(function (notehistory) {
170-
for(var i = 0; i < notehistory.length; i++) {
171-
if (notehistory[i].id == id) {
172-
notehistory[i].pinned = pinned;
173-
break;
174-
}
175-
}
176-
saveHistory(notehistory);
177-
if (pinned)
178-
$this.addClass('active');
179-
else
180-
$this.removeClass('active');
181-
});
169+
checkIfAuth(function () {
170+
postHistoryToServer(id, {
171+
pinned: pinned
172+
}, function (err, result) {
173+
if (!err) {
174+
if (pinned)
175+
$this.addClass('active');
176+
else
177+
$this.removeClass('active');
178+
}
179+
});
180+
}, function () {
181+
getHistory(function (notehistory) {
182+
for(var i = 0; i < notehistory.length; i++) {
183+
if (notehistory[i].id == id) {
184+
notehistory[i].pinned = pinned;
185+
break;
186+
}
187+
}
188+
saveHistory(notehistory);
189+
if (pinned)
190+
$this.addClass('active');
191+
else
192+
$this.removeClass('active');
193+
});
194+
})
182195
});
183196
buildTagsFilter(filtertags);
184197
}
@@ -199,23 +212,40 @@ var clearHistory = false;
199212
var deleteId = null;
200213

201214
function deleteHistory() {
202-
if (clearHistory) {
203-
saveHistory([]);
204-
historyList.clear();
205-
checkHistoryList();
206-
deleteId = null;
207-
} else {
208-
if (!deleteId) return;
209-
getHistory(function (notehistory) {
210-
var newnotehistory = removeHistory(deleteId, notehistory);
211-
saveHistory(newnotehistory);
212-
historyList.remove('id', deleteId);
213-
checkHistoryList();
215+
checkIfAuth(function () {
216+
deleteServerHistory(deleteId, function (err, result) {
217+
if (!err) {
218+
if (clearHistory) {
219+
historyList.clear();
220+
checkHistoryList();
221+
} else {
222+
historyList.remove('id', deleteId);
223+
checkHistoryList();
224+
}
225+
}
226+
$('.delete-modal').modal('hide');
214227
deleteId = null;
228+
clearHistory = false;
215229
});
216-
}
217-
$('.delete-modal').modal('hide');
218-
clearHistory = false;
230+
}, function () {
231+
if (clearHistory) {
232+
saveHistory([]);
233+
historyList.clear();
234+
checkHistoryList();
235+
deleteId = null;
236+
} else {
237+
if (!deleteId) return;
238+
getHistory(function (notehistory) {
239+
var newnotehistory = removeHistory(deleteId, notehistory);
240+
saveHistory(newnotehistory);
241+
historyList.remove('id', deleteId);
242+
checkHistoryList();
243+
deleteId = null;
244+
});
245+
}
246+
$('.delete-modal').modal('hide');
247+
clearHistory = false;
248+
});
219249
}
220250

221251
$(".ui-delete-modal-confirm").click(function () {

0 commit comments

Comments
 (0)