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
This commit is contained in:
Dan Stillman 2006-08-29 11:16:31 +00:00
parent cd432a1e2a
commit bdebc8dffa
4 changed files with 43 additions and 20 deletions

View file

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

View file

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

View file

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

View file

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