Adapt ArticleManager
This commit is contained in:
parent
46ac82fd27
commit
5096e5f129
1 changed files with 21 additions and 24 deletions
|
@ -426,12 +426,16 @@ class ArticleManager {
|
||||||
this._$input = $('#article_autocomplete');
|
this._$input = $('#article_autocomplete');
|
||||||
this._$nb = $('#article_number');
|
this._$nb = $('#article_number');
|
||||||
this._$stock = $('#article_stock');
|
this._$stock = $('#article_stock');
|
||||||
this.templates = {'category': '<div class="category"><span class="name"></span></div>',
|
|
||||||
'article' : '<div class="article"><span class="name"></span><span class="price"></span><span class="stock"></span></div>'}
|
|
||||||
|
|
||||||
this.selected = new Article() ;
|
this.selected = new Article() ;
|
||||||
this.list = new ArticleList() ;
|
this.data = new ArticleList() ;
|
||||||
this.autocomplete = new ArticleAutocomplete(this);
|
var $container = $('#articles_data');
|
||||||
|
var templates = {
|
||||||
|
'category': '<div class="category"><span class="name"></span></div>',
|
||||||
|
'article' : '<div class="article"><span class="name"></span><span class="price"></span><span class="stock"></span></div>'
|
||||||
|
} ;
|
||||||
|
this.display = new ForestDisplay($container, templates);
|
||||||
|
this.autocomplete = new ArticleAutocomplete(this, $container);
|
||||||
|
|
||||||
this._init_events();
|
this._init_events();
|
||||||
}
|
}
|
||||||
|
@ -441,7 +445,7 @@ class ArticleManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
display_list() {
|
display_list() {
|
||||||
this.list.display(this._$container, this.templates) ;
|
this.display.render(this.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
validate(article) {
|
validate(article) {
|
||||||
|
@ -461,25 +465,18 @@ class ArticleManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_data() {
|
reset_data() {
|
||||||
this._$container.html('');
|
this.display.clear();
|
||||||
this.list.clear();
|
this.data.clear();
|
||||||
this.list.fromAPI()
|
this.data.fromAPI()
|
||||||
.done( () => this.display_list() );
|
.done( () => this.display_list() );
|
||||||
}
|
}
|
||||||
|
|
||||||
get_article(id) {
|
|
||||||
return this.list.find('article', id);
|
|
||||||
}
|
|
||||||
|
|
||||||
update_data(data) {
|
update_data(data) {
|
||||||
for (let article_dict of data.articles) {
|
for (let article_dict of data.articles) {
|
||||||
var article = this.get_article(article_dict.id);
|
|
||||||
|
|
||||||
// For now, article additions are disregarded
|
var updated = this.data.update('article', article_dict.id, article_dict);
|
||||||
if (article) {
|
if (updated) {
|
||||||
article.stock = article_dict.stock;
|
this.display.update(updated);
|
||||||
this._$container.find('#article-'+article.id+' .stock')
|
|
||||||
.text(article.stock);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -508,7 +505,7 @@ class ArticleManager {
|
||||||
|
|
||||||
this._$container.on('click', '.article', function() {
|
this._$container.on('click', '.article', function() {
|
||||||
var id = $(this).parent().attr('id').split('-')[1];
|
var id = $(this).parent().attr('id').split('-')[1];
|
||||||
var article = that.list.find('article', id);
|
var article = that.data.find('article', id);
|
||||||
if (article)
|
if (article)
|
||||||
that.validate(article);
|
that.validate(article);
|
||||||
});
|
});
|
||||||
|
@ -547,9 +544,9 @@ class ArticleManager {
|
||||||
|
|
||||||
class ArticleAutocomplete {
|
class ArticleAutocomplete {
|
||||||
|
|
||||||
constructor(article_manager) {
|
constructor(article_manager, $container) {
|
||||||
this.manager = article_manager;
|
this.manager = article_manager;
|
||||||
this._$container = article_manager._$container ;
|
this._$container = $container ;
|
||||||
this._$input = $('#article_autocomplete');
|
this._$input = $('#article_autocomplete');
|
||||||
|
|
||||||
this.showAll() ;
|
this.showAll() ;
|
||||||
|
@ -583,7 +580,7 @@ class ArticleAutocomplete {
|
||||||
update(prefix, backspace) {
|
update(prefix, backspace) {
|
||||||
|
|
||||||
this.resetMatch();
|
this.resetMatch();
|
||||||
var article_list = this.manager.list ;
|
var article_list = this.manager.data ;
|
||||||
var lower = prefix.toLowerCase() ;
|
var lower = prefix.toLowerCase() ;
|
||||||
var that = this ;
|
var that = this ;
|
||||||
|
|
||||||
|
@ -611,7 +608,7 @@ class ArticleAutocomplete {
|
||||||
updateDisplay() {
|
updateDisplay() {
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
this.manager.list.traverse('category', function(category) {
|
this.manager.data.traverse('category', function(category) {
|
||||||
var is_active = false;
|
var is_active = false;
|
||||||
for (let article of category.articles) {
|
for (let article of category.articles) {
|
||||||
if (that.matching.indexOf(article) != -1) {
|
if (that.matching.indexOf(article) != -1) {
|
||||||
|
@ -646,7 +643,7 @@ class ArticleAutocomplete {
|
||||||
showAll() {
|
showAll() {
|
||||||
var that = this;
|
var that = this;
|
||||||
this.resetMatch();
|
this.resetMatch();
|
||||||
this.manager.list.traverse('article', function(article) {
|
this.manager.data.traverse('article', function(article) {
|
||||||
that.matching.push(article);
|
that.matching.push(article);
|
||||||
});
|
});
|
||||||
this.updateDisplay();
|
this.updateDisplay();
|
||||||
|
|
Loading…
Reference in a new issue