Zotero Commons updates:

- Store one item per IA bucket, with attachments stored as objects
- Use proper mediatype field based on Zotero item type
- Commons list is now pulled dynamically based on RDF stored at IA, without need for corresponding local item (which may have been deleted, etc.)
- Once available, OCRed PDFs can be pulled down by right-clicking on Commons and selecting Refresh
- Downloaded OCRed PDFs are now named the same as the existing attachment, with "(OCR)" appended
- The relations table is used to link downloaded OCRed PDFs to the IA file, so the downloaded file can be renamed without triggering another download
- The Commons view is marked for automatic refresh after an item is uploaded
- Added some progress notifications, though more are probably needed
- Other things

Also:

- Added Zotero.File.getBinaryContents(file)
- Erase an item's relations when the item is deleted, and purge orphaned ones
- Zotero.URI.eraseByPathPrefix(prefix) no longer prepends 'http://zotero.org' (which has been moved to Zotero.URI.defaultPrefix)
- New function Zotero.URI.eraseByURI(prefix)

Known Issues:

- Slow (some IA changes should be able to speed it up)
- Identifier format is likely temporary
- Sometimes it stops during setTimeout() calls for no apparent reason whatsoever
- Didn't test items with multiple attachments
- Not sure if Commons view will auto-refresh if you switch to it before the upload is done
- IA translator not yet updated
- Deleting items not supported by IA
- Date Added/Date Modified don't show up properly in Zotero for Commons items
This commit is contained in:
Dan Stillman 2010-04-27 08:03:08 +00:00
parent a678cfa5b9
commit 453fed88bd
12 changed files with 1084 additions and 703 deletions

View File

@ -1343,7 +1343,7 @@ var ZoteroPane = new function()
} }
var itemGroup = this.itemsView._itemGroup; var itemGroup = this.itemsView._itemGroup;
if (!itemGroup.isTrash() && !this.canEdit()) { if (!itemGroup.isTrash() && !itemGroup.isCommons() && !this.canEdit()) {
this.displayCannotEditLibraryMessage(); this.displayCannotEditLibraryMessage();
return; return;
} }
@ -1383,6 +1383,9 @@ var ZoteroPane = new function()
else if (itemGroup.isShare()) { else if (itemGroup.isShare()) {
return; return;
} }
else if (itemGroup.isCommons()) {
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
else if (itemGroup.isTrash()) { else if (itemGroup.isTrash()) {
var start = {}; var start = {};
@ -1462,47 +1465,25 @@ var ZoteroPane = new function()
} }
} }
this.createCommonsBucket = function() { this.refreshCommons = function() {
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var bucketName = { value: '' };
// TODO localize
var result = promptService.prompt(window,
"New Bucket",
"Enter a name for this bucket:", bucketName, "", {});
if (result && bucketName.value) {
Zotero.Commons.createBucket(bucketName.value);
}
}
this.refreshCommonsBucket = function() {
if (this.collectionsView if (this.collectionsView
&& this.collectionsView.selection && this.collectionsView.selection
&& this.collectionsView.selection.count > 0 && this.collectionsView.selection.count == 1
&& this.collectionsView.selection.currentIndex != -1) { && this.collectionsView.selection.currentIndex != -1) {
var bucket = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex); var itemGroup = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex);
if (bucket && bucket.isBucket()) { if (itemGroup && itemGroup.isCommons()) {
this.itemsView._itemGroup.ref._items = null; var self = this;
this.itemsView.refresh(); Zotero.Commons.syncBucketList(function () {
self.itemsView.refresh();
self.itemsView.sort();
// On a manual refresh, also check for new OCRed files
Zotero.Commons.syncFiles();
});
} }
} }
} }
this.removeCommonsBucket = function() {
if (this.collectionsView
&& this.collectionsView.selection
&& this.collectionsView.selection.count > 0
&& this.collectionsView.selection.currentIndex != -1) {
var bucket = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex);
if (bucket && bucket.isBucket()) {
Zotero.Commons.removeBucket(bucket.getName());
}
}
}
function editSelectedCollection() function editSelectedCollection()
{ {
if (!this.canEdit()) { if (!this.canEdit()) {
@ -1802,10 +1783,7 @@ var ZoteroPane = new function()
exportFile: 9, exportFile: 9,
loadReport: 10, loadReport: 10,
emptyTrash: 11, emptyTrash: 11,
createCommonsBucket: 12, refreshCommons: 12
syncBucketList: 13,
removeCommonsBucket: 14,
refreshCommonsBucket: 15
}; };
var itemGroup = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex); var itemGroup = this.collectionsView._getItemAtRow(this.collectionsView.selection.currentIndex);
@ -1873,14 +1851,8 @@ var ZoteroPane = new function()
else if (itemGroup.isTrash()) { else if (itemGroup.isTrash()) {
show = [m.emptyTrash]; show = [m.emptyTrash];
} }
// Header else if (itemGroup.isCommons()) {
else if (itemGroup.isHeader()) { show = [m.refreshCommons];
if (itemGroup.ref.id == 'commons-header') {
show = [m.createCommonsBucket, m.syncBucketList];
}
}
else if (itemGroup.isBucket()) {
show = [m.removeCommonsBucket, m.refreshCommonsBucket];
} }
// Group // Group
else if (itemGroup.isGroup()) { else if (itemGroup.isGroup()) {
@ -2261,7 +2233,7 @@ var ZoteroPane = new function()
return; return;
} }
if (tree.id == 'zotero-collections-tree') { if (tree.id == 'zotero-collections-tree') {
// Ignore triple clicks for collections // Ignore triple clicks for collections
if (event.detail != 2) { if (event.detail != 2) {
return; return;
@ -2295,15 +2267,12 @@ var ZoteroPane = new function()
ZoteroPane.loadURI(uri); ZoteroPane.loadURI(uri);
event.stopPropagation(); event.stopPropagation();
} }
else if(itemGroup.ref.id == 'commons-header') {
ZoteroPane.loadURI(Zotero.Commons.uri);
event.stopPropagation();
}
return; return;
} }
if (itemGroup.isBucket()) { if (itemGroup.isCommons()) {
ZoteroPane.loadURI(itemGroup.ref.uri); // TODO: take to a search of the user's buckets?
//ZoteroPane.loadURI(itemGroup.ref.uri);
event.stopPropagation(); event.stopPropagation();
} }
} }
@ -2325,6 +2294,18 @@ var ZoteroPane = new function()
var item = ZoteroPane.getSelectedItems()[0]; var item = ZoteroPane.getSelectedItems()[0];
if (item) { if (item) {
if (item.isRegularItem()) { if (item.isRegularItem()) {
// Double-click on Commons item should load IA page
var itemGroup = ZoteroPane.collectionsView._getItemAtRow(
ZoteroPane.collectionsView.selection.currentIndex
);
if (itemGroup.isCommons()) {
var bucket = Zotero.Commons.getBucketFromItem(item);
ZoteroPane.loadURI(bucket.uri);
event.stopPropagation();
return;
}
if (!viewOnDoubleClick) { if (!viewOnDoubleClick) {
return; return;
} }
@ -2879,6 +2860,8 @@ var ZoteroPane = new function()
return this.addItemFromPage(itemType, saveSnapshot, row); return this.addItemFromPage(itemType, saveSnapshot, row);
} }
var self = this;
Zotero.MIME.getMIMETypeFromURL(url, function (mimeType, hasNativeHandler) { Zotero.MIME.getMIMETypeFromURL(url, function (mimeType, hasNativeHandler) {
// If native type, save using a hidden browser // If native type, save using a hidden browser
if (hasNativeHandler) { if (hasNativeHandler) {
@ -2943,7 +2926,16 @@ var ZoteroPane = new function()
var collectionID = false; var collectionID = false;
} }
Zotero.Attachments.importFromURL(url, false, false, false, collectionID, null, libraryID); var attachmentItem = Zotero.Attachments.importFromURL(url, false, false, false, collectionID, mimeType, libraryID);
// importFromURL() doesn't trigger the notifier until
// after download is complete
//
// TODO: add a callback to importFromURL()
setTimeout(function () {
self.selectItem(attachmentItem.id);
}, 1001);
return; return;
} }
} }

View File

@ -107,10 +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="Create Bucket" oncommand="ZoteroPane.createCommonsBucket();"/><!--TODO localize --> <menuitem label="Refresh" oncommand="ZoteroPane.refreshCommons();"/><!--TODO localize -->
<menuitem label="Sync Bucket List with IA" oncommand="Zotero.Commons.syncBucketList();"/><!--TODO localize -->
<menuitem label="Remove Bucket from List" oncommand="ZoteroPane.removeCommonsBucket();"/><!--TODO localize -->
<menuitem label="Refresh Bucket" 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', 'bucket']); this._unregisterID = Zotero.Notifier.registerObserver(this, ['collection', 'search', 'share', 'group', 'commons']);
this.showDuplicates = false; this.showDuplicates = false;
} }
@ -194,7 +194,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', false)); this._showItem(new Zotero.ItemGroup('separator'));
var header = { var header = {
id: "group-libraries-header", id: "group-libraries-header",
label: "Group Libraries", // TODO: localize label: "Group Libraries", // TODO: localize
@ -234,30 +234,15 @@ 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', false)); this._showItem(new Zotero.ItemGroup('separator'));
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));
} }
} }
var buckets = Zotero.Commons.buckets; if (Zotero.Commons.enabled) {
if(buckets) { 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.buckets;
}
for(var i = 0, len = buckets.length; i < len; i++) {
self._showItem(new Zotero.ItemGroup('bucket', buckets[i]), 1);
}
}
};
this._showItem(new Zotero.ItemGroup('header', header), null, null, true);
header.expand(buckets);
} }
this._refreshHashMap(); this._refreshHashMap();
@ -278,7 +263,11 @@ 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)) {
openCollections.push(this._getItemAtRow(i).ref.id); var itemGroup = this._getItemAtRow(i);
if (!itemGroup.isCollection()) {
continue;
}
openCollections.push(itemGroup.ref.id);
} }
} }
@ -387,7 +376,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 != 'bucket') { if (type != 'commons') {
this.reload(); this.reload();
} }
this.rememberSelection(savedSelection); this.rememberSelection(savedSelection);
@ -433,7 +422,7 @@ Zotero.CollectionTreeView.prototype.notify = function(action, type, ids)
this.rememberSelection(savedSelection); this.rememberSelection(savedSelection);
break; break;
case 'bucket': case 'commons':
this.reload(); this.reload();
} }
} }
@ -522,14 +511,15 @@ 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";
} }
@ -537,7 +527,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.isBucket(); return itemGroup.isLibrary(true) || itemGroup.isCollection() || itemGroup.isHeader() || itemGroup.isCommons();
} }
Zotero.CollectionTreeView.prototype.isContainerOpen = function(row) Zotero.CollectionTreeView.prototype.isContainerOpen = function(row)
@ -557,9 +547,6 @@ 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();
} }
@ -617,8 +604,6 @@ 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();
@ -1063,12 +1048,14 @@ 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 (!itemGroup.editable
// Commons can be dropped on but not edited
&& !itemGroup.isCommons()) {
return false; return false;
} }
if (dataType == 'zotero/item') { if (dataType == 'zotero/item') {
if(itemGroup.isBucket()) { if(itemGroup.isCommons()) {
return true; return true;
} }
@ -1236,8 +1223,8 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient)
var targetLibraryID = null; var targetLibraryID = null;
} }
if(itemGroup.isBucket()) { if(itemGroup.isCommons()) {
itemGroup.ref.uploadItems(ids); Zotero.Commons.uploadItems(ids);
return; return;
} }
@ -1638,9 +1625,9 @@ Zotero.ItemGroup.prototype.isShare = function()
return this.type == 'share'; return this.type == 'share';
} }
Zotero.ItemGroup.prototype.isBucket = function() Zotero.ItemGroup.prototype.isCommons = function()
{ {
return this.type == 'bucket'; return this.type == 'commons';
} }
Zotero.ItemGroup.prototype.isTrash = function() Zotero.ItemGroup.prototype.isTrash = function()
@ -1667,7 +1654,7 @@ Zotero.ItemGroup.prototype.isWithinGroup = function () {
} }
Zotero.ItemGroup.prototype.__defineGetter__('editable', function () { Zotero.ItemGroup.prototype.__defineGetter__('editable', function () {
if (this.isTrash() || this.isShare()) { if (this.isTrash() || this.isShare() || this.isCommons()) {
return false; return false;
} }
if (!this.isWithinGroup()) { if (!this.isWithinGroup()) {
@ -1726,9 +1713,6 @@ 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');
@ -1739,6 +1723,9 @@ 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 "";
} }
@ -1751,8 +1738,8 @@ Zotero.ItemGroup.prototype.getChildItems = function()
case 'share': case 'share':
return this.ref.getAll(); return this.ref.getAll();
case 'bucket': case 'commons':
return this.ref.getItems(); return Zotero.Commons.getItems();
case 'header': case 'header':
return []; return [];
@ -1865,7 +1852,7 @@ Zotero.ItemGroup.prototype.getChildTags = function() {
case 'share': case 'share':
return false; return false;
case 'bucket': case 'commons':
return false; return false;
case 'header': case 'header':

File diff suppressed because it is too large Load Diff

View File

@ -338,7 +338,7 @@ Zotero.Group.prototype.erase = function() {
Zotero.DB.query(sql, this.libraryID); Zotero.DB.query(sql, this.libraryID);
var prefix = "groups/" + this.id; var prefix = "groups/" + this.id;
Zotero.Relations.eraseByPathPrefix(prefix); Zotero.Relations.eraseByURIPrefix(Zotero.URI.defaultPrefix + prefix);
// Delete group // Delete group
sql = "DELETE FROM groups WHERE groupID=?"; sql = "DELETE FROM groups WHERE groupID=?";

View File

@ -741,7 +741,7 @@ Zotero.Item.prototype.setField = function(field, value, loadIn) {
} }
if (!Zotero.ItemFields.isValidForType(fieldID, this.itemTypeID)) { if (!Zotero.ItemFields.isValidForType(fieldID, this.itemTypeID)) {
var msg = '"' + field + "' is not a valid field for type " + this.itemTypeID; var msg = "'" + field + "' is not a valid field for type " + this.itemTypeID;
if (loadIn) { if (loadIn) {
Zotero.debug(msg + " -- ignoring value '" + value + "'", 2); Zotero.debug(msg + " -- ignoring value '" + value + "'", 2);
@ -1240,7 +1240,7 @@ Zotero.Item.prototype.save = function() {
if (Zotero.ItemFields.getID('accessDate') == fieldID if (Zotero.ItemFields.getID('accessDate') == fieldID
&& this.getField(fieldID) == 'CURRENT_TIMESTAMP') { && this.getField(fieldID) == 'CURRENT_TIMESTAMP') {
value = Zotero.DB.transactionDateTime; value = Zotero.DB.transactionDateTime;
} }
var dataType = ZU.getSQLDataType(value); var dataType = ZU.getSQLDataType(value);
@ -3944,7 +3944,10 @@ Zotero.Item.prototype.erase = function() {
//Zotero.Fulltext.clearItemContent(this.id); //Zotero.Fulltext.clearItemContent(this.id);
} }
// Remove relations
var relation = Zotero.URI.getItemURI(this);
Zotero.Relations.eraseByURIPrefix(relation);
Zotero.DB.query('DELETE FROM annotations WHERE itemID=?', this.id); Zotero.DB.query('DELETE FROM annotations WHERE itemID=?', this.id);
Zotero.DB.query('DELETE FROM highlights WHERE itemID=?', this.id); Zotero.DB.query('DELETE FROM highlights WHERE itemID=?', this.id);
Zotero.DB.query('DELETE FROM deletedItems WHERE itemID=?', this.id); Zotero.DB.query('DELETE FROM deletedItems WHERE itemID=?', this.id);

View File

@ -31,8 +31,6 @@ Zotero.Relations = new function () {
owl: 'http://www.w3.org/2002/07/owl#' owl: 'http://www.w3.org/2002/07/owl#'
}; };
var _prefix = "http://zotero.org/";
this.get = function (id) { this.get = function (id) {
if (typeof id != 'number') { if (typeof id != 'number') {
throw ("id '" + id + "' must be an integer in Zotero.Relations.get()"); throw ("id '" + id + "' must be an integer in Zotero.Relations.get()");
@ -165,13 +163,40 @@ Zotero.Relations = new function () {
} }
this.eraseByPathPrefix = function (prefix) { this.eraseByURIPrefix = function (prefix) {
prefix = _prefix + prefix + '%'; prefix = prefix + '%';
sql = "DELETE FROM relations WHERE subject LIKE ? OR object LIKE ?"; sql = "DELETE FROM relations WHERE subject LIKE ? OR object LIKE ?";
Zotero.DB.query(sql, [prefix, prefix]); Zotero.DB.query(sql, [prefix, prefix]);
} }
this.eraseByURI = function (uri) {
sql = "DELETE FROM relations WHERE subject=? OR object=?";
Zotero.DB.query(sql, [uri, uri]);
}
this.purge = function () {
var sql = "SELECT subject FROM relations UNION SELECT object FROM relations";
var uris = Zotero.DB.columnQuery(sql);
if (uris) {
var prefix = Zotero.URI.defaultPrefix;
Zotero.DB.beginTransaction();
for each(var uri in uris) {
// Skip URIs that don't begin with the default prefix,
// since they don't correspond to local items
if (uri.indexOf(prefix) == -1) {
continue;
}
if (!Zotero.URI.getURIItem(uri)) {
this.eraseByURI(uri);
}
}
Zotero.DB.commitTransaction();
}
}
this.xmlToRelation = function (xml) { this.xmlToRelation = function (xml) {
var relation = new Zotero.Relation; var relation = new Zotero.Relation;
var libraryID = xml.@libraryID.toString(); var libraryID = xml.@libraryID.toString();
@ -196,7 +221,7 @@ Zotero.Relations = new function () {
var [prefix, value] = uri.split(':'); var [prefix, value] = uri.split(':');
if (prefix && value) { if (prefix && value) {
if (!_namespaces[prefix]) { if (!_namespaces[prefix]) {
throw ("Invalid prefix '" + prefix + "' in Zotero.Relations.add()"); throw ("Invalid prefix '" + prefix + "' in Zotero.Relations._getPrefixAndValue()");
} }
return [prefix, value]; return [prefix, value];
} }

View File

@ -137,6 +137,21 @@ Zotero.File = new function(){
} }
/**
* Return the contents of a file as a byte array
*/
this.getBinaryContents = function (bfile) {
var istream = Components.classes["@mozilla.org/network/file-input-stream;1"]
.createInstance(Components.interfaces.nsIFileInputStream);
istream.init(bfile, -1, -1, false);
var bstream = Components.classes["@mozilla.org/binaryinputstream;1"]
.createInstance(Components.interfaces.nsIBinaryInputStream);
bstream.setInputStream(istream);
return bstream.readBytes(bstream.available());
}
/* /*
* Return the contents of a URL as a string * Return the contents of a URL as a string
* *

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', 'bucket']); this._unregisterID = Zotero.Notifier.registerObserver(this, ['item', 'collection-item', 'share-items', 'commons']);
} }
@ -260,6 +260,7 @@ 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;
@ -269,7 +270,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;
@ -284,9 +285,10 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
this.refresh(); this.refresh();
} }
} }
else if (type == 'bucket') { else if (type == 'commons') {
if (itemGroup.isBucket()) { if (itemGroup.isCommons()) {
this.refresh(); this.refresh();
this.sort();
} }
} }
else if (savedSelection.length == 1 && savedSelection[0] == ids[0]) { else if (savedSelection.length == 1 && savedSelection[0] == ids[0]) {
@ -455,6 +457,7 @@ 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();
@ -499,6 +502,7 @@ 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)
{ {
@ -511,7 +515,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
@ -540,6 +544,7 @@ 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) {
@ -1112,6 +1117,8 @@ 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;
@ -1267,8 +1274,8 @@ 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.isBucket()) { else if (itemGroup.isCommons()) {
itemGroup.ref.deleteItems(ids); Zotero.Commons.deleteItems(ids);
} }
this._treebox.endUpdateBatch(); this._treebox.endUpdateBatch();
} }

View File

@ -25,6 +25,8 @@
Zotero.URI = new function () { Zotero.URI = new function () {
this.__defineGetter__('defaultPrefix', function () 'http://zotero.org/');
var _baseURI = ZOTERO_CONFIG.BASE_URI; var _baseURI = ZOTERO_CONFIG.BASE_URI;
var _apiURI = ZOTERO_CONFIG.API_URI; var _apiURI = ZOTERO_CONFIG.API_URI;
@ -166,12 +168,12 @@ Zotero.URI = new function () {
if (itemURI.indexOf(localUserURI) == 0) { if (itemURI.indexOf(localUserURI) == 0) {
itemURI = itemURI.substr(localUserURI.length); itemURI = itemURI.substr(localUserURI.length);
var libraryType = 'user'; var libraryType = 'user';
var libraryTypeID = null; var libraryID = null;
} }
} }
*/ */
var libraryType = 'user'; var libraryType = 'user';
var libraryTypeID = null; var libraryID = null;
} }
// If not found, try global URI // If not found, try global URI
@ -186,7 +188,7 @@ Zotero.URI = new function () {
throw ("Invalid library URI '" + itemURI + "' in Zotero.URI.getURIItem()"); throw ("Invalid library URI '" + itemURI + "' in Zotero.URI.getURIItem()");
} }
var libraryType = matches[1].substr(0, matches[1].length-1); var libraryType = matches[1].substr(0, matches[1].length-1);
var libraryTypeID = matches[2]; var libraryID = matches[2];
itemURI = itemURI.replace(typeRE, ''); itemURI = itemURI.replace(typeRE, '');
} }
@ -202,7 +204,10 @@ Zotero.URI = new function () {
} }
if (libraryType == 'group') { if (libraryType == 'group') {
var libraryID = Zotero.Groups.getLibraryIDFromGroupID(libraryTypeID); if (!Zotero.Libraries.exists(libraryID)) {
return false;
}
var libraryID = Zotero.Groups.getLibraryIDFromGroupID(libraryID);
return Zotero.Items.getByLibraryAndKey(libraryID, itemKey); return Zotero.Items.getByLibraryAndKey(libraryID, itemKey);
} }
} }

View File

@ -1033,6 +1033,8 @@ var Zotero = new function(){
* Returns true if an object (or associative array) has at least one value * Returns true if an object (or associative array) has at least one value
*/ */
function hasValues(obj) { function hasValues(obj) {
Zotero.debug("WARNING: Zotero.isEmpty() is deprecated! Use Zotero.Utilities.isEmpty(obj)", 2);
for (var i in obj) { for (var i in obj) {
return true; return true;
} }
@ -1239,6 +1241,8 @@ var Zotero = new function(){
Zotero.Tags.purge(); Zotero.Tags.purge();
Zotero.Fulltext.purgeUnusedWords(); Zotero.Fulltext.purgeUnusedWords();
Zotero.Items.purge(); Zotero.Items.purge();
// DEBUG: this might not need to be permanent
Zotero.Relations.purge();
if (!skipStoragePurge && Zotero.Utilities.prototype.probability(10)) { if (!skipStoragePurge && Zotero.Utilities.prototype.probability(10)) {
Zotero.Sync.Storage.purgeDeletedStorageFiles('zfs'); Zotero.Sync.Storage.purgeDeletedStorageFiles('zfs');

View File

@ -110,7 +110,6 @@ pref("extensions.zotero.zeroconf.server.enabled", false);
// Zotero Commons // Zotero Commons
pref("extensions.zotero.commons.enabled", false); pref("extensions.zotero.commons.enabled", false);
pref("extensions.zotero.commons.buckets", '');
pref("extensions.zotero.commons.accessKey", ''); pref("extensions.zotero.commons.accessKey", '');
pref("extensions.zotero.commons.secretKey", ''); pref("extensions.zotero.commons.secretKey", '');