Virtualize data objects
This commit is contained in:
parent
5ee40f6601
commit
bc8a340c30
4 changed files with 51 additions and 43 deletions
|
@ -24,12 +24,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Zotero.Collection = function() {
|
Zotero.Collection = function() {
|
||||||
let dataTypes = [
|
Zotero.Collection._super.apply(this);
|
||||||
'primaryData',
|
|
||||||
'childCollections',
|
|
||||||
'childItems'
|
|
||||||
];
|
|
||||||
Zotero.DataObject.apply(this, ['collection', dataTypes]);
|
|
||||||
|
|
||||||
this._name = null;
|
this._name = null;
|
||||||
this._parentID = null;
|
this._parentID = null;
|
||||||
|
@ -42,9 +37,17 @@ Zotero.Collection = function() {
|
||||||
this._childItems = [];
|
this._childItems = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.Collection.prototype = Object.create(Zotero.DataObject.prototype);
|
Zotero.Collection._super = Zotero.DataObject;
|
||||||
|
Zotero.Collection.prototype = Object.create(Zotero.Collection._super.prototype);
|
||||||
Zotero.Collection.constructor = Zotero.Collection;
|
Zotero.Collection.constructor = Zotero.Collection;
|
||||||
|
|
||||||
|
Zotero.Collection.prototype._objectType = 'collection';
|
||||||
|
Zotero.Collection.prototype._dataTypes = Zotero.Collection._super.prototype._dataTypes.concat([
|
||||||
|
'primaryData',
|
||||||
|
'childCollections',
|
||||||
|
'childItems'
|
||||||
|
]);
|
||||||
|
|
||||||
Zotero.Collection.prototype.__defineGetter__('id', function () { return this._get('id'); });
|
Zotero.Collection.prototype.__defineGetter__('id', function () { return this._get('id'); });
|
||||||
Zotero.Collection.prototype.__defineSetter__('id', function (val) { this._set('id', val); });
|
Zotero.Collection.prototype.__defineSetter__('id', function (val) { this._set('id', val); });
|
||||||
Zotero.Collection.prototype.__defineGetter__('libraryID', function () { return this._get('libraryID'); });
|
Zotero.Collection.prototype.__defineGetter__('libraryID', function () { return this._get('libraryID'); });
|
||||||
|
|
|
@ -24,21 +24,16 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param {String} objectType
|
|
||||||
* @param {String[]} dataTypes A set of data types that can be loaded for this data object
|
|
||||||
*
|
|
||||||
* @property {String} (readOnly) objectType
|
* @property {String} (readOnly) objectType
|
||||||
* @property {String} (readOnly) libraryKey
|
* @property {String} (readOnly) libraryKey
|
||||||
* @property {String|null} parentKey Null if no parent
|
* @property {String|null} parentKey Null if no parent
|
||||||
* @property {Integer|false|undefined} parentID False if no parent. Undefined if not applicable (e.g. search objects)
|
* @property {Integer|false|undefined} parentID False if no parent. Undefined if not applicable (e.g. search objects)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Zotero.DataObject = function (objectType, dataTypes) {
|
Zotero.DataObject = function () {
|
||||||
this._objectType = objectType;
|
let objectType = this._objectType;
|
||||||
this._ObjectType = objectType[0].toUpperCase() + objectType.substr(1);
|
this._ObjectType = objectType[0].toUpperCase() + objectType.substr(1);
|
||||||
this._objectTypePlural = Zotero.DataObjectUtilities.getObjectTypePlural(objectType);
|
this._objectTypePlural = Zotero.DataObjectUtilities.getObjectTypePlural(objectType);
|
||||||
this._dataTypes = dataTypes;
|
|
||||||
|
|
||||||
this._id = null;
|
this._id = null;
|
||||||
this._libraryID = null;
|
this._libraryID = null;
|
||||||
|
@ -57,6 +52,9 @@ Zotero.DataObject = function (objectType, dataTypes) {
|
||||||
this._clearChanged();
|
this._clearChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Zotero.DataObject.prototype._objectType = 'dataObject';
|
||||||
|
Zotero.DataObject.prototype._dataTypes = [];
|
||||||
|
|
||||||
Zotero.Utilities.Internal.defineProperty(Zotero.DataObject, 'objectType', {
|
Zotero.Utilities.Internal.defineProperty(Zotero.DataObject, 'objectType', {
|
||||||
get: function() this._objectType
|
get: function() this._objectType
|
||||||
});
|
});
|
||||||
|
@ -74,10 +72,6 @@ Zotero.Utilities.Internal.defineProperty(Zotero.DataObject, 'parentID', {
|
||||||
|
|
||||||
|
|
||||||
Zotero.DataObject.prototype._get = function (field) {
|
Zotero.DataObject.prototype._get = function (field) {
|
||||||
if (this._objectType == 'item') {
|
|
||||||
throw new Error("_get is not valid for items");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this['_' + field] !== null) {
|
if (this['_' + field] !== null) {
|
||||||
return this['_' + field];
|
return this['_' + field];
|
||||||
}
|
}
|
||||||
|
@ -166,11 +160,6 @@ Zotero.DataObject.prototype._setParentID = function (id) {
|
||||||
* @return {Boolean} True if changed, false if stayed the same
|
* @return {Boolean} True if changed, false if stayed the same
|
||||||
*/
|
*/
|
||||||
Zotero.DataObject.prototype._setParentKey = function(key) {
|
Zotero.DataObject.prototype._setParentKey = function(key) {
|
||||||
if (this._objectType == 'item') {
|
|
||||||
if (!this.isNote() && !this.isAttachment()) {
|
|
||||||
throw new Error("_setParentKey() can only be called on items of type 'note' or 'attachment'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
key = Zotero.DataObjectUtilities.checkKey(key);
|
key = Zotero.DataObjectUtilities.checkKey(key);
|
||||||
|
|
||||||
if (this._parentKey == key) {
|
if (this._parentKey == key) {
|
||||||
|
|
|
@ -32,18 +32,7 @@ Zotero.Item = function(itemTypeOrID) {
|
||||||
throw ("Zotero.Item constructor only takes one parameter");
|
throw ("Zotero.Item constructor only takes one parameter");
|
||||||
}
|
}
|
||||||
|
|
||||||
var dataTypes = [
|
Zotero.Item._super.apply(this);
|
||||||
'primaryData',
|
|
||||||
'itemData',
|
|
||||||
'note',
|
|
||||||
'creators',
|
|
||||||
'childItems',
|
|
||||||
'relatedItems', // TODO: remove
|
|
||||||
'tags',
|
|
||||||
'collections',
|
|
||||||
'relations'
|
|
||||||
];
|
|
||||||
Zotero.DataObject.apply(this, ['item', dataTypes]);
|
|
||||||
|
|
||||||
this._disabled = false;
|
this._disabled = false;
|
||||||
|
|
||||||
|
@ -100,10 +89,23 @@ Zotero.Item = function(itemTypeOrID) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.Item.prototype = Object.create(Zotero.DataObject.prototype);
|
Zotero.Item._super = Zotero.DataObject;
|
||||||
|
Zotero.Item.prototype = Object.create(Zotero.Item._super.prototype);
|
||||||
Zotero.Item.constructor = Zotero.Item;
|
Zotero.Item.constructor = Zotero.Item;
|
||||||
|
|
||||||
Zotero.Item.prototype.__defineGetter__('objectType', function () { return 'item'; });
|
Zotero.Item.prototype._objectType = 'item';
|
||||||
|
Zotero.Item.prototype._dataTypes = Zotero.Item._super.prototype._dataTypes.concat([
|
||||||
|
'primaryData',
|
||||||
|
'itemData',
|
||||||
|
'note',
|
||||||
|
'creators',
|
||||||
|
'childItems',
|
||||||
|
'relatedItems', // TODO: remove
|
||||||
|
'tags',
|
||||||
|
'collections',
|
||||||
|
'relations'
|
||||||
|
]);
|
||||||
|
|
||||||
Zotero.Item.prototype.__defineGetter__('id', function () this._id);
|
Zotero.Item.prototype.__defineGetter__('id', function () this._id);
|
||||||
Zotero.Item.prototype.__defineGetter__('itemID', function () {
|
Zotero.Item.prototype.__defineGetter__('itemID', function () {
|
||||||
Zotero.debug("Item.itemID is deprecated -- use Item.id");
|
Zotero.debug("Item.itemID is deprecated -- use Item.id");
|
||||||
|
@ -149,6 +151,17 @@ Zotero.Item.prototype.isPrimaryField = function (fieldName) {
|
||||||
return Zotero.Items.isPrimaryField(fieldName);
|
return Zotero.Items.isPrimaryField(fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Zotero.Item.prototype._get = function (fieldName) {
|
||||||
|
throw new Error("_get is not valid for items");
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.Item.prototype._setParentKey = function() {
|
||||||
|
if (!this.isNote() && !this.isAttachment()) {
|
||||||
|
throw new Error("_setParentKey() can only be called on items of type 'note' or 'attachment'");
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.Item._super.prototype._setParentKey.apply(this, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
|
|
|
@ -24,11 +24,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Zotero.Search = function() {
|
Zotero.Search = function() {
|
||||||
var dataTypes = [
|
Zotero.Search._super.apply(this);
|
||||||
'primaryData',
|
|
||||||
'conditions'
|
|
||||||
];
|
|
||||||
Zotero.DataObject.apply(this, ['search', dataTypes]);
|
|
||||||
|
|
||||||
this._name = null;
|
this._name = null;
|
||||||
|
|
||||||
|
@ -41,9 +37,16 @@ Zotero.Search = function() {
|
||||||
this._hasPrimaryConditions = false;
|
this._hasPrimaryConditions = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.Search.prototype = Object.create(Zotero.DataObject.prototype);
|
Zotero.Search._super = Zotero.DataObject;
|
||||||
|
Zotero.Search.prototype = Object.create(Zotero.Search._super.prototype);
|
||||||
Zotero.Search.constructor = Zotero.Search;
|
Zotero.Search.constructor = Zotero.Search;
|
||||||
|
|
||||||
|
Zotero.Search.prototype._objectType = 'search';
|
||||||
|
Zotero.Search.prototype._dataTypes = Zotero.Search._super.prototype._dataTypes.concat([
|
||||||
|
'primaryData',
|
||||||
|
'conditions'
|
||||||
|
]);
|
||||||
|
|
||||||
Zotero.Search.prototype.getID = function(){
|
Zotero.Search.prototype.getID = function(){
|
||||||
Zotero.debug('Zotero.Search.getName() is deprecated -- use Search.id');
|
Zotero.debug('Zotero.Search.getName() is deprecated -- use Search.id');
|
||||||
return this._id;
|
return this._id;
|
||||||
|
|
Loading…
Reference in a new issue