commit 5b84dfe6d0ca7845ecc650703e403fe6ff4c1acc
parent 01e9bea66efebf9df157af37308e3f2298d457c6
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 8 Dec 2009 00:02:28 +0000
Closes #1550, add "smart folders" to groups
Create via right-click on group
- "New Subcollection" context-menu option was active in read-only groups
- Zotero.Searches.getAll() now takes an optional libraryID parameter (and defaults to personal library)
Diffstat:
3 files changed, 59 insertions(+), 17 deletions(-)
diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js
@@ -753,6 +753,7 @@ var ZoteroPane = new function()
}
var s = new Zotero.Search();
+ s.libraryID = this.getSelectedLibraryID();
s.addCondition('title', 'contains', '');
var untitled = Zotero.getString('pane.collections.untitled');
@@ -1745,7 +1746,7 @@ var ZoteroPane = new function()
}
// Group
else if (itemGroup.isGroup()) {
- show = [m.newCollection];
+ show = [m.newCollection, m.newSavedSearch];
}
// Library
else
@@ -1754,8 +1755,8 @@ var ZoteroPane = new function()
}
// Disable some actions if user doesn't have write access
- var s = [m.editSelectedCollection, m.removeCollection, m.newCollection, m.newSavedSearch];
- if (itemGroup.isGroup() && !itemGroup.ref.editable) {
+ var s = [m.editSelectedCollection, m.removeCollection, m.newCollection, m.newSavedSearch, m.newSubcollection];
+ if (itemGroup.isWithinGroup() && !itemGroup.editable) {
disable = disable.concat(s);
}
else {
diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js
@@ -205,10 +205,22 @@ Zotero.CollectionTreeView.prototype.refresh = function()
self._showItem(new Zotero.ItemGroup('group', groups[i]), 1, null, startOpen);
+ var newRows = 0;
+
// Add group collections
var collections = groups[i].getCollections();
for (var j=0; j<collections.length; j++) {
self._showItem(new Zotero.ItemGroup('collection', collections[j]), 2);
+ newRows++;
+ }
+
+ // Add group searches
+ var savedSearches = Zotero.Searches.getAll(groups[i].libraryID);
+ if (savedSearches) {
+ for (var j=0; j<savedSearches.length; j++) {
+ self._showItem(new Zotero.ItemGroup('search', savedSearches[j]), 2);
+ newRows++;
+ }
}
}
}
@@ -608,15 +620,27 @@ Zotero.CollectionTreeView.prototype.toggleOpenState = function(row)
}
else {
if (itemGroup.isGroup()) {
- var collections = itemGroup.ref.getCollections(); // Get child collections
+ var collections = itemGroup.ref.getCollections();
}
else {
- var collections = Zotero.getCollections(itemGroup.ref.id); // Get child collections
+ var collections = Zotero.getCollections(itemGroup.ref.id);
}
+ // Add child collections
for (var i=0; i<collections.length; i++) {
- this._showItem(new Zotero.ItemGroup('collection', collections[i]), thisLevel+1, row+i+1); //insert new row
+ this._showItem(new Zotero.ItemGroup('collection', collections[i]), thisLevel + 1, row + count + 1);
count++;
}
+
+ // Add group searches
+ if (itemGroup.isGroup()) {
+ var savedSearches = Zotero.Searches.getAll(itemGroup.ref.libraryID);
+ if (savedSearches) {
+ for (var i=0; i<savedSearches.length; i++) {
+ this._showItem(new Zotero.ItemGroup('search', savedSearches[i]), thisLevel + 1, row + count + 1);
+ count;
+ }
+ }
+ }
}
}
}
@@ -1635,7 +1659,7 @@ Zotero.ItemGroup.prototype.__defineGetter__('editable', function () {
if (this.isGroup()) {
return this.ref.editable;
}
- if (this.isCollection()) {
+ if (this.isCollection() || this.isSearch()) {
var type = Zotero.Libraries.getType(libraryID);
if (type == 'group') {
var groupID = Zotero.Groups.getGroupIDFromLibraryID(libraryID);
@@ -1720,9 +1744,15 @@ Zotero.ItemGroup.prototype.getChildItems = function()
// FIXME: Hack to exclude group libraries for now
if (this.isSearch()) {
- var groups = Zotero.Groups.getAll();
- for each(var group in groups) {
- s.addCondition('libraryID', 'isNot', group.libraryID);
+ var currentLibraryID = this.ref.libraryID;
+ if (currentLibraryID) {
+ s.addCondition('libraryID', 'is', currentLibraryID);
+ }
+ else {
+ var groups = Zotero.Groups.getAll();
+ for each(var group in groups) {
+ s.addCondition('libraryID', 'isNot', group.libraryID);
+ }
}
}
diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js
@@ -1578,7 +1578,6 @@ Zotero.Searches = new function(){
this.constructor.prototype = new Zotero.DataObjects();
this.get = get;
- this.getAll = getAll;
this.erase = erase;
@@ -1600,13 +1599,24 @@ Zotero.Searches = new function(){
}
- /*
- * Returns an array of saved searches, ordered by name
+ /**
+ * Returns an array of Zotero.Search objects, ordered by name
+ *
+ * @param {Integer|null} [libraryID=null]
*/
- function getAll(){
+ this.getAll = function (libraryID) {
var sql = "SELECT savedSearchID AS id, savedSearchName AS name "
- + "FROM savedSearches ORDER BY name COLLATE NOCASE";
- var rows = Zotero.DB.query(sql);
+ + "FROM savedSearches WHERE libraryID";
+ if (libraryID) {
+ sql += "=?";
+ var params = [libraryID];
+ }
+ else {
+ sql += " IS NULL";
+ var params = null;
+ }
+ sql += " ORDER BY name COLLATE NOCASE";
+ var rows = Zotero.DB.query(sql, params);
if (!rows) {
return [];
}
@@ -2002,7 +2012,8 @@ Zotero.SearchConditions = new function(){
},
table: 'items',
field: 'libraryID',
- special: true
+ special: true,
+ noLoad: true
},
{