Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix logic in the input handler for the search edit field. Also needed to add a fetch handler in the Chapter collection that will filter by projectid.
  • Loading branch information
eb1 committed Feb 23, 2024
1 parent b561330 commit f5e1b0b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
10 changes: 9 additions & 1 deletion www/js/models/sql/chapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,16 @@ define(function (require) {
// results already in collection -- return them
options.success(results);
deferred.resolve(results);
} else if (options.data.hasOwnProperty('projectid')) {
// find projectid matches
var projectid = options.data.projectid;
results = chapters.filter(function (element) {
return element.attributes.projectid === projectid;
});
// results already in collection -- return them
options.success(results);
deferred.resolve(results);
} else if (options.data.hasOwnProperty('name')) {

// special case -- empty name query ==> reset local copy so we force a retrieve
// from the database
if (name === "") {
Expand Down
31 changes: 18 additions & 13 deletions www/js/views/SearchViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ define(function (require) {
onShow: function () {
var lstBooks = "";
this.bookList.fetch({reset: true, data: {projectid: this.model.get('projectid')}});
this.chapterList.fetch({reset: true, data: {projectid: this.model.get('projectid')}});
// initial sort - name
this.bookList.comparator = 'name';
this.bookList.sort();
Expand All @@ -1254,24 +1255,28 @@ define(function (require) {
event.preventDefault();
}
var key = $('#search').val();
if (key.length === 0 && $("#lstBooks").hasClass("hide")) {
// search is cleared out -- show the books UI
this.toggleSearchBrowse();
return;
}
if (key.length > 0 && $("#lstSearch").hasClass("hide")) {
// we have something to search for -- show the search UI
this.chapterList.fetch({reset: true, data: {projectid: this.model.get('projectid')}});
this.toggleSearchBrowse();
// search for the string provided
this.chapterList.fetch({reset: true, data: {name: key}});
this.chapterList.each(function (model) {
}
// search for the string provided (case-insensitive)
this.chapterList.each(function (model) {
if (model.get("name").toLowerCase().indexOf(key.toLowerCase()) > -1) {
lstChapters += chapTemplate(model.attributes);
});
if (this.chapterList.length > 0) {
$("#lstSearchResults").html(lstChapters);
$("#lblSearchResults").removeAttr("style");
} else {
$("#lblSearchResults").attr("style", "display:none");
}
}
if (key.length === 0 && $("#lstBooks").hasClass("hide")) {
// search is cleared out -- show the books UI
this.toggleSearchBrowse();
});
if (lstChapters.length > 0) {
$("#lstSearchResults").html(lstChapters);
$("#lblSearchResults").removeAttr("style");
} else {
$("#lblSearchResults").attr("style", "display:none");
$("#lstSearchResults").html("");
}
},

Expand Down

0 comments on commit f5e1b0b

Please sign in to comment.