From 5ab7519c8d7d651defeb6da7d8a695a0e418443e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Wed, 31 May 2017 17:14:31 +0200 Subject: [PATCH] ForestDisplay update node. - ForestDisplay update method update the container without re-rendering from scratch the object. This allows persistance of properties set by other components. - Fix unselect on basket updates from keyboard. --- kfet/static/kfet/js/kfet.api.js | 7 ++----- kfet/static/kfet/js/kpsul.js | 29 +++++++++++++++++++---------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/kfet/static/kfet/js/kfet.api.js b/kfet/static/kfet/js/kfet.api.js index e92d9f54..1fb62eb5 100644 --- a/kfet/static/kfet/js/kfet.api.js +++ b/kfet/static/kfet/js/kfet.api.js @@ -1517,11 +1517,8 @@ class ForestDisplay { * @param {Object} data */ update(data) { - var modelname = data.constructor.verbose_name; - var $new_elt = data.display($(this._templates[modelname]), {}); - - var $to_replace = this.get_dom(data).children(":first-child"); - $to_replace.replaceWith($new_elt); + let $container = $(this.get_dom(data).children()[0]); + data.display($container, {}); } delete(data) { diff --git a/kfet/static/kfet/js/kpsul.js b/kfet/static/kfet/js/kpsul.js index 447dde14..37c46fa3 100644 --- a/kfet/static/kfet/js/kpsul.js +++ b/kfet/static/kfet/js/kpsul.js @@ -712,6 +712,7 @@ class BasketManager { add_purchase(article, nb) { let found = this.find_purchase(article); + if (found) { let new_nb = found.article_nb + nb; if (new_nb > 0) { @@ -918,39 +919,36 @@ class BasketSelection { constructor(basket) { this.basket = basket; + this._$container = basket._$container; this._init(); } _init() { - this.basket._$container.selectable({ + this._$container.selectable({ filter: ".basket-item" }); this._init_events(); } _init_events() { + let that = this; let basket = this.basket; $(document).on('keydown', function (e) { switch(e.which) { case 46: // DEL (Suppr) - basket._$container.find('.ui-selected').each( function() { - let item = $(this).parent().data("object"); - basket.delete(item.id); - }); + that.get().each( (_, item) => basket.delete(item.id) ); break; case 38: // Arrow up - basket._$container.find('.ui-selected').each( function() { - let item = $(this).parent().data("object"); + that.get().each( (_, item) => { if (item instanceof PurchaseBasket) basket.add_purchase(item.article, 1); }); break; case 40: // Arrow down - basket._$container.find('.ui-selected').each( function() { - let item = $(this).parent().data("object"); + that.get().each( (_, item) => { if (item instanceof PurchaseBasket) basket.add_purchase(item.article, -1); }); @@ -959,8 +957,19 @@ class BasketSelection { }); } + get() { + return this.$get().map( function() { + return $(this).parent().data("object"); + }); + } + reset() { - this.basket._$container.find('.ui-selected').removeClass('.ui-selected'); + this.$get().removeClass('ui-selected'); + } + + $get() { + let filter = this._$container.selectable('option', 'filter'); + return this._$container.find(filter+'.ui-selected'); } }