commit 2a3af13ddfe071faadf9f470a4de7d5f9fc62928
parent 6dfdae870e5fc6e3f408c7384582d258f8f145e7
Author: Dan Stillman <dstillman@zotero.org>
Date: Mon, 13 Apr 2015 03:28:47 -0400
Automatically return local user URI from Zotero.URI.getLibraryURI()
Previously, getItemURI and getCollectionURI had to check the libraryID
to determine whether to return a local URI, and were doing so using an
obsolete check.
Diffstat:
2 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/chrome/content/zotero/xpcom/error.js b/chrome/content/zotero/xpcom/error.js
@@ -47,6 +47,7 @@ Zotero.Error.ERROR_ZFS_OVER_QUOTA = 5;
Zotero.Error.ERROR_ZFS_UPLOAD_QUEUE_LIMIT = 6;
Zotero.Error.ERROR_ZFS_FILE_EDITING_DENIED = 7;
Zotero.Error.ERROR_INVALID_ITEM_TYPE = 8;
+Zotero.Error.ERROR_USER_NOT_AVAILABLE = 9;
//Zotero.Error.ERROR_SYNC_EMPTY_RESPONSE_FROM_SERVER = 6;
//Zotero.Error.ERROR_SYNC_INVALID_RESPONSE_FROM_SERVER = 7;
diff --git a/chrome/content/zotero/xpcom/uri.js b/chrome/content/zotero/xpcom/uri.js
@@ -73,7 +73,15 @@ Zotero.URI = new function () {
this.getLibraryURI = function (libraryID) {
- var path = this.getLibraryPath(libraryID);
+ try {
+ var path = this.getLibraryPath(libraryID);
+ }
+ catch (e) {
+ if (e.error == Zotero.Error.ERROR_USER_NOT_AVAILABLE) {
+ return this.getCurrentUserURI();
+ }
+ throw e;
+ }
return _baseURI + path;
}
@@ -89,7 +97,7 @@ Zotero.URI = new function () {
case 'publications':
var id = Zotero.Users.getCurrentUserID();
if (!id) {
- throw new Exception("User id not available in Zotero.URI.getLibraryPath()");
+ throw new Zotero.Error("User id not available", "USER_NOT_AVAILABLE");
}
if (libraryType == 'publications') {
@@ -113,12 +121,7 @@ Zotero.URI = new function () {
* Return URI of item, which might be a local URI if user hasn't synced
*/
this.getItemURI = function (item) {
- if (item.libraryID) {
- var baseURI = this.getLibraryURI(item.libraryID);
- }
- else {
- var baseURI = this.getCurrentUserURI();
- }
+ var baseURI = this.getLibraryURI(item.libraryID);
return baseURI + "/items/" + item.key;
}
@@ -135,12 +138,7 @@ Zotero.URI = new function () {
* Return URI of collection, which might be a local URI if user hasn't synced
*/
this.getCollectionURI = function (collection) {
- if (collection.libraryID) {
- var baseURI = this.getLibraryURI(collection.libraryID);
- }
- else {
- var baseURI = this.getCurrentUserURI();
- }
+ var baseURI = this.getLibraryURI(collection.libraryID);
return baseURI + "/collections/" + collection.key;
}