www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 691819bd32d1e11c4ea1e96785cc43cb1164fdf6
parent 4b83d157b98bf83209e0c3dc68e393891b53d473
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 22 Sep 2015 00:53:38 -0400

Add Zotero.Library.prototype.libraryTypeID

Get the library-type-specific id for the library (e.g., userID for user
library, groupID for group library)

Diffstat:
Mchrome/content/zotero/xpcom/data/library.js | 24+++++++++++++++++++++++-
Mtest/tests/libraryTest.js | 8++++++++
2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/chrome/content/zotero/xpcom/data/library.js b/chrome/content/zotero/xpcom/data/library.js @@ -102,12 +102,34 @@ Zotero.defineProperty(Zotero.Library.prototype, 'libraryID', { Zotero.defineProperty(Zotero.Library.prototype, 'id', { get: function() this.libraryID, set: function(val) this.libraryID = val -}); +}); Zotero.defineProperty(Zotero.Library.prototype, 'libraryType', { get: function() this._get('_libraryType'), set: function(v) this._set('_libraryType', v) }); +/** + * Get the library-type-specific id for the library (e.g., userID for user library, + * groupID for group library) + * + * @property + */ +Zotero.defineProperty(Zotero.Library.prototype, 'libraryTypeID', { + get: function () { + switch (this._libraryType) { + case 'user': + case 'publications': + return Zotero.Users.getCurrentUserID(); + + case 'group': + return Zotero.Groups.getGroupIDFromLibraryID(this._libraryID); + + default: + throw new Error(`Cannot return library type id for ${this._libraryType} library`); + } + } +}); + Zotero.defineProperty(Zotero.Library.prototype, 'libraryVersion', { get: function() this._get('_libraryVersion'), set: function(v) this._set('_libraryVersion', v) diff --git a/test/tests/libraryTest.js b/test/tests/libraryTest.js @@ -34,6 +34,14 @@ describe("Zotero.Library", function() { }); }); + describe("#libraryTypeID", function () { + it("should return a group id for a group", function* () { + let library = yield createGroup(); + assert.typeOf(library.libraryTypeID, 'number'); + assert.equal(library.libraryTypeID, library.groupID); + }) + }) + describe("#libraryVersion", function() { it("should be settable to increasing values", function() { let library = new Zotero.Library();