WIP: Aureplop/kpsul js refactor #501
2 changed files with 17 additions and 17 deletions
|
@ -733,8 +733,11 @@ class ModelForest {
|
|||
*/
|
||||
traverse(modelname, callback) {
|
||||
function recurse(node) {
|
||||
if (node.modelname === modelname)
|
||||
callback(node.content, node.parent && node.parent.content || null) ;
|
||||
if (node.modelname === modelname) {
|
||||
var parent = node.parent && node.parent.content || null;
|
||||
var children = node.children.map( (child) => child.content);
|
||||
callback(node.content, children, parent);
|
||||
}
|
||||
|
||||
for (let child of node.children)
|
||||
recurse(child);
|
||||
|
|
|
@ -575,12 +575,9 @@ class ArticleAutocomplete {
|
|||
var lower = prefix.toLowerCase() ;
|
||||
var that = this ;
|
||||
|
||||
article_list.traverse('article', function(article, category) {
|
||||
if (article.name.toLowerCase().startsWith(lower)) {
|
||||
article_list.traverse('article', function(article) {
|
||||
if (article.name.toLowerCase().startsWith(lower))
|
||||
that.matching.push(article);
|
||||
if (that.active_categories.indexOf(category) == -1)
|
||||
that.active_categories.push(category);
|
||||
}
|
||||
});
|
||||
|
||||
if (this.matching.length == 1) {
|
||||
|
@ -602,14 +599,18 @@ class ArticleAutocomplete {
|
|||
updateDisplay() {
|
||||
var that = this;
|
||||
|
||||
this.manager.list.traverse('article', function(article, category) {
|
||||
if (that.matching.indexOf(article) != -1) {
|
||||
that._$container.find('#article-'+article.id).show();
|
||||
} else {
|
||||
that._$container.find('#article-'+article.id).hide();
|
||||
this.manager.list.traverse('category', function(category, articles) {
|
||||
var is_active = false;
|
||||
for (let article of articles) {
|
||||
if (that.matching.indexOf(article) != -1) {
|
||||
is_active = true;
|
||||
that._$container.find('#article-'+article.id).show();
|
||||
} else {
|
||||
that._$container.find('#article-'+article.id).hide();
|
||||
}
|
||||
}
|
||||
|
||||
if (that.active_categories.indexOf(category) != -1) {
|
||||
if (is_active) {
|
||||
that._$container.find('#category-'+category.id).show();
|
||||
} else {
|
||||
that._$container.find('#category-'+category.id).hide();
|
||||
|
@ -636,14 +637,10 @@ class ArticleAutocomplete {
|
|||
this.manager.list.traverse('article', function(article) {
|
||||
that.matching.push(article);
|
||||
});
|
||||
this.manager.list.traverse('category', function(category) {
|
||||
that.active_categories.push(category);
|
||||
});
|
||||
this.updateDisplay();
|
||||
}
|
||||
|
||||
resetMatch() {
|
||||
this.matching = [];
|
||||
this.active_categories = [];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue