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.
This commit is contained in:
Aurélien Delobelle 2017-05-31 17:14:31 +02:00
parent eff1b7ff19
commit 5ab7519c8d
2 changed files with 21 additions and 15 deletions

View file

@ -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) {

View file

@ -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');
}
}