From 485ae86a4279e82ae493089f8abea0bea7459a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Sun, 26 Mar 2017 14:46:46 +0200 Subject: [PATCH 1/5] add update method to ModelObject --- kfet/static/kfet/js/kfet.api.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kfet/static/kfet/js/kfet.api.js b/kfet/static/kfet/js/kfet.api.js index cc499c57..4f4b21bb 100644 --- a/kfet/static/kfet/js/kfet.api.js +++ b/kfet/static/kfet/js/kfet.api.js @@ -137,14 +137,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); } From b81b33c056c0280d90cc7fcff7a0bbc69f1549ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Sun, 26 Mar 2017 14:51:16 +0200 Subject: [PATCH 2/5] allow chaining on container in display method --- kfet/static/kfet/js/kfet.api.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kfet/static/kfet/js/kfet.api.js b/kfet/static/kfet/js/kfet.api.js index 4f4b21bb..799edfd6 100644 --- a/kfet/static/kfet/js/kfet.api.js +++ b/kfet/static/kfet/js/kfet.api.js @@ -164,10 +164,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; } } From 24f72ae7d45f6a00b7ab1f630c8bcf466d07ad91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Sun, 26 Mar 2017 14:52:23 +0200 Subject: [PATCH 3/5] add missing ; --- kfet/static/kfet/js/kfet.api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kfet/static/kfet/js/kfet.api.js b/kfet/static/kfet/js/kfet.api.js index 799edfd6..4ca087dc 100644 --- a/kfet/static/kfet/js/kfet.api.js +++ b/kfet/static/kfet/js/kfet.api.js @@ -243,7 +243,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); From bc6ecda0c8c16a197a13726e994b3978d2fe074a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Sun, 26 Mar 2017 14:59:21 +0200 Subject: [PATCH 4/5] fix addcost kspul --- kfet/templates/kfet/kpsul.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 15f83076..d69d6829 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -862,7 +862,7 @@ $(document).ready(function() { addcost_html .find('.addcost_for').text(Config.get('addcost_for')).end() .find('.addcost_amount').text(Config.get('addcost_amount').toFixed(2)).end(); - checkout_container.prepend(addcost_html); + kpsul.checkout_manager._$container.prepend(addcost_html); $('body').css('animation', 'colorchange 3s infinite'); } } @@ -919,7 +919,7 @@ $(document).ready(function() { } }); }, - onClose: function() { this._lastFocused = account_manager._$input_trigramme; } + onClose: function() { this._lastFocused = kpsul.account_manager.selection._$input; } }); } From 842f2cecc1f6cd89314fc381b4a3563d34fdf0a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Sun, 26 Mar 2017 15:12:03 +0200 Subject: [PATCH 5/5] fix import, fix ope with addcost enabled, move Config location --- kfet/static/kfet/js/kfet.api.js | 59 --------------------------------- kfet/static/kfet/js/kfet.js | 57 +++++++++++++++++++++++++++++++ kfet/templates/kfet/kpsul.html | 3 +- 3 files changed, 58 insertions(+), 61 deletions(-) diff --git a/kfet/static/kfet/js/kfet.api.js b/kfet/static/kfet/js/kfet.api.js index 4ca087dc..6b1f8fe3 100644 --- a/kfet/static/kfet/js/kfet.api.js +++ b/kfet/static/kfet/js/kfet.api.js @@ -4,65 +4,6 @@ * @license MIT */ -/** - * Get and store K-Psul config from API. - *

- * - * 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. diff --git a/kfet/static/kfet/js/kfet.js b/kfet/static/kfet/js/kfet.js index 0fb5c0e1..cf120fd4 100644 --- a/kfet/static/kfet/js/kfet.js +++ b/kfet/static/kfet/js/kfet.js @@ -40,6 +40,63 @@ function booleanCheck(v) { } +/** + * Get and store K-Psul config from API. + *

+ * + * 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) { diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index d69d6829..bdfdb673 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -13,7 +13,6 @@ - @@ -546,7 +545,7 @@ $(document).ready(function() { function amountEuroPurchase(article_data, nb) { var amount_euro = - article_data[3] * nb ; - if (Config.get('addcost_for') && Config.get('addcost_amount') && account_manager.account.trigramme != Config.get('addcost_for')) + if (Config.get('addcost_for') && Config.get('addcost_amount') && kpsul.account_manager.account.trigramme != Config.get('addcost_for')) amount_euro -= Config.get('addcost_amount') * nb; var reduc_divisor = 1; if (kpsul.account_manager.account.is_cof)