WIP: Aureplop/kpsul js refactor #501

Draft
delobell wants to merge 215 commits from aureplop/kpsul_js_refactor into master
2 changed files with 17 additions and 17 deletions
Showing only changes of commit 5c422e892a - Show all commits

View file

@ -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);

View file

@ -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) {
if (that.matching.indexOf(article) != -1) { var is_active = false;
that._$container.find('#article-'+article.id).show(); for (let article of articles) {
} else { if (that.matching.indexOf(article) != -1) {
that._$container.find('#article-'+article.id).hide(); 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(); 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 = [];
} }
} }