diff --git a/src/public/javascripts/services/entrypoints.js b/src/public/javascripts/services/entrypoints.js index 8af5b838a..515ca64a9 100644 --- a/src/public/javascripts/services/entrypoints.js +++ b/src/public/javascripts/services/entrypoints.js @@ -12,6 +12,7 @@ import recentChangesDialog from "../dialogs/recent_changes.js"; import sqlConsoleDialog from "../dialogs/sql_console.js"; import searchTreeService from "./search_tree.js"; import labelsDialog from "../dialogs/labels.js"; +import protectedSessionService from "./protected_session.js"; function registerEntrypoints() { // hot keys are active also inside inputs and content editables @@ -31,6 +32,9 @@ function registerEntrypoints() { $("#recent-changes-button").click(recentChangesDialog.showDialog); + $("#protected-session-on").click(protectedSessionService.enterProtectedSession); + $("#protected-session-off").click(protectedSessionService.leaveProtectedSession); + $("#recent-notes-button").click(recentNotesDialog.showDialog); utils.bindShortcut('ctrl+e', recentNotesDialog.showDialog); diff --git a/src/public/javascripts/services/protected_session.js b/src/public/javascripts/services/protected_session.js index 399742250..b31695347 100644 --- a/src/public/javascripts/services/protected_session.js +++ b/src/public/javascripts/services/protected_session.js @@ -11,9 +11,23 @@ const $password = $("#protected-session-password"); const $noteDetailWrapper = $("#note-detail-wrapper"); const $protectButton = $("#protect-button"); const $unprotectButton = $("#unprotect-button"); +const $protectedSessionOnButton = $("#protected-session-on"); +const $protectedSessionOffButton = $("#protected-session-off"); let protectedSessionDeferred = null; +async function enterProtectedSession() { + if (!protectedSessionHolder.isProtectedSessionAvailable()) { + await ensureProtectedSession(true, true); + } +} + +async function leaveProtectedSession() { + if (protectedSessionHolder.isProtectedSessionAvailable()) { + utils.reloadApp(); + } +} + function ensureProtectedSession(requireProtectedSession, modal) { const dfd = $.Deferred(); @@ -46,7 +60,7 @@ async function setupProtectedSession() { const password = $password.val(); $password.val(""); - const response = await enterProtectedSession(password); + const response = await enterProtectedSessionOnServer(password); if (!response.success) { infoService.showError("Wrong password."); @@ -67,6 +81,9 @@ async function setupProtectedSession() { protectedSessionDeferred.resolve(); + $protectedSessionOnButton.addClass('active'); + $protectedSessionOffButton.removeClass('active'); + protectedSessionDeferred = null; } } @@ -81,7 +98,7 @@ function ensureDialogIsClosed() { $password.val(''); } -async function enterProtectedSession(password) { +async function enterProtectedSessionOnServer(password) { return await server.post('login/protected', { password: password }); @@ -138,5 +155,7 @@ export default { protectNoteAndSendToServer, unprotectNoteAndSendToServer, protectBranch, - ensureDialogIsClosed + ensureDialogIsClosed, + enterProtectedSession, + leaveProtectedSession }; \ No newline at end of file diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index e48fcf11f..a0bd5f061 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -371,4 +371,12 @@ div.ui-tooltip { #history-navigation { margin: 0 20px 0 5px; display: flex; +} + +.btn { + border-color: #ddd; +} + +.btn.active { + background-color: #ddd; } \ No newline at end of file diff --git a/src/views/index.ejs b/src/views/index.ejs index 7c5f0681e..41a18a38a 100644 --- a/src/views/index.ejs +++ b/src/views/index.ejs @@ -23,10 +23,18 @@ style="background: url('/images/icons/forward.png')"> -
+
+
+ Protected session: + +
+ + +
+