forked from DGNum/gestioCOF
Merge branch 'Aufinal/refactor_articles' into Aufinal/refactor_history
This commit is contained in:
commit
fe965875f7
5 changed files with 31 additions and 25 deletions
|
@ -304,6 +304,10 @@ input[type=number]::-webkit-outer-spin-button {
|
|||
font-size:14px;
|
||||
}
|
||||
|
||||
#articles_data .article[data_stock="low"] {
|
||||
background:rgba(236,100,0,0.3);
|
||||
}
|
||||
|
||||
#articles_data span {
|
||||
height:25px;
|
||||
line-height:25px;
|
||||
|
|
|
@ -852,7 +852,7 @@ class Transfer extends Operation {
|
|||
class TreeNode {
|
||||
|
||||
constructor(type, content) {
|
||||
this.type = type;
|
||||
this.modelname = type;
|
||||
this.content = content;
|
||||
this.parent = null;
|
||||
this.children = [];
|
||||
|
@ -903,15 +903,15 @@ class ModelForest {
|
|||
* @param {number} direction
|
||||
*/
|
||||
get_or_create(data, direction) {
|
||||
var model = this.constructor.models[data.type];
|
||||
var model = this.constructor.models[data.modelname];
|
||||
|
||||
var existing = this.find(data.type, data.content.id);
|
||||
var existing = this.find(data.modelname, data.content.id);
|
||||
if (existing) {
|
||||
return existing;
|
||||
}
|
||||
|
||||
var content = new this.constructor.models[data.type](data.content);
|
||||
var node = new TreeNode(data.type, content);
|
||||
var content = new this.constructor.models[data.modelname](data.content);
|
||||
var node = new TreeNode(data.modelname, content);
|
||||
|
||||
if (data.child_sort)
|
||||
node.child_sort = this.constructor.models[data.child_sort];
|
||||
|
@ -965,11 +965,11 @@ class ModelForest {
|
|||
* @param {Object} [options] Options for element render method
|
||||
*/
|
||||
render_element(node, templates, options) {
|
||||
var template = templates[node.type];
|
||||
var template = templates[node.modelname];
|
||||
var options = options || {} ;
|
||||
|
||||
var $container = $('<div></div>');
|
||||
$container.attr('id', node.type+'-'+node.content.id);
|
||||
$container.attr('id', node.modelname+'-'+node.content.id);
|
||||
|
||||
var $rendered = node.content.display($(template), options);
|
||||
$container.append($rendered);
|
||||
|
@ -997,14 +997,14 @@ class ModelForest {
|
|||
var existing = node.parent ;
|
||||
var first_missing = node;
|
||||
|
||||
while (existing && !($container.find('#'+existing.type+'-'+existing.content.id).length)) {
|
||||
while (existing && !($container.find('#'+existing.modelname+'-'+existing.id).length)) {
|
||||
first_missing = existing ;
|
||||
existing = existing.parent;
|
||||
}
|
||||
|
||||
var $to_insert = this.render_element(first_missing, templates, options);
|
||||
if (existing) {
|
||||
$container.find('#'+existing.type+'-'+existing.content.id+'>:first-child').after($to_insert);
|
||||
$container.find('#'+existing.modelname+'-'+existing.content.id+'>:first-child').after($to_insert);
|
||||
} else {
|
||||
$container.prepend($to_insert);
|
||||
}
|
||||
|
@ -1045,7 +1045,7 @@ class ModelForest {
|
|||
find(type, id) {
|
||||
var result = null;
|
||||
function callback(node) {
|
||||
if (node.type === type && node.content.id == id)
|
||||
if (node.modelname === type && node.content.id == id)
|
||||
result = node ;
|
||||
}
|
||||
|
||||
|
@ -1446,6 +1446,10 @@ class ArticleFormatter extends Formatter {
|
|||
return Article.props;
|
||||
}
|
||||
|
||||
static get attrs() {
|
||||
return ['data_stock'];
|
||||
}
|
||||
|
||||
/**
|
||||
* <tt>s.price</tt> converted to UKF.
|
||||
*/
|
||||
|
@ -1464,7 +1468,7 @@ class ArticleFormatter extends Formatter {
|
|||
* Value of data_stock attribute based on s.stock.
|
||||
*/
|
||||
static attr_data_stock(s) {
|
||||
if (s.stock >= 5) { return this._data_stock.ok; }
|
||||
if (s.stock > 5) { return this._data_stock.ok; }
|
||||
else if (s.stock >= -5) { return this._data_stock.low; }
|
||||
else /* s.stock < -5 */{ return this._data_stock.neg; }
|
||||
}
|
||||
|
|
|
@ -416,9 +416,10 @@ class ArticleManager {
|
|||
this.list.fromAPI({}, this.display_list.bind(this), $.noop) ;
|
||||
}
|
||||
|
||||
//TODO: filter articles before ?
|
||||
update_data(data) {
|
||||
for (let article_dict of data) {
|
||||
article = this.list.find('article', article_dict['id']);
|
||||
for (let article_dict of data.articles) {
|
||||
var article = this.list.find('article', article_dict['id']);
|
||||
|
||||
// For now, article additions are disregarded
|
||||
if (article) {
|
||||
|
@ -528,7 +529,7 @@ class ArticleAutocomplete {
|
|||
var that = this ;
|
||||
|
||||
article_list.traverse(function(node) {
|
||||
if (node.type === 'article' &&
|
||||
if (node.modelname === 'article' &&
|
||||
node.content.name.toLowerCase()
|
||||
.startsWith(lower)) {
|
||||
that.matching['article'].push(node.content);
|
||||
|
@ -557,11 +558,11 @@ class ArticleAutocomplete {
|
|||
var that = this;
|
||||
|
||||
this.manager.list.traverse(function(node) {
|
||||
if (that.matching[node.type].indexOf(node.content) != -1) {
|
||||
that._$container.find('#'+node.type+'-'+node.content.id)
|
||||
if (that.matching[node.modelname].indexOf(node.content) != -1) {
|
||||
that._$container.find('#'+node.modelname+'-'+node.content.id)
|
||||
.show();
|
||||
} else {
|
||||
that._$container.find('#'+node.type+'-'+node.content.id)
|
||||
that._$container.find('#'+node.modelname+'-'+node.content.id)
|
||||
.hide();
|
||||
}
|
||||
});
|
||||
|
@ -584,7 +585,7 @@ class ArticleAutocomplete {
|
|||
var that = this;
|
||||
this.resetMatch();
|
||||
this.manager.list.traverse(function(node) {
|
||||
that.matching[node.type].push(node.content);
|
||||
that.matching[node.modelname].push(node.content);
|
||||
});
|
||||
this.updateDisplay();
|
||||
}
|
||||
|
|
|
@ -648,11 +648,8 @@ $(document).ready(function() {
|
|||
displayCheckoutData();
|
||||
}
|
||||
}
|
||||
/* for (var i=0; i<data['articles'].length; i++) {
|
||||
var article = data['articles'][i];
|
||||
articles_container.find('#data-article-'+article['id']+' .stock')
|
||||
.text(article['stock']);
|
||||
}*/
|
||||
kpsul.article_manager.update_data(data);
|
||||
|
||||
if (data['addcost']) {
|
||||
Config.set('addcost_for', data['addcost']['for']);
|
||||
Config.set('addcost_amount', data['addcost']['amount']);
|
||||
|
|
|
@ -1546,7 +1546,7 @@ def kpsul_articles_data(request):
|
|||
|
||||
for article in articles:
|
||||
articlelist.append({
|
||||
'type': 'article',
|
||||
'modelname': 'article',
|
||||
'content': {
|
||||
'id': article.id,
|
||||
'name': article.name,
|
||||
|
@ -1554,7 +1554,7 @@ def kpsul_articles_data(request):
|
|||
'stock': article.stock,
|
||||
},
|
||||
'parent': {
|
||||
'type': 'category',
|
||||
'modelname': 'category',
|
||||
'content': {
|
||||
'id': article.category.id,
|
||||
'name': article.category.name,
|
||||
|
|
Loading…
Reference in a new issue