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)
This commit is contained in:
Dan Stillman 2009-12-08 00:02:28 +00:00
parent 01e9bea66e
commit 5b84dfe6d0
3 changed files with 59 additions and 17 deletions

View file

@ -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 {

View file

@ -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,11 +1744,17 @@ Zotero.ItemGroup.prototype.getChildItems = function()
// FIXME: Hack to exclude group libraries for now
if (this.isSearch()) {
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);
}
}
}
try {
var ids;

View file

@ -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
},
{