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