N°3617 collapsible components state saving : use user pref instead of localStorage

No migration from existing localStorage keys (introduced in 2.5.0 with N°1030) as the console UI has dramatically change in 3.0.0 : will be useful to show all the collapsible sections content once again !

Note that an iTop instance identifier was used in the localStorage key, it is no longer needed as we're getting the user pref directly from the current instance.

Thanks @Molkobain for the help !
This commit is contained in:
Pierre Goiffon
2021-01-12 18:14:25 +01:00
parent 09da54ee56
commit 790a675d90
7 changed files with 49 additions and 41 deletions

View File

@@ -346,17 +346,41 @@ function SetUserPreference(sPreferenceCode, sPrefValue, bPersistent) {
/**
* Get user specific preferences
* depends on a global variable oUserPreferences created/filled by the iTopWebPage
* that acts as a local -write through- cache
* @borrows global variable oUserPreferences created/filled by the iTopWebPage if login method was called
*/
function GetUserPreference(sPreferenceCode, sDefaultValue) {
var value = sDefaultValue;
if ((typeof(oUserPreferences) !== 'undefined') && (typeof(oUserPreferences[sPreferenceCode]) !== 'undefined')) {
if ((typeof (oUserPreferences) !== 'undefined') && (typeof (oUserPreferences[sPreferenceCode]) !== 'undefined')) {
value = oUserPreferences[sPreferenceCode];
}
return value;
}
/**
* @param {string} sPreferenceCode
* @param {boolean} bDefaultValue
* @returns {boolean}
* @since 3.0.0
*/
function GetUserPreferenceAsBoolean(sPreferenceCode, bDefaultValue) {
let sVal = GetUserPreference(sPreferenceCode, bDefaultValue);
try {
sVal = sVal.toLowerCase();
} catch (error) {
// nothing : this may be the boolean default value !
}
if (sVal === "true") {
return true;
}
if (sVal === "false") {
return false;
}
return bDefaultValue;
}
/**
* Check/uncheck a whole list of checkboxes
*/