forked from DGNum/gestioCOF
Change node.type to node.modelname for clarity
This commit is contained in:
parent
fc3e86aea6
commit
3465dd7045
3 changed files with 17 additions and 17 deletions
|
@ -560,7 +560,7 @@ class Article extends ModelObject {
|
|||
class TreeNode {
|
||||
|
||||
constructor(type, content) {
|
||||
this.type = type;
|
||||
this.modelname = type;
|
||||
this.content = content;
|
||||
this.parent = null;
|
||||
this.children = [];
|
||||
|
@ -611,15 +611,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 = data.child_sort
|
||||
|
@ -671,11 +671,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);
|
||||
|
@ -695,13 +695,13 @@ class ModelForest {
|
|||
var existing = node.parent ;
|
||||
var first_missing = node;
|
||||
|
||||
while (existing && !($container.find('#'+existing.type+'-'+existing.id))) {
|
||||
while (existing && !($container.find('#'+existing.modelname+'-'+existing.id))) {
|
||||
first_missing = existing ;
|
||||
existing = existing.parent;
|
||||
}
|
||||
|
||||
var $to_insert = render_element(first_missing, templates, options);
|
||||
var $insert_in = existing ? $container.find('#'+existing.type+'-'+existing.id)
|
||||
var $insert_in = existing ? $container.find('#'+existing.modelname+'-'+existing.id)
|
||||
: $container ;
|
||||
$insert_in.prepend($to_insert);
|
||||
}
|
||||
|
@ -741,7 +741,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 ;
|
||||
}
|
||||
|
||||
|
|
|
@ -528,7 +528,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 +557,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 +584,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();
|
||||
}
|
||||
|
|
|
@ -1349,7 +1349,7 @@ def kpsul_articles_data(request):
|
|||
|
||||
for article in articles:
|
||||
articlelist.append({
|
||||
'type': 'article',
|
||||
'modelname': 'article',
|
||||
'content': {
|
||||
'id': article.id,
|
||||
'name': article.name,
|
||||
|
@ -1357,7 +1357,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