using server.method() instead of direct call to $.ajax - preparation for electron without network requests

This commit is contained in:
azivner
2017-11-28 20:52:38 -05:00
parent 14001f67d8
commit 54c0ff15b3
17 changed files with 150 additions and 217 deletions

View File

@@ -10,38 +10,26 @@ const recentNotes = (function() {
const noteDetailEl = $('#note-detail');
let list = [];
$.ajax({
url: baseApiUrl + 'recent-notes',
type: 'GET',
error: () => showError("Error getting recent notes.")
}).then(result => {
server.get('recent-notes').then(result => {
list = result.map(r => r.note_tree_id);
});
function addRecentNote(notePath) {
setTimeout(() => {
setTimeout(async () => {
// we include the note into recent list only if the user stayed on the note at least 5 seconds
if (notePath && notePath === noteTree.getCurrentNotePath()) {
$.ajax({
url: baseApiUrl + 'recent-notes/' + encodeURIComponent(notePath),
type: 'PUT',
error: () => showError("Error setting recent notes.")
}).then(result => {
list = result.map(r => r.note_path);
});
const result = await server.put('recent-notes/' + encodeURIComponent(notePath));
list = result.map(r => r.note_path);
}
}, 1500);
}
// FIXME: this should be probably just refresh upon deletion, not explicit delete
function removeRecentNote(notePathIdToRemove) {
$.ajax({
url: baseApiUrl + 'recent-notes/' + encodeURIComponent(notePathIdToRemove),
type: 'DELETE',
error: () => showError("Error removing note from recent notes.")
}).then(result => {
list = result.map(r => r.note_path);
});
async function removeRecentNote(notePathIdToRemove) {
const result = server.remove('recent-notes/' + encodeURIComponent(notePathIdToRemove));
list = result.map(r => r.note_path);
}
function showDialog() {