getClassForObjectType => getObjectsClassForObjectType

This commit is contained in:
Aurimas Vinckevicius 2014-11-14 02:34:15 -06:00
parent c222a3248a
commit 4657c46d4b
4 changed files with 10 additions and 13 deletions

View file

@ -201,7 +201,7 @@ Zotero.API.Data = {
var params = this.parsePath(path); var params = this.parsePath(path);
//Zotero.debug(params); //Zotero.debug(params);
return Zotero.DataObjectUtilities.getClassForObjectType(params.objectType) return Zotero.DataObjectUtilities.getObjectsClassForObjectType(params.objectType)
.apiDataGenerator(params); .apiDataGenerator(params);
} }
}; };

View file

@ -70,6 +70,10 @@ Zotero.defineProperty(Zotero.DataObject.prototype, 'parentID', {
set: function(v) this._setParentID(v) set: function(v) this._setParentID(v)
}); });
Zotero.defineProperty(Zotero.DataObject.prototype, 'ObjectsClass', {
get: function() Zotero.DataObjectUtilities.getObjectsClassForObjectType(this.objectType)
});
Zotero.DataObject.prototype._get = function (field) { Zotero.DataObject.prototype._get = function (field) {
if (this['_' + field] !== null) { if (this['_' + field] !== null) {
@ -135,7 +139,7 @@ Zotero.DataObject.prototype._getParentID = function () {
if (!this._parentKey) { if (!this._parentKey) {
return false; return false;
} }
return this._parentID = this._getClass().getIDFromLibraryAndKey(this._libraryID, this._parentKey); return this._parentID = this.ObjectsClass.getIDFromLibraryAndKey(this._libraryID, this._parentKey);
} }
@ -148,7 +152,7 @@ Zotero.DataObject.prototype._getParentID = function () {
Zotero.DataObject.prototype._setParentID = function (id) { Zotero.DataObject.prototype._setParentID = function (id) {
return this._setParentKey( return this._setParentKey(
id id
? this._getClass().getLibraryAndKeyFromID(Zotero.DataObjectUtilities.checkDataID(id))[1] ? this.ObjectsClass.getLibraryAndKeyFromID(Zotero.DataObjectUtilities.checkDataID(id))[1]
: null : null
); );
} }
@ -368,13 +372,6 @@ Zotero.DataObject.prototype._requireData = function (dataType) {
} }
} }
/**
* Returns a global Zotero class object given a data object. (e.g. Zotero.Items)
* @return {obj} One of Zotero data classes
*/
Zotero.DataObject.prototype._getClass = function () {
return Zotero.DataObjectUtilities.getClassForObjectType(this._objectType);
}
/** /**
* Loads data for a given data type * Loads data for a given data type

View file

@ -59,12 +59,12 @@ Zotero.DataObjectUtilities = {
}, },
"getObjectTypePlural": function getObjectTypePlural(objectType) { "getObjectTypePlural": function(objectType) {
return objectType == 'search' ? 'searches' : objectType + 's'; return objectType == 'search' ? 'searches' : objectType + 's';
}, },
"getClassForObjectType": function getClassForObjectType(objectType) { "getObjectsClassForObjectType": function(objectType) {
var objectTypePlural = this.getObjectTypePlural(objectType); var objectTypePlural = this.getObjectTypePlural(objectType);
var className = objectTypePlural[0].toUpperCase() + objectTypePlural.substr(1); var className = objectTypePlural[0].toUpperCase() + objectTypePlural.substr(1);
return Zotero[className] return Zotero[className]

View file

@ -1201,7 +1201,7 @@ Zotero.Search.prototype._buildQuery = Zotero.Promise.coroutine(function* () {
let objLibraryID; let objLibraryID;
let objKey = condition.value; let objKey = condition.value;
let objectType = condition.name == 'collection' ? 'collection' : 'search'; let objectType = condition.name == 'collection' ? 'collection' : 'search';
let objectTypeClass = Zotero.DataObjectUtilities.getClassForObjectType(objectType); let objectTypeClass = Zotero.DataObjectUtilities.getObjectsClassForObjectType(objectType);
// Old-style library-key hash // Old-style library-key hash
if (objKey.contains('_')) { if (objKey.contains('_')) {