Switch back to multiple items per Zotero Commons bucket

- Creating buckets not yet supported
- Some now-unused single-item-per-bucket code still needs to be removed
- Child attachments are not displayed in Zotero Commons pane
- Manual refreshing via bucket right-click (or a Firefox restart) is currently necessary after adding items
- Double-clicking bucket takes you to bucket page; double-clicking item takes you to named anchor
This commit is contained in:
Dan Stillman 2010-07-07 18:34:09 +00:00
parent 7ce0e9ee23
commit f3a8cbd993
6 changed files with 741 additions and 529 deletions

View file

@ -1343,7 +1343,7 @@ var ZoteroPane = new function()
} }
var itemGroup = this.itemsView._itemGroup; var itemGroup = this.itemsView._itemGroup;
if (!itemGroup.isTrash() && !itemGroup.isCommons() && !this.canEdit()) { if (!itemGroup.isTrash() && !itemGroup.isBucket() && !this.canEdit()) {
this.displayCannotEditLibraryMessage(); this.displayCannotEditLibraryMessage();
return; return;
} }
@ -1383,7 +1383,7 @@ var ZoteroPane = new function()
else if (itemGroup.isShare()) { else if (itemGroup.isShare()) {
return; return;
} }
else if (itemGroup.isCommons()) { else if (itemGroup.isBucket()) {
var prompt = toDelete; var prompt = toDelete;
} }
// Do nothing in trash view if any non-deleted items are selected // Do nothing in trash view if any non-deleted items are selected
@ -1465,24 +1465,26 @@ var ZoteroPane = new function()
} }
} }
this.refreshCommons = function() { this.refreshCommonsBucket = function() {
if (this.collectionsView if (!this.collectionsView
&& this.collectionsView.selection || !this.collectionsView.selection
&& this.collectionsView.selection.count == 1 || this.collectionsView.selection.count != 1
&& this.collectionsView.selection.currentIndex != -1) { || this.collectionsView.selection.currentIndex == -1) {
return false;
}
var itemGroup = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex); var itemGroup = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex);
if (itemGroup && itemGroup.isCommons()) { if (itemGroup && itemGroup.isBucket()) {
var self = this; var self = this;
Zotero.Commons.syncBucketList(function () { itemGroup.ref.refreshItems(function () {
self.itemsView.refresh(); self.itemsView.refresh();
self.itemsView.sort(); self.itemsView.sort();
// On a manual refresh, also check for new OCRed files // On a manual refresh, also check for new OCRed files
Zotero.Commons.syncFiles(); //Zotero.Commons.syncFiles();
}); });
} }
} }
}
function editSelectedCollection() function editSelectedCollection()
{ {
@ -1783,7 +1785,7 @@ var ZoteroPane = new function()
exportFile: 9, exportFile: 9,
loadReport: 10, loadReport: 10,
emptyTrash: 11, emptyTrash: 11,
refreshCommons: 12 refreshCommonsBucket: 12
}; };
var itemGroup = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex); var itemGroup = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex);
@ -1854,8 +1856,8 @@ var ZoteroPane = new function()
else if (itemGroup.isHeader()) { else if (itemGroup.isHeader()) {
// Don't show menu for headers // Don't show menu for headers
} }
else if (itemGroup.isCommons()) { else if (itemGroup.isBucket()) {
show = [m.refreshCommons]; show = [m.refreshCommonsBucket];
} }
// Group // Group
else if (itemGroup.isGroup()) { else if (itemGroup.isGroup()) {
@ -2156,12 +2158,16 @@ var ZoteroPane = new function()
// TODO: implement menu for remote items // TODO: implement menu for remote items
if (!itemGroup.editable) { if (!itemGroup.editable) {
for (var i in m) { for (var i in m) {
// Still show export/bib/report for non-editable views
// (other than Commons buckets, which aren't real items)
if (!itemGroup.isBucket()) {
switch (i) { switch (i) {
case 'exportItems': case 'exportItems':
case 'createBib': case 'createBib':
case 'loadReport': case 'loadReport':
continue; continue;
} }
}
disable.push(m[i]); disable.push(m[i]);
var index = enable.indexOf(m[i]); var index = enable.indexOf(m[i]);
if (index != -1) { if (index != -1) {
@ -2273,9 +2279,8 @@ var ZoteroPane = new function()
return; return;
} }
if (itemGroup.isCommons()) { if (itemGroup.isBucket()) {
// TODO: take to a search of the user's buckets? ZoteroPane.loadURI(itemGroup.ref.uri);
//ZoteroPane.loadURI(itemGroup.ref.uri);
event.stopPropagation(); event.stopPropagation();
} }
} }
@ -2302,9 +2307,9 @@ var ZoteroPane = new function()
ZoteroPane.collectionsView.selection.currentIndex ZoteroPane.collectionsView.selection.currentIndex
); );
if (itemGroup.isCommons()) { if (itemGroup.isBucket()) {
var bucket = Zotero.Commons.getBucketFromItem(item); var uri = itemGroup.ref.getItemURI(item);
ZoteroPane.loadURI(bucket.uri); ZoteroPane.loadURI(uri);
event.stopPropagation(); event.stopPropagation();
return; return;
} }

View file

@ -107,7 +107,7 @@
<menuitem label="&zotero.toolbar.export.label;" oncommand="Zotero_File_Interface.exportFile()"/> <menuitem label="&zotero.toolbar.export.label;" oncommand="Zotero_File_Interface.exportFile()"/>
<menuitem oncommand="Zotero_Report_Interface.loadCollectionReport()"/> <menuitem oncommand="Zotero_Report_Interface.loadCollectionReport()"/>
<menuitem label="&zotero.toolbar.emptyTrash.label;" oncommand="ZoteroPane.emptyTrash();"/> <menuitem label="&zotero.toolbar.emptyTrash.label;" oncommand="ZoteroPane.emptyTrash();"/>
<menuitem label="Refresh" oncommand="ZoteroPane.refreshCommons();"/><!--TODO localize --> <menuitem label="Refresh" oncommand="ZoteroPane.refreshCommonsBucket();"/><!--TODO localize -->
</popup> </popup>
<popup id="zotero-itemmenu" onpopupshowing="ZoteroPane.buildItemContextMenu();"> <popup id="zotero-itemmenu" onpopupshowing="ZoteroPane.buildItemContextMenu();">
<menuitem label="&zotero.items.menu.showInLibrary;" oncommand="ZoteroPane.selectItem(this.parentNode.getAttribute('itemID'), true)"/> <menuitem label="&zotero.items.menu.showInLibrary;" oncommand="ZoteroPane.selectItem(this.parentNode.getAttribute('itemID'), true)"/>

View file

@ -39,7 +39,7 @@ Zotero.CollectionTreeView = function()
this._treebox = null; this._treebox = null;
this.itemToSelect = null; this.itemToSelect = null;
this._highlightedRows = {}; this._highlightedRows = {};
this._unregisterID = Zotero.Notifier.registerObserver(this, ['collection', 'search', 'share', 'group', 'commons']); this._unregisterID = Zotero.Notifier.registerObserver(this, ['collection', 'search', 'share', 'group', 'bucket']);
this.showDuplicates = false; this.showDuplicates = false;
} }
@ -149,6 +149,16 @@ Zotero.CollectionTreeView.prototype.setTree = function(treebox)
*/ */
Zotero.CollectionTreeView.prototype.refresh = function() Zotero.CollectionTreeView.prototype.refresh = function()
{ {
// Record open states before refreshing
if (this._dataItems) {
for (var i=0, len=this._dataItems.length; i<len; i++) {
var itemGroup = this._dataItems[i][0]
if (itemGroup.ref && itemGroup.ref.id == 'commons-header') {
var commonsExpand = this.isContainerOpen(i);
}
}
}
this.selection.clearSelection(); this.selection.clearSelection();
var oldCount = this.rowCount; var oldCount = this.rowCount;
this._dataItems = []; this._dataItems = [];
@ -194,7 +204,7 @@ Zotero.CollectionTreeView.prototype.refresh = function()
var groups = Zotero.Groups.getAll(); var groups = Zotero.Groups.getAll();
if (groups.length) { if (groups.length) {
this._showItem(new Zotero.ItemGroup('separator')); this._showItem(new Zotero.ItemGroup('separator', false));
var header = { var header = {
id: "group-libraries-header", id: "group-libraries-header",
label: "Group Libraries", // TODO: localize label: "Group Libraries", // TODO: localize
@ -234,15 +244,33 @@ Zotero.CollectionTreeView.prototype.refresh = function()
var shares = Zotero.Zeroconf.instances; var shares = Zotero.Zeroconf.instances;
if (shares.length) { if (shares.length) {
this._showItem(new Zotero.ItemGroup('separator')); this._showItem(new Zotero.ItemGroup('separator', false));
for each(var share in shares) { for each(var share in shares) {
this._showItem(new Zotero.ItemGroup('share', share)); this._showItem(new Zotero.ItemGroup('share', share));
} }
} }
if (Zotero.Commons.enabled) { if (Zotero.Commons.enabled) {
this._showItem(new Zotero.ItemGroup('separator')); this._showItem(new Zotero.ItemGroup('separator', false));
this._showItem(new Zotero.ItemGroup('commons'), null, null, true); var header = {
id: "commons-header",
label: "Commons", // TODO: localize
expand: function (buckets) {
if (!buckets) {
var buckets = Zotero.Commons.getBuckets();
}
for each(var bucket in buckets) {
self._showItem(new Zotero.ItemGroup('bucket', bucket), 1);
}
}
};
Zotero.debug('=============');
Zotero.debug(commonsExpand);
this._showItem(new Zotero.ItemGroup('header', header), null, null, commonsExpand);
if (commonsExpand) {
header.expand();
}
} }
this._refreshHashMap(); this._refreshHashMap();
@ -263,11 +291,7 @@ Zotero.CollectionTreeView.prototype.reload = function()
for (var i=0; i<this.rowCount; i++) { for (var i=0; i<this.rowCount; i++) {
if (this.isContainer(i) && this.isContainerOpen(i)) { if (this.isContainer(i) && this.isContainerOpen(i)) {
var itemGroup = this._getItemAtRow(i); openCollections.push(this._getItemAtRow(i).ref.id);
if (!itemGroup.isCollection()) {
continue;
}
openCollections.push(itemGroup.ref.id);
} }
} }
@ -376,7 +400,7 @@ Zotero.CollectionTreeView.prototype.notify = function(action, type, ids)
this.rememberSelection(savedSelection); this.rememberSelection(savedSelection);
} }
else if (action == 'modify' || action == 'refresh') { else if (action == 'modify' || action == 'refresh') {
if (type != 'commons') { if (type != 'bucket') {
this.reload(); this.reload();
} }
this.rememberSelection(savedSelection); this.rememberSelection(savedSelection);
@ -422,8 +446,10 @@ Zotero.CollectionTreeView.prototype.notify = function(action, type, ids)
this.rememberSelection(savedSelection); this.rememberSelection(savedSelection);
break; break;
case 'commons': case 'bucket':
this.reload(); this.reload();
this.rememberSelection(savedSelection);
break;
} }
} }
@ -511,15 +537,14 @@ Zotero.CollectionTreeView.prototype.getImageSrc = function(row, col)
if (source.ref.id == 'group-libraries-header') { if (source.ref.id == 'group-libraries-header') {
collectionType = 'groups'; collectionType = 'groups';
} }
else if (source.ref.id == 'commons-header') {
collectionType = 'commons';
}
break; break;
case 'group': case 'group':
collectionType = 'library'; collectionType = 'library';
break; break;
case 'commons':
collectionType = 'commons';
break;
} }
return "chrome://zotero/skin/treesource-" + collectionType + ".png"; return "chrome://zotero/skin/treesource-" + collectionType + ".png";
} }
@ -527,7 +552,7 @@ Zotero.CollectionTreeView.prototype.getImageSrc = function(row, col)
Zotero.CollectionTreeView.prototype.isContainer = function(row) Zotero.CollectionTreeView.prototype.isContainer = function(row)
{ {
var itemGroup = this._getItemAtRow(row); var itemGroup = this._getItemAtRow(row);
return itemGroup.isLibrary(true) || itemGroup.isCollection() || itemGroup.isHeader() || itemGroup.isCommons(); return itemGroup.isLibrary(true) || itemGroup.isCollection() || itemGroup.isHeader() || itemGroup.isBucket();
} }
Zotero.CollectionTreeView.prototype.isContainerOpen = function(row) Zotero.CollectionTreeView.prototype.isContainerOpen = function(row)
@ -547,6 +572,9 @@ Zotero.CollectionTreeView.prototype.isContainerEmpty = function(row)
if (itemGroup.isHeader()) { if (itemGroup.isHeader()) {
return false; return false;
} }
if (itemGroup.isBucket()) {
return true;
}
if (itemGroup.isGroup()) { if (itemGroup.isGroup()) {
return !itemGroup.ref.hasCollections(); return !itemGroup.ref.hasCollections();
} }
@ -604,6 +632,8 @@ Zotero.CollectionTreeView.prototype.toggleOpenState = function(row)
if (itemGroup.type == 'header') { if (itemGroup.type == 'header') {
itemGroup.ref.expand(); itemGroup.ref.expand();
} }
else if(itemGroup.type == 'bucket') {
}
else { else {
if (itemGroup.isLibrary()) { if (itemGroup.isLibrary()) {
count = itemGroup.ref.expand(); count = itemGroup.ref.expand();
@ -1048,17 +1078,15 @@ Zotero.CollectionTreeView.prototype.canDrop = function(row, orient, dragData)
{ {
var itemGroup = this._getItemAtRow(row); //the collection we are dragging over var itemGroup = this._getItemAtRow(row); //the collection we are dragging over
if (!itemGroup.editable if (dataType == 'zotero/item' && itemGroup.isBucket()) {
// Commons can be dropped on but not edited return true;
&& !itemGroup.isCommons()) { }
if (!itemGroup.editable) {
return false; return false;
} }
if (dataType == 'zotero/item') { if (dataType == 'zotero/item') {
if(itemGroup.isCommons()) {
return true;
}
var ids = data; var ids = data;
var items = Zotero.Items.get(ids); var items = Zotero.Items.get(ids);
var skip = true; var skip = true;
@ -1223,8 +1251,8 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient)
var targetLibraryID = null; var targetLibraryID = null;
} }
if(itemGroup.isCommons()) { if(itemGroup.isBucket()) {
Zotero.Commons.uploadItems(ids); itemGroup.ref.uploadItems(ids);
return; return;
} }
@ -1625,9 +1653,9 @@ Zotero.ItemGroup.prototype.isShare = function()
return this.type == 'share'; return this.type == 'share';
} }
Zotero.ItemGroup.prototype.isCommons = function() Zotero.ItemGroup.prototype.isBucket = function()
{ {
return this.type == 'commons'; return this.type == 'bucket';
} }
Zotero.ItemGroup.prototype.isTrash = function() Zotero.ItemGroup.prototype.isTrash = function()
@ -1654,7 +1682,7 @@ Zotero.ItemGroup.prototype.isWithinGroup = function () {
} }
Zotero.ItemGroup.prototype.__defineGetter__('editable', function () { Zotero.ItemGroup.prototype.__defineGetter__('editable', function () {
if (this.isTrash() || this.isShare() || this.isCommons()) { if (this.isTrash() || this.isShare() || this.isBucket()) {
return false; return false;
} }
if (!this.isWithinGroup()) { if (!this.isWithinGroup()) {
@ -1714,6 +1742,9 @@ Zotero.ItemGroup.prototype.getName = function()
case 'share': case 'share':
return this.ref.name; return this.ref.name;
case 'bucket':
return this.ref.name;
case 'trash': case 'trash':
return Zotero.getString('pane.collections.trash'); return Zotero.getString('pane.collections.trash');
@ -1723,9 +1754,6 @@ Zotero.ItemGroup.prototype.getName = function()
case 'header': case 'header':
return this.ref.label; return this.ref.label;
case 'commons':
return "Commons";
default: default:
return ""; return "";
} }
@ -1738,8 +1766,8 @@ Zotero.ItemGroup.prototype.getChildItems = function()
case 'share': case 'share':
return this.ref.getAll(); return this.ref.getAll();
case 'commons': case 'bucket':
return Zotero.Commons.getItems(); return this.ref.getItems();
case 'header': case 'header':
return []; return [];
@ -1852,7 +1880,7 @@ Zotero.ItemGroup.prototype.getChildTags = function() {
case 'share': case 'share':
return false; return false;
case 'commons': case 'bucket':
return false; return false;
case 'header': case 'header':

File diff suppressed because it is too large Load diff

View file

@ -52,7 +52,7 @@ Zotero.ItemTreeView = function(itemGroup, sourcesOnly)
this._dataItems = []; this._dataItems = [];
this.rowCount = 0; this.rowCount = 0;
this._unregisterID = Zotero.Notifier.registerObserver(this, ['item', 'collection-item', 'share-items', 'commons']); this._unregisterID = Zotero.Notifier.registerObserver(this, ['item', 'collection-item', 'share-items', 'bucket']);
} }
@ -260,7 +260,6 @@ Zotero.ItemTreeView.prototype.refresh = function()
*/ */
Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData) Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
{ {
Zotero.debug('=============');
if (!this._treebox || !this._treebox.treeBody) { if (!this._treebox || !this._treebox.treeBody) {
Components.utils.reportError("Treebox didn't exist in itemTreeView.notify()"); Components.utils.reportError("Treebox didn't exist in itemTreeView.notify()");
return; return;
@ -270,7 +269,7 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
Zotero.debug("Item row map didn't exist in itemTreeView.notify()"); Zotero.debug("Item row map didn't exist in itemTreeView.notify()");
return; return;
} }
Zotero.debug(1);
var itemGroup = this._itemGroup; var itemGroup = this._itemGroup;
var madeChanges = false; var madeChanges = false;
@ -285,10 +284,9 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
this.refresh(); this.refresh();
} }
} }
else if (type == 'commons') { else if (type == 'bucket') {
if (itemGroup.isCommons()) { if (itemGroup.isBucket()) {
this.refresh(); this.refresh();
this.sort();
} }
} }
else if (savedSelection.length == 1 && savedSelection[0] == ids[0]) { else if (savedSelection.length == 1 && savedSelection[0] == ids[0]) {
@ -457,7 +455,6 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
} }
else if(action == 'add') else if(action == 'add')
{ {
Zotero.debug(2);
// If saved search or trash, just re-run search // If saved search or trash, just re-run search
if (itemGroup.isSearch() || itemGroup.isTrash()) { if (itemGroup.isSearch() || itemGroup.isTrash()) {
this.refresh(); this.refresh();
@ -502,7 +499,6 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
if(madeChanges) if(madeChanges)
{ {
Zotero.debug(3);
// If adding and this is the active window, select the item // If adding and this is the active window, select the item
if(action == 'add' && ids.length===1 && activeWindow) if(action == 'add' && ids.length===1 && activeWindow)
{ {
@ -515,7 +511,7 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
// Reset to Info tab // Reset to Info tab
this._ownerDocument.getElementById('zotero-view-tabbox').selectedIndex = 0; this._ownerDocument.getElementById('zotero-view-tabbox').selectedIndex = 0;
Zotero.debug(4);
this.selectItem(ids[0]); this.selectItem(ids[0]);
} }
// If single item is selected and was modified // If single item is selected and was modified
@ -544,7 +540,6 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
} }
else else
{ {
Zotero.debug(4);
var previousRow = this._itemRowMap[ids[0]]; var previousRow = this._itemRowMap[ids[0]];
if (sort) { if (sort) {
@ -1117,8 +1112,6 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
*/ */
Zotero.ItemTreeView.prototype.selectItem = function(id, expand, noRecurse) Zotero.ItemTreeView.prototype.selectItem = function(id, expand, noRecurse)
{ {
Zotero.debug('=============');
Zotero.debug(Zotero.suppressUIUpdates);
// Don't change selection if UI updates are disabled (e.g., during sync) // Don't change selection if UI updates are disabled (e.g., during sync)
if (Zotero.suppressUIUpdates) { if (Zotero.suppressUIUpdates) {
return; return;
@ -1262,7 +1255,10 @@ Zotero.ItemTreeView.prototype.deleteSelection = function (force)
var itemGroup = this._itemGroup; var itemGroup = this._itemGroup;
if (itemGroup.isTrash()) { if (itemGroup.isBucket()) {
itemGroup.ref.deleteItems(ids);
}
else if (itemGroup.isTrash()) {
Zotero.Items.erase(ids); Zotero.Items.erase(ids);
} }
else if (itemGroup.isGroup() || (force && itemGroup.isWithinGroup())) { else if (itemGroup.isGroup() || (force && itemGroup.isWithinGroup())) {
@ -1274,9 +1270,6 @@ Zotero.ItemTreeView.prototype.deleteSelection = function (force)
else if (itemGroup.isCollection()) { else if (itemGroup.isCollection()) {
itemGroup.ref.removeItems(ids); itemGroup.ref.removeItems(ids);
} }
else if (itemGroup.isCommons()) {
Zotero.Commons.deleteItems(ids);
}
this._treebox.endUpdateBatch(); this._treebox.endUpdateBatch();
} }

View file

@ -28,7 +28,7 @@ Zotero.Notifier = new function(){
var _disabled = false; var _disabled = false;
var _types = [ var _types = [
'collection', 'creator', 'search', 'share', 'share-items', 'item', 'collection', 'creator', 'search', 'share', 'share-items', 'item',
'collection-item', 'item-tag', 'tag', 'group', 'commons' 'collection-item', 'item-tag', 'tag', 'group', 'bucket'
]; ];
var _inTransaction; var _inTransaction;
var _locked = false; var _locked = false;