From 85a8e96854a0765d9867ee7437aba386eebff9a6 Mon Sep 17 00:00:00 2001 From: Anne-Cath Date: Mon, 9 Dec 2024 13:25:41 +0100 Subject: [PATCH] Use user params in place of specific param --- js/layouts/activity-panel/activity-panel.js | 6 +++--- js/utils.js | 11 ++++++++--- .../Base/Layout/ActivityPanel/ActivityPanel.php | 15 --------------- .../base/layouts/activity-panel/layout.js.twig | 1 - 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/js/layouts/activity-panel/activity-panel.js b/js/layouts/activity-panel/activity-panel.js index 484f84742c..9d72ded0b7 100644 --- a/js/layouts/activity-panel/activity-panel.js +++ b/js/layouts/activity-panel/activity-panel.js @@ -32,7 +32,6 @@ $(function() lock_token: null, lock_watcher_period: 30, // Period (in seconds) between lock status update, uses the "activity_panel.lock_watcher_period" config. param. lock_endpoint: null, - show_multiple_entries_submit_confirmation: true, save_state_endpoint: null, last_loaded_entries_ids: {}, load_more_entries_endpoint: null, @@ -474,7 +473,9 @@ $(function() let sStimulusCode = (undefined !== oData.stimulus_code) ? oData.stimulus_code : null // If several entry forms filled, show a confirmation message - if ((true === this.options.show_multiple_entries_submit_confirmation) && (Object.keys(this._GetEntriesFromAllForms()).length > 1)) { + if ((GetUserPreference('activity_panel.show_multiple_entries_submit_confirmation',true) === true + || GetUserPreference('activity_panel.show_multiple_entries_submit_confirmation', true) === "true") + && (Object.keys(this._GetEntriesFromAllForms()).length > 1)) { this._ShowEntriesSubmitConfirmation(sStimulusCode); } // Else push data directly to the server @@ -916,7 +917,6 @@ $(function() _SaveSubmitConfirmationPref: function() { // Note: We have to send the value as a string because of the API limitation - this.options.show_multiple_entries_submit_confirmation = false; SetUserPreference('activity_panel.show_multiple_entries_submit_confirmation', 'false', true); }, /** diff --git a/js/utils.js b/js/utils.js index 7cdbb307aa..c49461929e 100644 --- a/js/utils.js +++ b/js/utils.js @@ -213,10 +213,15 @@ function SetUserPreference(sPreferenceCode, sPrefValue, bPersistent) { } catch (err) { sPreviousValue = undefined; } - oUserPreferences[sPreferenceCode] = sPrefValue; if (bPersistent && (sPrefValue != sPreviousValue)) { - ajax_request = $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php', - {operation: 'set_pref', code: sPreferenceCode, value: sPrefValue}); // Make it persistent + return $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php', + {operation: 'set_pref', code: sPreferenceCode, value: sPrefValue}, function (data) { + //do nothing + }).done(function() { + oUserPreferences[sPreferenceCode] = sPrefValue; + }); // Make it persistent + } else { + oUserPreferences[sPreferenceCode] = sPrefValue; } } diff --git a/sources/Application/UI/Base/Layout/ActivityPanel/ActivityPanel.php b/sources/Application/UI/Base/Layout/ActivityPanel/ActivityPanel.php index 21d3abbc29..2eb9aa7fb0 100644 --- a/sources/Application/UI/Base/Layout/ActivityPanel/ActivityPanel.php +++ b/sources/Application/UI/Base/Layout/ActivityPanel/ActivityPanel.php @@ -132,7 +132,6 @@ public function __construct(DBObject $oObject, array $aEntries = [], ?string $sI $this->bAreEntriesSorted = false; $this->bHasMoreEntriesToLoad = false; $this->aLastLoadedEntriesIds = []; - $this->ComputedShowMultipleEntriesSubmitConfirmation(); } /** @@ -960,18 +959,4 @@ public function GetSubBlocks(): array return $aSubBlocks; } - /** - * @see static::$bShowMultipleEntriesSubmitConfirmation - * @return $this - * @throws \CoreException - * @throws \CoreUnexpectedValue - * @throws \MySQLException - */ - protected function ComputedShowMultipleEntriesSubmitConfirmation() - { - // Note: Test on a string is necessary as we can only store strings from the JS API, not booleans. - // Note 2: Do not invert the test to "=== 'true'" as it won't work. Default value is a bool ("true"), values from the DB are strings (true|false) - $this->bShowMultipleEntriesSubmitConfirmation = appUserPreferences::GetPref('activity_panel.show_multiple_entries_submit_confirmation', static::DEFAULT_SHOW_MULTIPLE_ENTRIES_SUBMI_CONFIRMATION) !== 'false'; - return $this; - } } \ No newline at end of file diff --git a/templates/base/layouts/activity-panel/layout.js.twig b/templates/base/layouts/activity-panel/layout.js.twig index 5797b91e24..5c4986a276 100644 --- a/templates/base/layouts/activity-panel/layout.js.twig +++ b/templates/base/layouts/activity-panel/layout.js.twig @@ -5,7 +5,6 @@ $('#{{ oUIBlock.GetId() }}').activity_panel({ lock_enabled: {{ oUIBlock.IsLockEnabled()|var_export }}, lock_watcher_period: {{ oUIBlock.GetLockWatcherPeriod() }}, lock_endpoint: {{ oUIBlock.GetLockEndpoint()|var_export|raw }}, - show_multiple_entries_submit_confirmation: {{ oUIBlock.GetShowMultipleEntriesSubmitConfirmation()|var_export }}, save_state_endpoint: {{ oUIBlock.GetSaveStateEndpoint()|var_export|raw }}, last_loaded_entries_ids: {{ oUIBlock.GetLastEntryIds()|json_encode|raw }}, load_more_entries_endpoint: {{ oUIBlock.GetLoadMoreEntriesEndpoint()|var_export|raw }},