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/premium.js

37 lines
No EOL
876 B
JavaScript

/*eslint no-var: "error" */
/*eslint-env es6*/
import {call} from 'core/ajax';
import notification from 'core/notification';
// Prepare default value.
let premiumstatus_cache = null;
/**
* Check if premium status is enabled.
* @returns {Bool} True/False
*/
export function premiumenabled (){
const premium = premiumstatus();
return (premium.enabled)?true:false;
}
/**
* Get premium status object
* @returns {Object} The premium status object
*/
function premiumstatus() {
if (!premiumstatus_cache) {
// Retrieve premium status if needed.
call([{
methodname: 'local_treestudyplan_premiumstatus',
args: {}
}])[0].then(function(response){
premiumstatus_cache = response;
}).catch(notification.exception);
}
return premiumstatus_cache;
}
// Preload premium status.
premiumstatus();