Add Zotero.Library.prototype.libraryTypeID
Get the library-type-specific id for the library (e.g., userID for user library, groupID for group library)
This commit is contained in:
parent
4b83d157b9
commit
691819bd32
2 changed files with 31 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue