From 36d4af6300a71646aa189cb30e2c04e9c4cb6b4a Mon Sep 17 00:00:00 2001 From: poliphilochu Date: Fri, 5 Jul 2024 22:16:55 +0800 Subject: [PATCH] refs #40870. Add user preferenc e feature to sidePanel --- packages/sidePanel/sidePanel.js | 23 +++++++++++++++++++++-- templates/CRM/common/sidePanel.tpl | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/sidePanel/sidePanel.js b/packages/sidePanel/sidePanel.js index a18af668e..ab1ee0565 100644 --- a/packages/sidePanel/sidePanel.js +++ b/packages/sidePanel/sidePanel.js @@ -54,6 +54,7 @@ _nspOpened, _nspFullscreen, _nspContainerClass, + _nspUserPreference, _nspAPI = window.location.origin + "/api/", _container, _content = "." + NSP_CONTENT, @@ -246,19 +247,36 @@ _cssVariablesUpdate("--nsp-width", _nspWidth); } - if (_nspOpened) { + let nspOpenedDefault = _nspOpened; + if (_nspUserPreference) { + if (typeof window.setCookie !== 'undefined') { + nspOpenedDefault = getCookie('nsp_user_preference_open_status'); + } + } + + if (nspOpenedDefault && nspOpenedDefault != 'false') { _nspMain.open(); } - }, + }, open: function() { $(_container).addClass(OPEN_CLASS); $(_container).removeClass(CLOSE_CLASS); $("body").addClass("nsp-" + OPEN_CLASS); + if (_nspUserPreference) { + if (typeof window.setCookie !== 'undefined') { + setCookie('nsp_user_preference_open_status', true, 86400*30, window.location.pathname); + } + } }, close: function() { $(_container).removeClass(OPEN_CLASS); $(_container).addClass(CLOSE_CLASS); $("body").removeClass("nsp-" + OPEN_CLASS); + if (_nspUserPreference) { + if (typeof window.setCookie !== 'undefined') { + setCookie('nsp_user_preference_open_status', false, 86400*30, window.location.pathname); + } + } }, fullscreen: function() { _nspMain.open(); @@ -453,6 +471,7 @@ _nspWidth = _nspOptions.width; _nspOpened = _nspOptions.opened; _nspFullscreen = _nspOptions.fullscreen; + _nspUserPreference = _nspOptions.userPreference; if (_debugMode) { $("html").addClass("is-debug"); diff --git a/templates/CRM/common/sidePanel.tpl b/templates/CRM/common/sidePanel.tpl index 7408edcb5..7312b084d 100644 --- a/templates/CRM/common/sidePanel.tpl +++ b/templates/CRM/common/sidePanel.tpl @@ -24,6 +24,7 @@ neticrmSidePanelOpts.width = "{/literal}{$width}{literal}"; neticrmSidePanelOpts.opened = "{/literal}{$opened}{literal}"; neticrmSidePanelOpts.fullscreen = "{/literal}{$fullscreen}{literal}"; + neticrmSidePanelOpts.userPreference = "{/literal}{$userPreference}{literal}"; neticrmSidePanelOpts.debugMode = "{/literal}{$config->debug}{literal}"; window.neticrmSidePanelInstance = $(".nsp-container").neticrmSidePanel(".nsp-container", neticrmSidePanelOpts); });