Merge branch 'aureplop/kpsul_js_refactor' of git.eleves.ens.fr:cof-geek/gestioCOF into Aufinal/dialog_utils
This commit is contained in:
commit
6d92df4155
2 changed files with 71 additions and 62 deletions
|
@ -4,65 +4,6 @@
|
|||
* @license MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get and store K-Psul config from API.
|
||||
* <br><br>
|
||||
*
|
||||
* Config should be accessed statically only.
|
||||
*/
|
||||
class Config {
|
||||
|
||||
/**
|
||||
* Get or create config object.
|
||||
* @private
|
||||
* @return {object} object - config keys/values
|
||||
*/
|
||||
static _get_or_create_config() {
|
||||
if (window.config === undefined)
|
||||
window.config = {};
|
||||
return window.config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get config from API.
|
||||
* @param {jQueryAjaxComplete} [callback] - A function to be called when
|
||||
* the request finishes.
|
||||
*/
|
||||
static reset(callback) {
|
||||
$.getJSON(Urls['kfet.kpsul.get_settings']())
|
||||
.done(function(data) {
|
||||
for (var key in data) {
|
||||
Config.set(key, data[key]);
|
||||
}
|
||||
})
|
||||
.always(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value for key in config.
|
||||
* @param {string} key
|
||||
*/
|
||||
static get(key) {
|
||||
return this._get_or_create_config()[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value for key in config.
|
||||
* @param {string} key
|
||||
* @param {*} value
|
||||
*/
|
||||
static set(key, value) {
|
||||
// API currently returns string for Decimal type
|
||||
if (['addcost_amount', 'subvention_cof'].indexOf(key) > -1)
|
||||
value = floatCheck(value);
|
||||
this._get_or_create_config()[key] = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* ---------- ---------- */
|
||||
|
||||
|
||||
/**
|
||||
* Virtual namespace for models.
|
||||
|
@ -137,14 +78,23 @@ class ModelObject {
|
|||
*/
|
||||
from(data) {
|
||||
// TODO: add restrict
|
||||
$.extend(this, this.constructor.default_data, data);
|
||||
this.clear();
|
||||
this.update(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update properties of this instance from data ones.
|
||||
* @param {Object} data
|
||||
*/
|
||||
update(data) {
|
||||
$.extend(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear properties to {@link Models.ModelObject.default_data|default_data}.
|
||||
*/
|
||||
clear() {
|
||||
this.from({});
|
||||
$.extend(this, this.constructor.default_data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -155,10 +105,12 @@ class ModelObject {
|
|||
* @param {Formatters.Formatter}
|
||||
* [formatter={@link Models.ModelObject#formatter|this.formatter()}]
|
||||
* Formatter class to use.
|
||||
* @return {jQuery} The DOM element $container, allowing methods chaining.
|
||||
*/
|
||||
display($container, options, formatter) {
|
||||
formatter = formatter || this.formatter();
|
||||
formatter.render(this, $container, options);
|
||||
return $container;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -232,7 +184,7 @@ class APIModelObject extends ModelObject {
|
|||
|
||||
$.getJSON(this.url_object, api_options)
|
||||
.done(function (json, textStatus, jqXHR) {
|
||||
that.from(json)
|
||||
that.from(json);
|
||||
on_success(json, textStatus, jqXHR);
|
||||
})
|
||||
.fail(on_error);
|
||||
|
|
|
@ -40,6 +40,63 @@ function booleanCheck(v) {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get and store K-Psul config from API.
|
||||
* <br><br>
|
||||
*
|
||||
* Config should be accessed statically only.
|
||||
*/
|
||||
class Config {
|
||||
|
||||
/**
|
||||
* Get or create config object.
|
||||
* @private
|
||||
* @return {object} object - config keys/values
|
||||
*/
|
||||
static _get_or_create_config() {
|
||||
if (window.config === undefined)
|
||||
window.config = {};
|
||||
return window.config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get config from API.
|
||||
* @param {jQueryAjaxComplete} [callback] - A function to be called when
|
||||
* the request finishes.
|
||||
*/
|
||||
static reset(callback) {
|
||||
$.getJSON(Urls['kfet.kpsul.get_settings']())
|
||||
.done(function(data) {
|
||||
for (var key in data) {
|
||||
Config.set(key, data[key]);
|
||||
}
|
||||
})
|
||||
.always(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value for key in config.
|
||||
* @param {string} key
|
||||
*/
|
||||
static get(key) {
|
||||
return this._get_or_create_config()[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value for key in config.
|
||||
* @param {string} key
|
||||
* @param {*} value
|
||||
*/
|
||||
static set(key, value) {
|
||||
// API currently returns string for Decimal type
|
||||
if (['addcost_amount', 'subvention_cof'].indexOf(key) > -1)
|
||||
value = floatCheck(value);
|
||||
this._get_or_create_config()[key] = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
$(window).scroll(function() {
|
||||
if ($(window).width() >= 768 && $(this).scrollTop() > 72.6) {
|
||||
|
|
Loading…
Reference in a new issue