From a29de134f165be6ca072f70fbcd62663c5444bcf Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Wed, 5 Apr 2017 08:58:46 -0300 Subject: [PATCH] Move focus ; move is_low_stock to method --- kfet/static/kfet/js/kfet.api.js | 4 ++++ kfet/static/kfet/js/kpsul.js | 2 +- kfet/templates/kfet/kpsul.html | 12 ++++-------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/kfet/static/kfet/js/kfet.api.js b/kfet/static/kfet/js/kfet.api.js index 293ff6a2..3fb3860e 100644 --- a/kfet/static/kfet/js/kfet.api.js +++ b/kfet/static/kfet/js/kfet.api.js @@ -502,6 +502,10 @@ class Article extends ModelObject { // API currently returns a string object (serialization of Decimal type within Django) get price() { return this._price; } set price(v) { this._price = floatCheck(v); } + + is_low_stock(nb) { + return (-5 <= this.stock - nb && this.stock - nb <= 5); + } } diff --git a/kfet/static/kfet/js/kpsul.js b/kfet/static/kfet/js/kpsul.js index 0027543e..9474e46f 100644 --- a/kfet/static/kfet/js/kpsul.js +++ b/kfet/static/kfet/js/kpsul.js @@ -98,7 +98,7 @@ class AccountManager { $('#id_on_acc').val(this.account.id); this.display(); - kpsul.article_manager.focus(); + kpsul.focus(); kpsul._env.updateBasketAmount(); kpsul._env.updateBasketRel(); } diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index c1243d4a..38a9e323 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -191,7 +191,7 @@ $(document).ready(function() { commentDialog.open({ callback: confirm_callback, - next_focus: kpsul.article_manager, + next_focus: kpsul, }); } @@ -237,7 +237,7 @@ $(document).ready(function() { else displayErrors(getErrorsHtml(response)); }, - next_focus: kpsul.article_manager, + next_focus: kpsul, }); } @@ -312,17 +312,13 @@ $(document).ready(function() { .find('.name').text(article.name).end() .find('.amount').text(amountToUKF(amount_euro, kpsul.account_manager.account.is_cof)); basket_container.prepend(article_basket_html); - if (is_low_stock(article, nb)) + if (article.is_low_stock(nb)) article_basket_html.find('.lowstock') .show(); updateBasketRel(); } } - function is_low_stock(article, nb) { - return (-5 <= article.stock - nb && article.stock - nb <= 5); - } - function addDeposit(amount) { var deposit_basket_html = $(item_basket_default_html); var amount = parseFloat(amount).toFixed(2); @@ -481,7 +477,7 @@ $(document).ready(function() { } - if (is_low_stock(article, nb_after)) + if (article.is_low_stock(nb_after)) article_html.find('.lowstock') .show(); else