move the searching to the proper collection

so everything get filtered, not just the visible
This commit is contained in:
Martin Cech
2019-07-06 11:56:08 +02:00
parent a13953dabc
commit 5cfed80eac
2 changed files with 18 additions and 17 deletions
@@ -284,7 +284,7 @@ var FolderListView = Backbone.View.extend({
const trimmed_term = $.trim(search_term);
if (trimmed_term !== "") {
let result_collection = null;
result_collection = this.collection.search(search_term);
result_collection = this.folder_container.search(search_term);
this.options.result_models = result_collection.models;
this.collection.reset(result_collection);
} else {
@@ -81,22 +81,7 @@ var Folder = Backbone.Collection.extend({
sortFolder: function(sort_key, sort_order) {
this.comparator = mod_util.generateFolderComparator(sort_key, sort_order);
this.sort();
},
/**
* Search the collection and return only the models that have
* the search term in their names.
* [the term to search]
* @type {string}
*/
search: function(search_term) {
if (search_term == "") return this;
const lowercase_term = search_term.toLowerCase();
return this.filter(data => {
const lowercase_name = data.get("name").toLowerCase();
return lowercase_name.indexOf(lowercase_term) !== -1;
});
},
}
});
var FolderContainer = Backbone.Model.extend({
@@ -105,6 +90,22 @@ var FolderContainer = Backbone.Model.extend({
urlRoot: `${getAppRoot()}api/folders/`,
id: "unknown"
},
/**
* Search the folder and return only the models that have
* the search term in their names.
* [the term to search]
* @type {string}
*/
search: function(search_term) {
if (search_term == "") return this;
const lowercase_term = search_term.toLowerCase();
return this.get("folder").filter(data => {
const lowercase_name = data.get("name").toLowerCase();
return lowercase_name.indexOf(lowercase_term) !== -1;
});
},
parse: function(obj) {
const Galaxy = getGalaxyInstance();
// empty the collection