Change node.type to node.modelname for clarity

This commit is contained in:
Ludovic Stephan 2017-03-20 00:26:11 -03:00
parent fc3e86aea6
commit 3465dd7045
3 changed files with 17 additions and 17 deletions

View file

@ -560,7 +560,7 @@ class Article extends ModelObject {
class TreeNode { class TreeNode {
constructor(type, content) { constructor(type, content) {
this.type = type; this.modelname = type;
this.content = content; this.content = content;
this.parent = null; this.parent = null;
this.children = []; this.children = [];
@ -611,15 +611,15 @@ class ModelForest {
* @param {number} direction * @param {number} direction
*/ */
get_or_create(data, 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) { if (existing) {
return existing; return existing;
} }
var content = new this.constructor.models[data.type](data.content); var content = new this.constructor.models[data.modelname](data.content);
var node = new TreeNode(data.type, content); var node = new TreeNode(data.modelname, content);
if (data.child_sort) if (data.child_sort)
node.child_sort = data.child_sort node.child_sort = data.child_sort
@ -671,11 +671,11 @@ class ModelForest {
* @param {Object} [options] Options for element render method * @param {Object} [options] Options for element render method
*/ */
render_element(node, templates, options) { render_element(node, templates, options) {
var template = templates[node.type]; var template = templates[node.modelname];
var options = options || {} ; var options = options || {} ;
var $container = $('<div></div>'); 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); var $rendered = node.content.display($(template), options);
$container.append($rendered); $container.append($rendered);
@ -695,13 +695,13 @@ class ModelForest {
var existing = node.parent ; var existing = node.parent ;
var first_missing = node; var first_missing = node;
while (existing && !($container.find('#'+existing.type+'-'+existing.id))) { while (existing && !($container.find('#'+existing.modelname+'-'+existing.id))) {
first_missing = existing ; first_missing = existing ;
existing = existing.parent; existing = existing.parent;
} }
var $to_insert = render_element(first_missing, templates, options); 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 ; : $container ;
$insert_in.prepend($to_insert); $insert_in.prepend($to_insert);
} }
@ -741,7 +741,7 @@ class ModelForest {
find(type, id) { find(type, id) {
var result = null; var result = null;
function callback(node) { function callback(node) {
if (node.type === type && node.content.id == id) if (node.modelname === type && node.content.id == id)
result = node ; result = node ;
} }

View file

@ -528,7 +528,7 @@ class ArticleAutocomplete {
var that = this ; var that = this ;
article_list.traverse(function(node) { article_list.traverse(function(node) {
if (node.type === 'article' && if (node.modelname === 'article' &&
node.content.name.toLowerCase() node.content.name.toLowerCase()
.startsWith(lower)) { .startsWith(lower)) {
that.matching['article'].push(node.content); that.matching['article'].push(node.content);
@ -557,11 +557,11 @@ class ArticleAutocomplete {
var that = this; var that = this;
this.manager.list.traverse(function(node) { this.manager.list.traverse(function(node) {
if (that.matching[node.type].indexOf(node.content) != -1) { if (that.matching[node.modelname].indexOf(node.content) != -1) {
that._$container.find('#'+node.type+'-'+node.content.id) that._$container.find('#'+node.modelname+'-'+node.content.id)
.show(); .show();
} else { } else {
that._$container.find('#'+node.type+'-'+node.content.id) that._$container.find('#'+node.modelname+'-'+node.content.id)
.hide(); .hide();
} }
}); });
@ -584,7 +584,7 @@ class ArticleAutocomplete {
var that = this; var that = this;
this.resetMatch(); this.resetMatch();
this.manager.list.traverse(function(node) { this.manager.list.traverse(function(node) {
that.matching[node.type].push(node.content); that.matching[node.modelname].push(node.content);
}); });
this.updateDisplay(); this.updateDisplay();
} }

View file

@ -1349,7 +1349,7 @@ def kpsul_articles_data(request):
for article in articles: for article in articles:
articlelist.append({ articlelist.append({
'type': 'article', 'modelname': 'article',
'content': { 'content': {
'id': article.id, 'id': article.id,
'name': article.name, 'name': article.name,
@ -1357,7 +1357,7 @@ def kpsul_articles_data(request):
'stock': article.stock, 'stock': article.stock,
}, },
'parent': { 'parent': {
'type': 'category', 'modelname': 'category',
'content': { 'content': {
'id': article.category.id, 'id': article.category.id,
'name': article.category.name, 'name': article.category.name,