This repository has been archived on 2025-01-01. You can view files and clone it, but cannot push or open issues or pull requests.
moodle-local_treestudyplan/amd/src/util/settings.js
2024-04-21 23:08:03 +02:00

42 lines
No EOL
910 B
JavaScript

/*eslint no-var: "error" */
/*eslint-env es6*/
import {call} from 'core/ajax';
import notification from 'core/notification';
// Prepare default value.
let settingcache = null;
/**
* Check if premium status is enabled.
* @param {String} key
* @returns {}
*/
export function settings ( key ){
const settings = loadsettings();
if ( key in settings ) {
return settings[key];
} else {
return null;
}
}
/**
* Get settings from server or cache
* @returns {Object} The settings object
*/
function loadsettings() {
if (!settingcache) {
// Retrieve setting cache if needed.
call([{
methodname: 'local_treestudyplan_getsettings',
args: {}
}])[0].then(function(response){
settingcache = response;
}).catch(notification.exception);
}
return settingcache;
}
// Preload premium status.
loadsettings();