From 39e00dcc654f50b94eeabf245398646a06c40d95 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 24 Nov 2018 15:11:05 -0700 Subject: [PATCH] Add note color picker, close #4 --- .gitmodules | 2 +- action.php | 12 ++++++++ langs/en/notes.json | 6 +++- lib/Note.lib.php | 5 ++++ pages/editnote.php | 2 +- pages/home.php | 68 ++++++++++++++++++++++++++++++++++++++++++++- static/js/home.js | 10 ++++++- 7 files changed, 100 insertions(+), 5 deletions(-) diff --git a/.gitmodules b/.gitmodules index 58b232e..72740a4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,4 +3,4 @@ url = https://source.netsyms.com/Netsyms/Material-Color [submodule "static/easy-markdown-editor"] path = static/easy-markdown-editor - url = https://source.netsyms.com/Netsyms/easy-markdown-editor.git + url = https://source.netsyms.com/Netsyms/easy-markdown-editor.git \ No newline at end of file diff --git a/action.php b/action.php index ab4a272..c42ce82 100644 --- a/action.php +++ b/action.php @@ -90,4 +90,16 @@ switch ($VARS['action']) { $notes[] = Note::loadNote($n)->toArray(); } exit(json_encode($notes)); + case "setcolor": + if (empty($VARS['noteid'])) { + die($Strings->get("invalid parameters")); + } + $note = Note::loadNote($VARS['noteid']); + if (!$note->hasWriteAccess(new User($_SESSION['uid']))) { + die($Strings->get("invalid parameters")); + } + $note->setColor($VARS['color']); + $note->saveNote(); + returnToSender(""); + break; } \ No newline at end of file diff --git a/langs/en/notes.json b/langs/en/notes.json index 2140825..ee33272 100644 --- a/langs/en/notes.json +++ b/langs/en/notes.json @@ -5,5 +5,9 @@ "Edit": "Edit", "Delete": "Delete", "Download": "Download", - "Note deleted": "Note deleted" + "Note deleted": "Note deleted", + "Favorite": "Favorite", + "Set color": "Set color", + "Cancel": "Cancel", + "Save": "Save" } diff --git a/lib/Note.lib.php b/lib/Note.lib.php index 45743cf..a694ff6 100644 --- a/lib/Note.lib.php +++ b/lib/Note.lib.php @@ -239,6 +239,11 @@ class Note { * @param string $color "RRGGBB" */ public function setColor(string $color) { + $color = strtoupper($color); + // Make sure we have a valid RRGGBB hex + if (!preg_match("/[A-F0-9]{6}/", $color)) { + $color = "FFFFFF"; + } $this->color = $color; } diff --git a/pages/editnote.php b/pages/editnote.php index d3f5150..e0989c1 100644 --- a/pages/editnote.php +++ b/pages/editnote.php @@ -29,6 +29,6 @@ $note->saveNote();
- +
\ No newline at end of file diff --git a/pages/home.php b/pages/home.php index 0c0f6ab..b66b2e5 100644 --- a/pages/home.php +++ b/pages/home.php @@ -14,6 +14,29 @@ foreach ($noteids as $n) { + +
get("New note"); ?>
@@ -37,9 +100,12 @@ foreach ($notes as $note) {
getHTML(); ?> diff --git a/static/js/home.js b/static/js/home.js index 407cf8d..bfb1d41 100644 --- a/static/js/home.js +++ b/static/js/home.js @@ -23,4 +23,12 @@ setInterval(function () { } } }); -}, 15 * 1000); \ No newline at end of file +}, 15 * 1000); + +$(".color-btn").click(function () { + $("#colormodal input[name=noteid]").val($(this).data("noteid")); + $("#colormodal input[name=color]").val($(this).data("color")); + $("#colormodal").modal(); +}); + +$('[data-toggle="tooltip"]').tooltip(); \ No newline at end of file