From bdebc8dffaa6ca8833495fefe9c11d0a634d7a71 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 29 Aug 2006 11:16:31 +0000 Subject: [PATCH] Saved search improvements: - select() new collections and saved searches on creation - Show all collections in search dialog Collection condition drop-down, not just top-level ones -- eventually there should probably be some sort of level indication to show hierarchy - Don't allow a search to define itself as a savedSearchID condition. Right. - Fixed a couple bugs in Collection condition creation that would've made such searches often not work - Added saved search 'add' support to collectionTreeView notify(), and send the right trigger from Scholar.Search --- .../scholar/bindings/scholarsearch.xml | 32 +++++++++++-------- chrome/chromeFiles/content/scholar/overlay.js | 4 +-- .../scholar/xpcom/collectionTreeView.js | 16 ++++++++-- .../content/scholar/xpcom/search.js | 11 ++++++- 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/chrome/chromeFiles/content/scholar/bindings/scholarsearch.xml b/chrome/chromeFiles/content/scholar/bindings/scholarsearch.xml index 750a65d4b..c13c00fb2 100644 --- a/chrome/chromeFiles/content/scholar/bindings/scholarsearch.xml +++ b/chrome/chromeFiles/content/scholar/bindings/scholarsearch.xml @@ -177,12 +177,13 @@ if (this.id('conditionsmenu').value==this.selectedCondition){ return; } + var conditionsMenu = this.id('conditionsmenu'); var operatorsList = this.id('operatorsmenu'); - this.selectedCondition = this.id('conditionsmenu').value; + this.selectedCondition = conditionsMenu.value; this.selectedOperator = operatorsList.value; - var condition = Scholar.SearchConditions.get(this.id('conditionsmenu').value); + var condition = Scholar.SearchConditions.get(conditionsMenu.value); var operators = condition['operators']; // Display appropriate operators for condition @@ -200,18 +201,23 @@ operatorsList.selectedIndex = selectThis; // Generate drop-down menus for certain conditions - switch (this.id('conditionsmenu').value){ + switch (conditionsMenu.value){ case 'collectionID': var merged = []; - var searches = Scholar.Searches.getAll(); - var cols = Scholar.getCollections(); + + var cols = Scholar.getCollections(false, true); for (var i in cols) { merged.push([cols[i].getName(), 'C' + cols[i].getID()]); } + + var searches = Scholar.Searches.getAll(); for (var i in searches) { - merged.push([searches[i]['name'], 'S' + searches[i]['id']]); + if (searches[i]['id'] != this.parent.search.getID()) + { + merged.push([searches[i]['name'], 'S' + searches[i]['id']]); + } } this.createValueMenu(merged); @@ -261,7 +267,10 @@ this.id('valuemenu').selectedIndex = 0; } - this.id('valuemenu').value = this.value; + if (this.value) + { + this.id('valuemenu').value = this.value; + } this.id('valuefield').hidden = true; this.id('valuemenu').hidden = false; ]]> @@ -282,29 +291,26 @@ if(this.parent.search) { this.dontupdate = true; //so that the search doesn't get updated while we are creating controls. + var prefix = ''; // Handle collectionID/savedSearchID switch (condition['condition']) { case 'savedSearchID': this.id('conditionsmenu').value = 'collectionID'; - var prefix = 'S'; + prefix = 'S'; break; case 'collectionID': - this.id('conditionsmenu').value = 'collectionID'; - var prefix = 'C'; - + prefix = 'C'; // fall through default: this.id('conditionsmenu').value = condition['condition']; - var prefix = ''; } this.id('operatorsmenu').value = condition['operator']; this.value = prefix + condition['value']; - this.dontupdate = false; } diff --git a/chrome/chromeFiles/content/scholar/overlay.js b/chrome/chromeFiles/content/scholar/overlay.js index 91fb5b39e..5aaf2e136 100644 --- a/chrome/chromeFiles/content/scholar/overlay.js +++ b/chrome/chromeFiles/content/scholar/overlay.js @@ -174,11 +174,9 @@ var ScholarPane = new function() var s = new Scholar.Search(); s.addCondition('title','contains',''); + // TODO: add integer to 'Untitled' if more than one var io = {dataIn: {search: s, name: 'Untitled'}, dataOut: null}; window.openDialog('chrome://scholar/content/searchDialog.xul','','chrome,modal',io); - - if(io.dataOut) - getCollectionsView().reload(); //we don't have notification support for searches } function onCollectionSelected() diff --git a/chrome/chromeFiles/content/scholar/xpcom/collectionTreeView.js b/chrome/chromeFiles/content/scholar/xpcom/collectionTreeView.js index dfa0c813c..bd7bcfc24 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/collectionTreeView.js +++ b/chrome/chromeFiles/content/scholar/xpcom/collectionTreeView.js @@ -180,11 +180,21 @@ Scholar.CollectionTreeView.prototype.notify = function(action, type, ids) // Multiple adds not currently supported ids = ids[0]; - var item = Scholar.Collections.get(ids); + switch (type) + { + case 'collection': + var item = Scholar.Collections.get(ids); + this._showItem(new Scholar.ItemGroup('collection',item), 0, this.rowCount); + break; + + case 'search': + var search = Scholar.Searches.get(ids); + this._showItem(new Scholar.ItemGroup('search', search), 0, this.rowCount); + break; + } - this._showItem(new Scholar.ItemGroup('collection',item), 0, this.rowCount); this._treebox.rowCountChanged(this.rowCount-1,1); - + this.selection.select(this.rowCount-1); madeChanges = true; } diff --git a/chrome/chromeFiles/content/scholar/xpcom/search.js b/chrome/chromeFiles/content/scholar/xpcom/search.js index feebee804..ce7c95b7e 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/search.js +++ b/chrome/chromeFiles/content/scholar/xpcom/search.js @@ -64,6 +64,11 @@ Scholar.Search.prototype.load = function(savedSearchID){ } +Scholar.Search.prototype.getID = function(){ + return this._savedSearchID; +} + + /* * Save the search to the DB and return a savedSearchID * @@ -84,6 +89,8 @@ Scholar.Search.prototype.save = function(){ + "WHERE savedSearchID=" + this._savedSearchID); } else { + var isNew = true; + this._savedSearchID = Scholar.getRandomID('savedSearches', 'savedSearchID'); @@ -112,7 +119,9 @@ Scholar.Search.prototype.save = function(){ } Scholar.DB.commitTransaction(); - Scholar.Notifier.trigger('modify', 'search', this._savedSearchID); + Scholar.Notifier.trigger( + (isNew ? 'add' : 'modify'), 'search', this._savedSearchID + ); return this._savedSearchID; }