From 20dbd0a613aca206ef5ccdb04daf0499ec253213 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Wed, 9 Jan 2019 13:55:56 -0700 Subject: [PATCH] Add note deletion --- www/js/NotePostNotes.class.js | 24 ++++++++++++++++++ www/js/Notes.class.js | 13 ++++++++++ www/js/editnote.js | 2 +- www/js/home.js | 48 +++++++++++++++++++---------------- www/pages/editnote.html | 2 +- 5 files changed, 65 insertions(+), 24 deletions(-) diff --git a/www/js/NotePostNotes.class.js b/www/js/NotePostNotes.class.js index 72a842f..05f690f 100644 --- a/www/js/NotePostNotes.class.js +++ b/www/js/NotePostNotes.class.js @@ -13,6 +13,30 @@ class NotePostNotes extends Notes { this.password = password; } + del(noteid, callback) { + super.del(noteid); + var self = this; + $.ajax({ + url: this.server + "/api/deletenote", + dataType: "json", + cache: false, + method: "POST", + data: { + id: noteid + }, + beforeSend: function (xhr) { + xhr.setRequestHeader("Authorization", "Basic " + btoa(self.username + ":" + self.password)); + }, success: function (val) { + if (val.status == "OK") { + self.notes = val.notes; + } + if (typeof callback == 'function') { + callback(); + } + } + }); + } + add(note, callback) { note.norealid = true; super.add(note, callback); diff --git a/www/js/Notes.class.js b/www/js/Notes.class.js index 8357c8b..f5f5652 100644 --- a/www/js/Notes.class.js +++ b/www/js/Notes.class.js @@ -36,6 +36,19 @@ class Notes { this.notes.push(note); } + del(noteid, callback) { + var newnotearr = []; + for (var i = 0; i < this.notes.length; i++) { + if (this.notes[i].id != noteid) { + newnotearr.push(this.notes[i]); + } + } + this.notes = newnotearr; + if (typeof callback == 'function') { + callback(); + } + } + add(note, callback) { this.notes.push(note); if (typeof callback == 'function') { diff --git a/www/js/editnote.js b/www/js/editnote.js index baadaff..91ca041 100644 --- a/www/js/editnote.js +++ b/www/js/editnote.js @@ -40,7 +40,7 @@ function saveme(callback) { } function exiteditor() { - if ($("note_content").val() == "" || $("note_content").val() === $("orig_content").val()) { + if ($("#note_content").val() == "" || $("#note_content").val() === $("#orig_content").val()) { router.back({force: true, ignoreCache: true, reload: true}); } else { saveme(function () { diff --git a/www/js/home.js b/www/js/home.js index bcd361e..a756ad6 100644 --- a/www/js/home.js +++ b/www/js/home.js @@ -6,18 +6,18 @@ $(".view-main").on("ptr:refresh", ".ptr-content", function () { - router.navigate("/home"); + restartApplication(); }); function editNote(id) { var note = notes.get(id); router.navigate("/editnote", { - context: { - noteid: id, - content: note.content, - notetitle: note.title, - } - }); + context: { + noteid: id, + content: note.content, + notetitle: note.title, + } + }); console.log("Editing " + id); } @@ -30,7 +30,11 @@ function makeList(id) { } function deleteNote(id) { - + app.dialog.confirm('Are you sure?', 'Delete Note', function () { + notes.del(id, function () { + app.ptr.refresh(); + }); + }); } $("#app").on("click", ".edit-note-btn", function () { @@ -66,20 +70,20 @@ function openNoteActionMenu(notecard) { editNote(noteid); } }, - { - text: "Favorite", - icon: '', - onClick: function () { - favoriteNote(noteid); - } - }, - { - text: "Make a List", - icon: '', - onClick: function () { - makeList(noteid); - } - }, +// { +// text: "Favorite", +// icon: '', +// onClick: function () { +// favoriteNote(noteid); +// } +// }, +// { +// text: "Make a List", +// icon: '', +// onClick: function () { +// makeList(noteid); +// } +// }, { text: "Delete", icon: '', diff --git a/www/pages/editnote.html b/www/pages/editnote.html index 5730c89..bb6df4d 100644 --- a/www/pages/editnote.html +++ b/www/pages/editnote.html @@ -28,7 +28,7 @@
- +