Add Trash to group libraries

Also:

- Update trash icon properly when adding items to trash or emptying trash
- (dev) Zotero.Items.getDeleted() and Zotero.Items.emptyTrash() parameter order changed
- (dev) Zotero.Items.getDeleted() now returns an empty array rather than FALSE on no results

Group trash does not yet auto-empty
This commit is contained in:
Dan Stillman 2011-08-30 23:35:12 +00:00
parent 3b1cc39f21
commit 09e934128f
7 changed files with 84 additions and 59 deletions

View file

@ -41,10 +41,11 @@ Zotero.CollectionTreeView = function()
this._treebox = null;
this._highlightedRows = {};
this._unregisterID = Zotero.Notifier.registerObserver(this, ['collection', 'search', 'share', 'group', 'bucket']);
this._unregisterID = Zotero.Notifier.registerObserver(this, ['collection', 'search', 'share', 'group', 'trash', 'bucket']);
this._containerState = {};
this._duplicateLibraries = [];
this._unfiledLibraries = [];
this._trashNotEmpty = {};
}
/*
@ -148,7 +149,6 @@ Zotero.CollectionTreeView.prototype.refresh = function()
var self = this;
var library = {
id: null,
libraryID: null
};
@ -256,11 +256,14 @@ Zotero.CollectionTreeView.prototype.notify = function(action, type, ids)
return;
}
if (action == 'refresh' && type == 'trash') {
this._trashNotEmpty[ids[0]] = !!Zotero.Items.getDeleted(ids[0]).length;
return;
}
this.selection.selectEventsSuppressed = true;
var savedSelection = this.saveSelection();
var madeChanges = false;
if (action == 'delete') {
var selectedIndex = this.selection.count ? this.selection.selectedIndex : 0;
@ -432,20 +435,20 @@ Zotero.CollectionTreeView.prototype.getCellText = function(row, column)
Zotero.CollectionTreeView.prototype.getImageSrc = function(row, col)
{
var source = this._getItemAtRow(row);
var collectionType = source.type;
var itemGroup = this._getItemAtRow(row);
var collectionType = itemGroup.type;
switch (collectionType) {
case 'trash':
if (this.trashNotEmpty) {
if (this._trashNotEmpty[itemGroup.ref.libraryID ? itemGroup.ref.libraryID : 0]) {
collectionType += '-full';
}
break;
case 'header':
if (source.ref.id == 'group-libraries-header') {
if (itemGroup.ref.id == 'group-libraries-header') {
collectionType = 'groups';
}
else if (source.ref.id == 'commons-header') {
else if (itemGroup.ref.id == 'commons-header') {
collectionType = 'commons';
}
break;
@ -490,11 +493,13 @@ Zotero.CollectionTreeView.prototype.isContainerEmpty = function(row)
}
if (itemGroup.isGroup()) {
var libraryID = itemGroup.ref.libraryID;
libraryID = (libraryID ? libraryID : 0) + '';
return !itemGroup.ref.hasCollections()
&& !itemGroup.ref.hasSearches()
&& this._duplicateLibraries.indexOf(libraryID + '') == -1
&& this._unfiledLibraries.indexOf(libraryID + '') == -1;
&& this._duplicateLibraries.indexOf(libraryID) == -1
&& this._unfiledLibraries.indexOf(libraryID) == -1
&& this.hideSources.indexOf('trash') != -1;
}
if (itemGroup.isCollection()) {
return !itemGroup.ref.hasChildCollections();
@ -819,17 +824,16 @@ Zotero.CollectionTreeView.prototype._expandRow = function (row, forceOpen) {
if (isGroup) {
var group = Zotero.Groups.getByLibraryID(libraryID);
var collections = group.getCollections();
var showTrash = false;
}
else {
var collections = Zotero.getCollections(itemGroup.ref.id);
var showTrash = this.hideSources.indexOf('trash') == -1;
}
var savedSearches = Zotero.Searches.getAll(libraryID);
var showDuplicates = this.hideSources.indexOf('duplicates') == -1
&& this._duplicateLibraries.indexOf(intLibraryID + '') != -1;
var showUnfiled = this._unfiledLibraries.indexOf(intLibraryID + '') != -1;
var showTrash = this.hideSources.indexOf('trash') == -1;
// If not a manual open and either the library is set to be hidden
// or this is a collection that isn't explicitly opened,
@ -841,7 +845,7 @@ Zotero.CollectionTreeView.prototype._expandRow = function (row, forceOpen) {
return 0;
}
var startOpen = !!(collections.length || savedSearches.length || showDuplicates || showUnfiled);
var startOpen = !!(collections.length || savedSearches.length || showDuplicates || showUnfiled || showTrash);
// If this isn't a manual open, set the initial state depending on whether
// there are child nodes
@ -881,7 +885,7 @@ Zotero.CollectionTreeView.prototype._expandRow = function (row, forceOpen) {
// Duplicate items
if (showDuplicates) {
var d = new Zotero.Duplicates(isGroup ? group.libraryID : 0);
var d = new Zotero.Duplicates(intLibraryID);
this._showRow(new Zotero.ItemGroup('duplicates', d), level, row + 1 + newRows);
newRows++;
}
@ -890,22 +894,25 @@ Zotero.CollectionTreeView.prototype._expandRow = function (row, forceOpen) {
if (showUnfiled) {
var s = new Zotero.Search;
if (isGroup) {
s.libraryID = group.libraryID;
s.libraryID = libraryID;
}
s.name = Zotero.getString('pane.collections.unfiled');
s.addCondition('libraryID', 'is', isGroup ? group.libraryID : null);
s.addCondition('libraryID', 'is', libraryID);
s.addCondition('unfiled', 'true');
this._showRow(new Zotero.ItemGroup('unfiled', s), level, row + 1 + newRows);
newRows++;
}
if (showTrash) {
var deletedItems = Zotero.Items.getDeleted();
if (deletedItems || Zotero.Prefs.get("showTrashWhenEmpty")) {
this._showRow(new Zotero.ItemGroup('trash', false), level, row + 1 + newRows);
var deletedItems = Zotero.Items.getDeleted(libraryID);
if (deletedItems.length || Zotero.Prefs.get("showTrashWhenEmpty")) {
var ref = {
libraryID: libraryID
};
this._showRow(new Zotero.ItemGroup('trash', ref), level, row + 1 + newRows);
newRows++;
}
this.trashNotEmpty = !!deletedItems;
this._trashNotEmpty[intLibraryID] = !!deletedItems.length;
}
return newRows;
@ -1785,7 +1792,7 @@ Zotero.ItemGroup.prototype.__defineGetter__('id', function () {
return 'U' + (this.ref.libraryID ? this.ref.libraryID : 0);
case 'trash':
return 'T';
return 'T' + (this.ref.libraryID ? this.ref.libraryID : 0);
case 'header':
if (this.ref.id == 'group-libraries-header') {
@ -2005,6 +2012,7 @@ Zotero.ItemGroup.prototype.getSearchObject = function() {
includeScopeChildren = true;
}
else if (this.isTrash()) {
s.addCondition('libraryID', 'is', this.ref.libraryID);
s.addCondition('deleted', 'true');
}
else {

View file

@ -2053,7 +2053,7 @@ Zotero.Item.prototype.save = function() {
}
}
// Refresh trash
Zotero.Notifier.trigger('refresh', 'collection', 0);
Zotero.Notifier.trigger('refresh', 'trash', this.libraryID ? this.libraryID : 0);
if (this._deleted) {
Zotero.Notifier.trigger('trash', 'item', this.id);
}

View file

@ -125,16 +125,34 @@ Zotero.Items = new function() {
/**
* Return items marked as deleted
*
* @param {Boolean} asIDs Return itemIDs instead of
* @param {Number|NULL} libraryID
* @param {Boolean} asIDs Return itemIDs instead of
* Zotero.Item objects
* @return {Zotero.Item[]|Integer[]}
* @return {Zotero.Item[]|Integer[]}
*/
this.getDeleted = function (asIDs, days) {
var sql = "SELECT itemID FROM deletedItems";
if (days) {
sql += " WHERE dateDeleted<=DATE('NOW', '-" + parseInt(days) + " DAYS')";
this.getDeleted = function (libraryID, asIDs, days) {
// Throw warning for pre-3.0b3 arguments
if (typeof libraryID == 'boolean') {
throw new Error("libraryID must be a number or null");
}
var sql = "SELECT itemID FROM items JOIN deletedItems USING (itemID) "
+ "WHERE libraryID" + (libraryID ? "=?" : " IS NULL");
if (days) {
sql += " AND dateDeleted<=DATE('NOW', '-" + parseInt(days) + " DAYS')";
}
if (libraryID) {
var ids = Zotero.DB.columnQuery(sql, [libraryID]);
}
else {
var ids = Zotero.DB.columnQuery(sql);
}
if (!ids) {
return [];
}
var ids = Zotero.DB.columnQuery(sql);
if (asIDs) {
return ids;
}
@ -467,15 +485,15 @@ Zotero.Items = new function() {
/**
* @param {Integer} days Only delete items deleted more than this many days ago
*/
this.emptyTrash = function (days) {
this.emptyTrash = function (libraryID, days) {
Zotero.DB.beginTransaction();
var deletedIDs = this.getDeleted(true, days);
if (deletedIDs) {
var deletedIDs = this.getDeleted(libraryID, true, days);
if (deletedIDs.length) {
this.erase(deletedIDs);
Zotero.Notifier.trigger('refresh', 'collection', 0);
Zotero.Notifier.trigger('refresh', 'collection', libraryID ? libraryID : 0);
}
Zotero.DB.commitTransaction();
return deletedIDs ? deletedIDs.length : 0;
return deletedIDs.length;
}

View file

@ -1546,10 +1546,7 @@ Zotero.ItemTreeView.prototype.deleteSelection = function (force)
else if (itemGroup.isTrash()) {
Zotero.Items.erase(ids);
}
else if (itemGroup.isGroup() || (force && itemGroup.isWithinGroup())) {
Zotero.Items.erase(ids);
}
else if (itemGroup.isLibrary() || force) {
else if (itemGroup.isLibrary(true) || force) {
Zotero.Items.trash(ids);
}
else if (itemGroup.isCollection()) {

View file

@ -28,7 +28,7 @@ Zotero.Notifier = new function(){
var _disabled = false;
var _types = [
'collection', 'creator', 'search', 'share', 'share-items', 'item',
'collection-item', 'item-tag', 'tag', 'group', 'bucket', 'relation'
'collection-item', 'item-tag', 'tag', 'group', 'trash', 'bucket', 'relation'
];
var _inTransaction;
var _locked = false;
@ -277,7 +277,7 @@ Zotero.Notifier = new function(){
}
}
if (runQueue[type][event].ids.length) {
if (runQueue[type][event].ids.length || event == 'refresh') {
totals += ' [' + event + '-' + type + ': ' + runQueue[type][event].ids.length + ']';
}
}
@ -290,7 +290,7 @@ Zotero.Notifier = new function(){
for (var type in runQueue) {
for (var event in runQueue[type]) {
if (runQueue[type][event].ids.length) {
if (runQueue[type][event].ids.length || event == 'refresh') {
trigger(event, type, runQueue[type][event].ids,
runQueue[type][event].data, true);
}

View file

@ -1383,7 +1383,7 @@ if(appInfo.platformVersion[0] >= 2) {
var returns = [];
for (var i=0; i<args.length; i++){
if (!args[i]) {
if (!args[i] && args[i] !== 0) {
continue;
}
if (args[i].constructor.name == 'Array') {

View file

@ -404,7 +404,8 @@ var ZoteroPane = new function()
var days = Zotero.Prefs.get('trashAutoEmptyDays');
if (days) {
var d = new Date();
var deleted = Zotero.Items.emptyTrash(days);
// TODO: empty group trashes if permissions
var deleted = Zotero.Items.emptyTrash(null, days);
var d2 = new Date();
Zotero.debug("Emptied old items from trash in " + (d2 - d) + " ms");
}
@ -1430,13 +1431,13 @@ var ZoteroPane = new function()
)
};
if (itemGroup.isLibrary()) {
if (itemGroup.isLibrary(true)) {
// In library, don't prompt if meta key was pressed
var prompt = force ? false : toTrash;
}
else if (itemGroup.isCollection()) {
// In collection, only prompt if trashing
var prompt = force ? (itemGroup.isWithinGroup() ? toDelete : toTrash) : false;
var prompt = force ? toTrash : false;
}
else if (itemGroup.isSearch() || itemGroup.isUnfiled() || itemGroup.isDuplicates()) {
if (!force) {
@ -1458,10 +1459,6 @@ var ZoteroPane = new function()
}
var prompt = toDelete;
}
// This should be changed if/when groups get trash
else if (itemGroup.isGroup()) {
var prompt = toDelete;
}
else if (itemGroup.isBucket()) {
var prompt = toDelete;
}
@ -1570,6 +1567,8 @@ var ZoteroPane = new function()
this.emptyTrash = function () {
var libraryID = this.getSelectedLibraryID();
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
@ -1580,7 +1579,7 @@ var ZoteroPane = new function()
+ Zotero.getString('general.actionCannotBeUndone')
);
if (result) {
Zotero.Items.emptyTrash();
Zotero.Items.emptyTrash(libraryID);
Zotero.purgeDataObjects(true);
}
}
@ -1909,15 +1908,17 @@ var ZoteroPane = new function()
this.getSelectedLibraryID = function () {
var group = this.getSelectedGroup();
if (group) {
return group.libraryID;
var itemGroup = this.getItemGroup();
var groupID = this.getSelectedGroup(true);
if (groupID) {
return groupID;
}
var collection = this.getSelectedCollection();
if (collection) {
return collection.libraryID;
else if (itemGroup.isWithinGroup()) {
return itemGroup.ref.libraryID;
}
else {
return null;
}
return null;
}
@ -1960,7 +1961,8 @@ var ZoteroPane = new function()
if (this.collectionsView.selection
&& this.collectionsView.selection.count > 0
&& this.collectionsView.selection.currentIndex != -1) {
var itemGroup = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex);
var itemGroup = this.getItemGroup();
if (itemGroup && itemGroup.isGroup()) {
return asID ? itemGroup.ref.id : itemGroup.ref;
}