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.
This commit is contained in:
Dan Stillman 2015-04-13 03:28:47 -04:00
parent 6dfdae870e
commit 2a3af13ddf
2 changed files with 13 additions and 14 deletions

View file

@ -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;

View file

@ -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;
}