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:
parent
eff1b7ff19
commit
5ab7519c8d
2 changed files with 21 additions and 15 deletions
|
@ -1517,11 +1517,8 @@ class ForestDisplay {
|
||||||
* @param {Object} data
|
* @param {Object} data
|
||||||
*/
|
*/
|
||||||
update(data) {
|
update(data) {
|
||||||
var modelname = data.constructor.verbose_name;
|
let $container = $(this.get_dom(data).children()[0]);
|
||||||
var $new_elt = data.display($(this._templates[modelname]), {});
|
data.display($container, {});
|
||||||
|
|
||||||
var $to_replace = this.get_dom(data).children(":first-child");
|
|
||||||
$to_replace.replaceWith($new_elt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(data) {
|
delete(data) {
|
||||||
|
|
|
@ -712,6 +712,7 @@ class BasketManager {
|
||||||
|
|
||||||
add_purchase(article, nb) {
|
add_purchase(article, nb) {
|
||||||
let found = this.find_purchase(article);
|
let found = this.find_purchase(article);
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
let new_nb = found.article_nb + nb;
|
let new_nb = found.article_nb + nb;
|
||||||
if (new_nb > 0) {
|
if (new_nb > 0) {
|
||||||
|
@ -918,39 +919,36 @@ class BasketSelection {
|
||||||
|
|
||||||
constructor(basket) {
|
constructor(basket) {
|
||||||
this.basket = basket;
|
this.basket = basket;
|
||||||
|
this._$container = basket._$container;
|
||||||
this._init();
|
this._init();
|
||||||
}
|
}
|
||||||
|
|
||||||
_init() {
|
_init() {
|
||||||
this.basket._$container.selectable({
|
this._$container.selectable({
|
||||||
filter: ".basket-item"
|
filter: ".basket-item"
|
||||||
});
|
});
|
||||||
this._init_events();
|
this._init_events();
|
||||||
}
|
}
|
||||||
|
|
||||||
_init_events() {
|
_init_events() {
|
||||||
|
let that = this;
|
||||||
let basket = this.basket;
|
let basket = this.basket;
|
||||||
$(document).on('keydown', function (e) {
|
$(document).on('keydown', function (e) {
|
||||||
switch(e.which) {
|
switch(e.which) {
|
||||||
case 46:
|
case 46:
|
||||||
// DEL (Suppr)
|
// DEL (Suppr)
|
||||||
basket._$container.find('.ui-selected').each( function() {
|
that.get().each( (_, item) => basket.delete(item.id) );
|
||||||
let item = $(this).parent().data("object");
|
|
||||||
basket.delete(item.id);
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case 38:
|
case 38:
|
||||||
// Arrow up
|
// Arrow up
|
||||||
basket._$container.find('.ui-selected').each( function() {
|
that.get().each( (_, item) => {
|
||||||
let item = $(this).parent().data("object");
|
|
||||||
if (item instanceof PurchaseBasket)
|
if (item instanceof PurchaseBasket)
|
||||||
basket.add_purchase(item.article, 1);
|
basket.add_purchase(item.article, 1);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 40:
|
case 40:
|
||||||
// Arrow down
|
// Arrow down
|
||||||
basket._$container.find('.ui-selected').each( function() {
|
that.get().each( (_, item) => {
|
||||||
let item = $(this).parent().data("object");
|
|
||||||
if (item instanceof PurchaseBasket)
|
if (item instanceof PurchaseBasket)
|
||||||
basket.add_purchase(item.article, -1);
|
basket.add_purchase(item.article, -1);
|
||||||
});
|
});
|
||||||
|
@ -959,8 +957,19 @@ class BasketSelection {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get() {
|
||||||
|
return this.$get().map( function() {
|
||||||
|
return $(this).parent().data("object");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
reset() {
|
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');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue