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

View file

@ -107,7 +107,7 @@
<menuitem label="&zotero.toolbar.export.label;" oncommand="Zotero_File_Interface.exportFile()"/>
<menuitem oncommand="Zotero_Report_Interface.loadCollectionReport()"/>
<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 id="zotero-itemmenu" onpopupshowing="ZoteroPane.buildItemContextMenu();">
<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.itemToSelect = null;
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;
}
@ -149,6 +149,16 @@ Zotero.CollectionTreeView.prototype.setTree = function(treebox)
*/
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();
var oldCount = this.rowCount;
this._dataItems = [];
@ -194,7 +204,7 @@ Zotero.CollectionTreeView.prototype.refresh = function()
var groups = Zotero.Groups.getAll();
if (groups.length) {
this._showItem(new Zotero.ItemGroup('separator'));
this._showItem(new Zotero.ItemGroup('separator', false));
var header = {
id: "group-libraries-header",
label: "Group Libraries", // TODO: localize
@ -234,15 +244,33 @@ Zotero.CollectionTreeView.prototype.refresh = function()
var shares = Zotero.Zeroconf.instances;
if (shares.length) {
this._showItem(new Zotero.ItemGroup('separator'));
this._showItem(new Zotero.ItemGroup('separator', false));
for each(var share in shares) {
this._showItem(new Zotero.ItemGroup('share', share));
}
}
if (Zotero.Commons.enabled) {
this._showItem(new Zotero.ItemGroup('separator'));
this._showItem(new Zotero.ItemGroup('commons'), null, null, true);
this._showItem(new Zotero.ItemGroup('separator', false));
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();
@ -263,11 +291,7 @@ Zotero.CollectionTreeView.prototype.reload = function()
for (var i=0; i<this.rowCount; i++) {
if (this.isContainer(i) && this.isContainerOpen(i)) {
var itemGroup = this._getItemAtRow(i);
if (!itemGroup.isCollection()) {
continue;
}
openCollections.push(itemGroup.ref.id);
openCollections.push(this._getItemAtRow(i).ref.id);
}
}
@ -376,7 +400,7 @@ Zotero.CollectionTreeView.prototype.notify = function(action, type, ids)
this.rememberSelection(savedSelection);
}
else if (action == 'modify' || action == 'refresh') {
if (type != 'commons') {
if (type != 'bucket') {
this.reload();
}
this.rememberSelection(savedSelection);
@ -422,8 +446,10 @@ Zotero.CollectionTreeView.prototype.notify = function(action, type, ids)
this.rememberSelection(savedSelection);
break;
case 'commons':
case 'bucket':
this.reload();
this.rememberSelection(savedSelection);
break;
}
}
@ -511,15 +537,14 @@ Zotero.CollectionTreeView.prototype.getImageSrc = function(row, col)
if (source.ref.id == 'group-libraries-header') {
collectionType = 'groups';
}
else if (source.ref.id == 'commons-header') {
collectionType = 'commons';
}
break;
case 'group':
collectionType = 'library';
break;
case 'commons':
collectionType = 'commons';
break;
}
return "chrome://zotero/skin/treesource-" + collectionType + ".png";
}
@ -527,7 +552,7 @@ Zotero.CollectionTreeView.prototype.getImageSrc = function(row, col)
Zotero.CollectionTreeView.prototype.isContainer = function(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)
@ -547,6 +572,9 @@ Zotero.CollectionTreeView.prototype.isContainerEmpty = function(row)
if (itemGroup.isHeader()) {
return false;
}
if (itemGroup.isBucket()) {
return true;
}
if (itemGroup.isGroup()) {
return !itemGroup.ref.hasCollections();
}
@ -604,6 +632,8 @@ Zotero.CollectionTreeView.prototype.toggleOpenState = function(row)
if (itemGroup.type == 'header') {
itemGroup.ref.expand();
}
else if(itemGroup.type == 'bucket') {
}
else {
if (itemGroup.isLibrary()) {
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
if (!itemGroup.editable
// Commons can be dropped on but not edited
&& !itemGroup.isCommons()) {
if (dataType == 'zotero/item' && itemGroup.isBucket()) {
return true;
}
if (!itemGroup.editable) {
return false;
}
if (dataType == 'zotero/item') {
if(itemGroup.isCommons()) {
return true;
}
var ids = data;
var items = Zotero.Items.get(ids);
var skip = true;
@ -1223,8 +1251,8 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient)
var targetLibraryID = null;
}
if(itemGroup.isCommons()) {
Zotero.Commons.uploadItems(ids);
if(itemGroup.isBucket()) {
itemGroup.ref.uploadItems(ids);
return;
}
@ -1625,9 +1653,9 @@ Zotero.ItemGroup.prototype.isShare = function()
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()
@ -1654,7 +1682,7 @@ Zotero.ItemGroup.prototype.isWithinGroup = function () {
}
Zotero.ItemGroup.prototype.__defineGetter__('editable', function () {
if (this.isTrash() || this.isShare() || this.isCommons()) {
if (this.isTrash() || this.isShare() || this.isBucket()) {
return false;
}
if (!this.isWithinGroup()) {
@ -1713,6 +1741,9 @@ Zotero.ItemGroup.prototype.getName = function()
case 'share':
return this.ref.name;
case 'bucket':
return this.ref.name;
case 'trash':
return Zotero.getString('pane.collections.trash');
@ -1723,9 +1754,6 @@ Zotero.ItemGroup.prototype.getName = function()
case 'header':
return this.ref.label;
case 'commons':
return "Commons";
default:
return "";
}
@ -1738,8 +1766,8 @@ Zotero.ItemGroup.prototype.getChildItems = function()
case 'share':
return this.ref.getAll();
case 'commons':
return Zotero.Commons.getItems();
case 'bucket':
return this.ref.getItems();
case 'header':
return [];
@ -1852,7 +1880,7 @@ Zotero.ItemGroup.prototype.getChildTags = function() {
case 'share':
return false;
case 'commons':
case 'bucket':
return false;
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.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.debug('=============');
if (!this._treebox || !this._treebox.treeBody) {
Components.utils.reportError("Treebox didn't exist in itemTreeView.notify()");
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()");
return;
}
Zotero.debug(1);
var itemGroup = this._itemGroup;
var madeChanges = false;
@ -285,10 +284,9 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
this.refresh();
}
}
else if (type == 'commons') {
if (itemGroup.isCommons()) {
else if (type == 'bucket') {
if (itemGroup.isBucket()) {
this.refresh();
this.sort();
}
}
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')
{
Zotero.debug(2);
// If saved search or trash, just re-run search
if (itemGroup.isSearch() || itemGroup.isTrash()) {
this.refresh();
@ -502,7 +499,6 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
if(madeChanges)
{
Zotero.debug(3);
// If adding and this is the active window, select the item
if(action == 'add' && ids.length===1 && activeWindow)
{
@ -515,7 +511,7 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
// Reset to Info tab
this._ownerDocument.getElementById('zotero-view-tabbox').selectedIndex = 0;
Zotero.debug(4);
this.selectItem(ids[0]);
}
// If single item is selected and was modified
@ -544,7 +540,6 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
}
else
{
Zotero.debug(4);
var previousRow = this._itemRowMap[ids[0]];
if (sort) {
@ -1117,8 +1112,6 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
*/
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)
if (Zotero.suppressUIUpdates) {
return;
@ -1262,7 +1255,10 @@ Zotero.ItemTreeView.prototype.deleteSelection = function (force)
var itemGroup = this._itemGroup;
if (itemGroup.isTrash()) {
if (itemGroup.isBucket()) {
itemGroup.ref.deleteItems(ids);
}
else if (itemGroup.isTrash()) {
Zotero.Items.erase(ids);
}
else if (itemGroup.isGroup() || (force && itemGroup.isWithinGroup())) {
@ -1274,9 +1270,6 @@ Zotero.ItemTreeView.prototype.deleteSelection = function (force)
else if (itemGroup.isCollection()) {
itemGroup.ref.removeItems(ids);
}
else if (itemGroup.isCommons()) {
Zotero.Commons.deleteItems(ids);
}
this._treebox.endUpdateBatch();
}

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', 'commons'
'collection-item', 'item-tag', 'tag', 'group', 'bucket'
];
var _inTransaction;
var _locked = false;