forked from DGNum/gestioCOF
Change child sort + bugfix grom prev commit
This commit is contained in:
parent
73fb3c419e
commit
9ad208a171
1 changed files with 14 additions and 12 deletions
|
@ -669,7 +669,11 @@ class ModelForest {
|
||||||
var children = this.get_children(node);
|
var children = this.get_children(node);
|
||||||
|
|
||||||
if (children) {
|
if (children) {
|
||||||
children.sort(struct_data.child_sort);
|
if (struct_data.child_sort)
|
||||||
|
children.sort(struct_data.child_sort);
|
||||||
|
else
|
||||||
|
children.sort(children[0].constructor.compare);
|
||||||
|
|
||||||
for (let child of children) {
|
for (let child of children) {
|
||||||
var $child = this.render_element(child, templates, options);
|
var $child = this.render_element(child, templates, options);
|
||||||
$container.append($child);
|
$container.append($child);
|
||||||
|
@ -702,7 +706,11 @@ class ModelForest {
|
||||||
* @param {Object} [options] Options for element render method
|
* @param {Object} [options] Options for element render method
|
||||||
*/
|
*/
|
||||||
display($container, templates, options) {
|
display($container, templates, options) {
|
||||||
this.roots.sort(this.constructor.root_sort);
|
if (this.constructor.root_sort)
|
||||||
|
this.roots.sort(this.constructor.root_sort);
|
||||||
|
else
|
||||||
|
this.roots.sort(this.roots[0].constructor.compare);
|
||||||
|
|
||||||
for (let root of this.roots) {
|
for (let root of this.roots) {
|
||||||
$container.append(this.render_element(root, templates, options));
|
$container.append(this.render_element(root, templates, options));
|
||||||
}
|
}
|
||||||
|
@ -720,8 +728,9 @@ class ModelForest {
|
||||||
var that = this;
|
var that = this;
|
||||||
function recurse(node) {
|
function recurse(node) {
|
||||||
if (node.constructor.verbose_name === modelname) {
|
if (node.constructor.verbose_name === modelname) {
|
||||||
if callback(node);
|
if (callback(node)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var children = that.get_children(node);
|
var children = that.get_children(node);
|
||||||
|
@ -730,6 +739,8 @@ class ModelForest {
|
||||||
if (recurse(child))
|
if (recurse(child))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let root of this.roots)
|
for (let root of this.roots)
|
||||||
|
@ -809,20 +820,11 @@ class ArticleList extends APIModelForest {
|
||||||
'category': {
|
'category': {
|
||||||
'model': ArticleCategory,
|
'model': ArticleCategory,
|
||||||
'children': 'articles',
|
'children': 'articles',
|
||||||
'child_sort': Article.compare,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Comparison function to sort roots
|
|
||||||
* @default <tt>{@link Models.ArticleCategory.compare|ArticleCategory.compare}</tt>
|
|
||||||
*/
|
|
||||||
static get root_sort() {
|
|
||||||
return ArticleCategory.compare;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default url to get ArticlList data
|
* Default url to get ArticlList data
|
||||||
* @abstract
|
* @abstract
|
||||||
|
|
Loading…
Reference in a new issue