From 083cccea2830290bac3601d82c9ef1fd5ca7652f Mon Sep 17 00:00:00 2001 From: azivner Date: Sat, 2 Jun 2018 11:47:16 -0400 Subject: [PATCH] better protected/unprotected note indicator, fixes #110 --- src/public/images/icons/shield-off.png | Bin 0 -> 462 bytes src/public/images/icons/shield.png | Bin 0 -> 388 bytes .../javascripts/services/note_detail.js | 10 +++++---- .../javascripts/services/protected_session.js | 8 ++++++++ src/public/stylesheets/style.css | 9 +++------ src/views/index.ejs | 19 ++++++++++-------- 6 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 src/public/images/icons/shield-off.png create mode 100644 src/public/images/icons/shield.png diff --git a/src/public/images/icons/shield-off.png b/src/public/images/icons/shield-off.png new file mode 100644 index 0000000000000000000000000000000000000000..31c0ab9217c80f7c1ed42b42880779144a3b232f GIT binary patch literal 462 zcmV;<0WtoGP)~!46T6K<^iTL|!b}bF7Eo{1t z@j*Xn0{gheiw5Y|K=%hY3OvCNT;+l2jd!`%%a%3;^EgSv2Bt8LkI5b8(I|$2PGc(# zr}&w5w<4|1u+R~_#W{XOE_GVo476zL`KgR1gA_RU2Q67t<8 literal 0 HcmV?d00001 diff --git a/src/public/images/icons/shield.png b/src/public/images/icons/shield.png new file mode 100644 index 0000000000000000000000000000000000000000..4892e57c78e891a84993489676aa370ccb2924d3 GIT binary patch literal 388 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-VTavfC3&Vd9T(EcfWS|IVfk$L9 zP{(x;W^~e+T>%tiFY)wsWq-uR#Lq00c++DG0|TR=r;B5V#p$P)_j)l0im*J;Kjvh@ z)%DGh#Z&nO^Nrh`y;~z*SbK2X_$d>W^IVxDY~_|<7p9FJy&J_`HkqjlB;R?HWyRjc z{QS(BzYpU+B`W?V*9MQmeOt1rH8SvE~{OJkZu(3T4hr4GTp zaoG;ndET3wI88{9UfOfid!gr{%P;tswYwB_?KZqV>5)|I8-6{z)I&d>H{M-wn)Q!% zV7wdaJ@>mh0y|8f{B7EKCjlJob3LB0*04Vs`s7foTPjjQ$5rs=D{rE?1R#Y+7Nm fl0Sg6@2L82U5A_Xf?rnx!;8Vw)z4*}Q$iB}YB--| literal 0 HcmV?d00001 diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index fa287b599..3d2dcc21d 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -22,6 +22,7 @@ const $noteDetailComponents = $(".note-detail-component"); const $protectButton = $("#protect-button"); const $unprotectButton = $("#unprotect-button"); const $noteDetailWrapper = $("#note-detail-wrapper"); +const $noteDetailComponentWrapper = $("#note-detail-component-wrapper"); const $noteIdDisplay = $("#note-id-display"); const $labelList = $("#label-list"); const $labelListInner = $("#label-list-inner"); @@ -116,9 +117,9 @@ async function saveNoteIfChanged() { function setNoteBackgroundIfProtected(note) { const isProtected = !!note.isProtected; - $noteDetailWrapper.toggleClass("protected", isProtected); - $protectButton.toggle(!isProtected); - $unprotectButton.toggle(isProtected); + $noteDetailComponentWrapper.toggleClass("protected", isProtected); + $protectButton.toggleClass("active", isProtected); + $unprotectButton.toggleClass("active", !isProtected); } let isNewNoteCreated = false; @@ -150,6 +151,8 @@ async function loadNoteDetail(noteId) { $noteIdDisplay.html(noteId); + setNoteBackgroundIfProtected(currentNote); + await handleProtectedSession(); $noteDetailWrapper.show(); @@ -170,7 +173,6 @@ async function loadNoteDetail(noteId) { noteChangeDisabled = false; } - setNoteBackgroundIfProtected(currentNote); treeService.setBranchBackgroundBasedOnProtectedStatus(noteId); // after loading new note make sure editor is scrolled to the top diff --git a/src/public/javascripts/services/protected_session.js b/src/public/javascripts/services/protected_session.js index b31695347..2f6fba0d9 100644 --- a/src/public/javascripts/services/protected_session.js +++ b/src/public/javascripts/services/protected_session.js @@ -105,6 +105,10 @@ async function enterProtectedSessionOnServer(password) { } async function protectNoteAndSendToServer() { + if (noteDetailService.getCurrentNote().isProtected) { + return; + } + await ensureProtectedSession(true, true); const note = noteDetailService.getCurrentNote(); @@ -118,6 +122,10 @@ async function protectNoteAndSendToServer() { } async function unprotectNoteAndSendToServer() { + if (!noteDetailService.getCurrentNote().isProtected) { + return; + } + await ensureProtectedSession(true, true); const note = noteDetailService.getCurrentNote(); diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index 4ce0b0cd3..a18d68425 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -51,7 +51,7 @@ overflow: auto; } -#note-detail-wrapper.protected, #note-detail-wrapper.protected .CodeMirror { +#note-detail-component-wrapper.protected, #note-detail-component-wrapper.protected .CodeMirror { background-color: #eee; } @@ -138,10 +138,6 @@ span.fancytree-active:not(.fancytree-focused) .fancytree-title { width: 24px; } -#protect-button, #unprotect-button { - display: none; -} - .ui-widget-content a:not(.ui-tabs-anchor) { color: #337ab7 !important; } @@ -361,10 +357,11 @@ div.ui-tooltip { .btn { border-color: #ddd; + background-color: #eee; } .btn.active { - background-color: #ddd; + background-color: #ccc; } #note-path-list .current a { diff --git a/src/views/index.ejs b/src/views/index.ejs index a781c1df5..e22f59013 100644 --- a/src/views/index.ejs +++ b/src/views/index.ejs @@ -105,15 +105,18 @@ - +
+ Protected: - +
+ + +
+