Improve note creation and deletion error handling and reliability
This commit is contained in:
parent
47d0a48e4f
commit
59b4f70a75
@ -105,7 +105,7 @@ class NotePostNotes extends Notes {
|
||||
}
|
||||
} else {
|
||||
if (typeof error == 'function') {
|
||||
error();
|
||||
error(val.msg);
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -117,7 +117,6 @@ class NotePostNotes extends Notes {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sync notes with the NotePost server, resolving conflicts in the process.
|
||||
*
|
||||
@ -154,18 +153,26 @@ class NotePostNotes extends Notes {
|
||||
for (var i = 0; i < notesToUpload.length; i++) {
|
||||
addedOrChangedLocallyAjax.push(self.saveNote(self.fix(notesToUpload[i]), function (n) {
|
||||
notes.push(n);
|
||||
}, function (err) {
|
||||
if (typeof err === "string") {
|
||||
app.dialog.alert(err, "Error");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
$.when(addedOrChangedLocallyAjax).then(function () {
|
||||
$.when(addedOrChangedLocallyAjax).always(function () {
|
||||
self.notes = notes;
|
||||
self.fixAll();
|
||||
localStorage.setItem("notes", JSON.stringify(notes));
|
||||
console.log(JSON.parse(localStorage.getItem("notes")));
|
||||
|
||||
}).then(function () {
|
||||
if (typeof success == 'function') {
|
||||
success(notes);
|
||||
}
|
||||
}, function () {
|
||||
if (typeof error == 'function') {
|
||||
error(notes);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -137,6 +137,9 @@ class Notes {
|
||||
if (localStorage.getItem("notes") !== null) {
|
||||
// There is localstorage
|
||||
var storage = JSON.parse(localStorage.getItem("notes"));
|
||||
if (typeof this.notes === 'undefined') {
|
||||
this.notes = [];
|
||||
}
|
||||
console.log("Memory copy:", this.notes);
|
||||
console.log("Storage copy:", storage);
|
||||
var delta = getDelta(this.notes, storage);
|
||||
|
@ -13,10 +13,18 @@ function saveme(callback) {
|
||||
closeTimeout: 2000
|
||||
}).open();
|
||||
$("#orig_content").val(note.content);
|
||||
});
|
||||
if (typeof callback == "function") {
|
||||
callback();
|
||||
}
|
||||
}, function () {
|
||||
app.toast.create({
|
||||
text: 'Something went wrong, your note might not be synced correctly.',
|
||||
closeTimeout: 10000
|
||||
}).open();
|
||||
if (typeof callback == "function") {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
sync();
|
||||
@ -29,6 +37,15 @@ function saveme(callback) {
|
||||
NOTES.add(note, function (n) {
|
||||
$("#note_content").data("noteid", n.noteid);
|
||||
finishSave(n, callback);
|
||||
}, function (err) {
|
||||
if (typeof err == "string") {
|
||||
app.dialog.alert(err, "Error");
|
||||
} else {
|
||||
app.dialog.alert("An unknown error occurred.", "Error");
|
||||
}
|
||||
if (typeof callback == "function") {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var note = NOTES.get(noteid);
|
||||
@ -39,17 +56,6 @@ function saveme(callback) {
|
||||
}
|
||||
}
|
||||
|
||||
function exiteditor() {
|
||||
sync();
|
||||
if ($("#note_content").val() == "" || $("#note_content").val() === $("#orig_content").val()) {
|
||||
router.back({force: true, ignoreCache: true, reload: true});
|
||||
} else {
|
||||
saveme(function () {
|
||||
router.back({force: true, ignoreCache: true, reload: true});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
document.getElementById("noteframe").contentWindow.initEditor($("#note_content").val());
|
||||
}
|
||||
@ -62,6 +68,17 @@ function sync() {
|
||||
$("#note_content").val(document.getElementById("noteframe").contentWindow.getMarkdown());
|
||||
}
|
||||
|
||||
function exiteditor() {
|
||||
sync();
|
||||
if ($("#note_content").val() == "" || $("#note_content").val() === $("#orig_content").val()) {
|
||||
router.back({force: true, ignoreCache: true, reload: true});
|
||||
} else {
|
||||
saveme(function () {
|
||||
router.back({force: true, ignoreCache: true, reload: true});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$("#noteframe").on("load", function () {
|
||||
init();
|
||||
});
|
@ -70,6 +70,7 @@ function deleteNote(id) {
|
||||
app.dialog.confirm('Are you sure?', 'Delete Note', function () {
|
||||
NOTES.del(id, function () {
|
||||
window.shuffleInstance.remove(document.getElementById("notecard-" + id));
|
||||
loadCards();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user