From dd5a142fdd96a2f7a0dcddee774ce70c2e52b2d2 Mon Sep 17 00:00:00 2001 From: azivner Date: Wed, 15 Nov 2017 00:10:11 -0500 Subject: [PATCH] hiding protected session dialog when moving over to unprotected note --- public/javascripts/note_editor.js | 6 +++++- public/javascripts/protected_session.js | 21 +++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/public/javascripts/note_editor.js b/public/javascripts/note_editor.js index 4f5902aba..a1767d531 100644 --- a/public/javascripts/note_editor.js +++ b/public/javascripts/note_editor.js @@ -169,7 +169,7 @@ const noteEditor = (function() { function setTreeBasedOnProtectedStatus(note) { const node = treeUtils.getNodeByKey(note.detail.note_id); - node.toggleClass("protected", note.detail.is_protected); + node.toggleClass("protected", !!note.detail.is_protected); } function setNoteBackgroundIfProtected(note) { @@ -202,6 +202,10 @@ const noteEditor = (function() { protected_session.touchProtectedSession(); } + // this might be important if we focused on protected note when not in protected note and we got a dialog + // to login, but we chose instead to come to another node - at that point the dialog is still visible and this will close it. + protected_session.ensureDialogIsClosed(); + noteDetailWrapperEl.show(); noteTitleEl.val(currentNote.detail.note_title); diff --git a/public/javascripts/protected_session.js b/public/javascripts/protected_session.js index 9e7ec3781..59963c90b 100644 --- a/public/javascripts/protected_session.js +++ b/public/javascripts/protected_session.js @@ -69,13 +69,7 @@ const protected_session = (function() { noteTree.reload(); if (protectedSessionDeferred !== null) { - // this may fal if the dialog has not been previously opened - try { - dialogEl.dialog('close'); - } - catch(e) {} - - passwordEl.val(''); + ensureDialogIsClosed(dialogEl, passwordEl); protectedSessionDeferred.resolve(); @@ -83,6 +77,16 @@ const protected_session = (function() { } } + function ensureDialogIsClosed() { + // this may fal if the dialog has not been previously opened + try { + dialogEl.dialog('close'); + } + catch (e) {} + + passwordEl.val(''); + } + async function enterProtectedSession(password) { return await $.ajax({ url: baseApiUrl + 'login/protected', @@ -182,6 +186,7 @@ const protected_session = (function() { unprotectNoteAndSendToServer, getProtectedSessionId, touchProtectedSession, - protectSubTree + protectSubTree, + ensureDialogIsClosed }; })(); \ No newline at end of file