Transition __defineGetter/Setter__ to Zotero.defineProperty

This commit is contained in:
Aurimas Vinckevicius 2014-11-14 02:29:54 -06:00
parent f7d5ebc357
commit c222a3248a
3 changed files with 418 additions and 361 deletions

View file

@ -48,27 +48,39 @@ Zotero.Collection.prototype._dataTypes = Zotero.Collection._super.prototype._dat
'childItems' 'childItems'
]); ]);
Zotero.Collection.prototype.__defineGetter__('id', function () { return this._get('id'); }); Zotero.defineProperty(Zotero.Collection.prototype, 'id', {
Zotero.Collection.prototype.__defineSetter__('id', function (val) { this._set('id', val); }); get: function() this._get('id'),
Zotero.Collection.prototype.__defineGetter__('libraryID', function () { return this._get('libraryID'); }); set: function(val) this._set('id', val)
Zotero.Collection.prototype.__defineSetter__('libraryID', function (val) { return this._set('libraryID', val); }); });
Zotero.Collection.prototype.__defineGetter__('key', function () { return this._get('key'); }); Zotero.defineProperty(Zotero.Collection.prototype, 'libraryID', {
Zotero.Collection.prototype.__defineSetter__('key', function (val) { this._set('key', val) }); get: function() this._get('libraryID'),
Zotero.Collection.prototype.__defineGetter__('name', function () { return this._get('name'); }); set: function(val) this._set('libraryID', val)
Zotero.Collection.prototype.__defineSetter__('name', function (val) { this._set('name', val); }); });
// .parentKey and .parentID defined in dataObject.js Zotero.defineProperty(Zotero.Collection.prototype, 'key', {
Zotero.Collection.prototype.__defineGetter__('version', function () { return this._get('version'); }); get: function() this._get('key'),
Zotero.Collection.prototype.__defineSetter__('version', function (val) { this._set('version', val); }); set: function(val) this._set('key', val)
Zotero.Collection.prototype.__defineGetter__('synced', function () { return this._get('synced'); }); });
Zotero.Collection.prototype.__defineSetter__('synced', function (val) { this._set('synced', val); }); Zotero.defineProperty(Zotero.Collection.prototype, 'name', {
get: function() this._get('name'),
Zotero.Collection.prototype.__defineGetter__('parent', function (val) { set: function(val) this._set('name', val)
});
Zotero.defineProperty(Zotero.Collection.prototype, 'version', {
get: function() this._get('version'),
set: function(val) this._set('version', val)
});
Zotero.defineProperty(Zotero.Collection.prototype, 'synced', {
get: function() this._get('synced'),
set: function(val) this._set('synced', val)
});
Zotero.defineProperty(Zotero.Collection.prototype, 'parent', {
get: function() {
Zotero.debug("WARNING: Zotero.Collection.prototype.parent has been deprecated -- use .parentID or .parentKey", 2); Zotero.debug("WARNING: Zotero.Collection.prototype.parent has been deprecated -- use .parentID or .parentKey", 2);
return this.parentID; return this.parentID;
}); },
Zotero.Collection.prototype.__defineSetter__('parent', function (val) { set: function(val) {
Zotero.debug("WARNING: Zotero.Collection.prototype.parent has been deprecated -- use .parentID or .parentKey", 2); Zotero.debug("WARNING: Zotero.Collection.prototype.parent has been deprecated -- use .parentID or .parentKey", 2);
this.parentID = val; this.parentID = val;
}
}); });
Zotero.Collection.prototype._set = function (field, value) { Zotero.Collection.prototype._set = function (field, value) {

View file

@ -106,35 +106,62 @@ Zotero.Item.prototype._dataTypes = Zotero.Item._super.prototype._dataTypes.conca
'relations' 'relations'
]); ]);
Zotero.Item.prototype.__defineGetter__('id', function () this._id); Zotero.defineProperty(Zotero.Item.prototype, 'id', {
Zotero.Item.prototype.__defineGetter__('itemID', function () { get: function() this._id,
set: function(val) this.setField('id', val)
});
Zotero.defineProperty(Zotero.Item.prototype, 'itemID', {
get: function() {
Zotero.debug("Item.itemID is deprecated -- use Item.id"); Zotero.debug("Item.itemID is deprecated -- use Item.id");
return this._id; return this._id;
}
});
Zotero.defineProperty(Zotero.Item.prototype, 'libraryID', {
get: function() this._libraryID,
set: function(val) this.setField('libraryID', val)
});
Zotero.defineProperty(Zotero.Item.prototype, 'key', {
get: function() this._key,
set: function(val) this.setField('key', val)
});
Zotero.defineProperty(Zotero.Item.prototype, 'itemTypeID', {
get: function() this._itemTypeID
});
Zotero.defineProperty(Zotero.Item.prototype, 'dateAdded', {
get: function() this._dateAdded
});
Zotero.defineProperty(Zotero.Item.prototype, 'dateModified', {
get: function() this._dateModified
});
Zotero.defineProperty(Zotero.Item.prototype, 'version', {
get: function() this._itemVersion,
set: function(val) this.setField('version', val)
});
Zotero.defineProperty(Zotero.Item.prototype, 'synced', {
get: function() this._synced,
set: function(val) this.setField('synced', val)
}); });
Zotero.Item.prototype.__defineSetter__('id', function (val) { this.setField('id', val); });
Zotero.Item.prototype.__defineGetter__('libraryID', function () this._libraryID );
Zotero.Item.prototype.__defineSetter__('libraryID', function (val) { this.setField('libraryID', val); });
Zotero.Item.prototype.__defineGetter__('key', function () this._key );
Zotero.Item.prototype.__defineSetter__('key', function (val) { this.setField('key', val) });
Zotero.Item.prototype.__defineGetter__('itemTypeID', function () this._itemTypeID);
Zotero.Item.prototype.__defineGetter__('dateAdded', function () this._dateAdded );
Zotero.Item.prototype.__defineGetter__('dateModified', function () this._dateModified );
Zotero.Item.prototype.__defineGetter__('version', function () this._itemVersion );
Zotero.Item.prototype.__defineSetter__('version', function (val) { return this.setField('itemVersion', val); });
Zotero.Item.prototype.__defineGetter__('synced', function () this._synced );
Zotero.Item.prototype.__defineSetter__('synced', function (val) { return this.setField('synced', val); });
// .parentKey and .parentID defined in dataObject.js, but create aliases // .parentKey and .parentID defined in dataObject.js, but create aliases
Zotero.Item.prototype.__defineGetter__('parentItemKey', function () this._parentKey ); Zotero.defineProperty(Zotero.Item.prototype, 'parentItemID', {
Zotero.Item.prototype.__defineSetter__('parentItemKey', function (val) this._setParentKey(val) ); get: function() this.parentID,
Zotero.Item.prototype.__defineGetter__('parentItemID', function () this._getParentID() ); set: function(val) this.parentID = val
Zotero.Item.prototype.__defineSetter__('parentItemID', function (val) this._setParentID(val) ); });
Zotero.defineProperty(Zotero.Item.prototype, 'parentItemKey', {
get: function() this.parentKey,
set: function(val) this.parentKey = val
});
Zotero.Item.prototype.__defineGetter__('firstCreator', function () this._firstCreator ); Zotero.defineProperty(Zotero.Item.prototype, 'firstCreator', {
Zotero.Item.prototype.__defineGetter__('sortCreator', function () this._sortCreator ); get: function() this._firstCreator
});
Zotero.Item.prototype.__defineGetter__('relatedItems', function () { return this._getRelatedItems(true); }); Zotero.defineProperty(Zotero.Item.prototype, 'sortCreator', {
Zotero.Item.prototype.__defineSetter__('relatedItems', function (arr) { this._setRelatedItems(arr); }); get: function() this._sortCreator
});
Zotero.defineProperty(Zotero.Item.prototype, 'relatedItems', {
get: function() this._getRelatedItems(true),
set: function(arr) this._setRelatedItems(arr)
});
Zotero.Item.prototype.getID = function() { Zotero.Item.prototype.getID = function() {
Zotero.debug('Item.getID() is deprecated -- use Item.id'); Zotero.debug('Item.getID() is deprecated -- use Item.id');
@ -1059,8 +1086,8 @@ Zotero.Item.prototype.removeCreator = function(orderIndex, allowMissing) {
return true; return true;
} }
Zotero.defineProperty(Zotero.Item.prototype, 'deleted', {
Zotero.Item.prototype.__defineGetter__('deleted', function () { get: function() {
if (!this.id) { if (!this.id) {
return false; return false;
} }
@ -1068,10 +1095,8 @@ Zotero.Item.prototype.__defineGetter__('deleted', function () {
return this._deleted; return this._deleted;
} }
this._requireData('primaryData'); this._requireData('primaryData');
}); },
set: function(val) {
Zotero.Item.prototype.__defineSetter__('deleted', function (val) {
var deleted = !!val; var deleted = !!val;
if (this._deleted == deleted) { if (this._deleted == deleted) {
@ -1081,6 +1106,7 @@ Zotero.Item.prototype.__defineSetter__('deleted', function (val) {
this._markFieldChange('deleted', !!this._deleted); this._markFieldChange('deleted', !!this._deleted);
this._changed.deleted = true; this._changed.deleted = true;
this._deleted = deleted; this._deleted = deleted;
}
}); });
@ -2688,15 +2714,14 @@ Zotero.Item.prototype.getAttachmentLinkMode = function() {
* Possible values specified as constants in Zotero.Attachments * Possible values specified as constants in Zotero.Attachments
* (e.g. Zotero.Attachments.LINK_MODE_LINKED_FILE) * (e.g. Zotero.Attachments.LINK_MODE_LINKED_FILE)
*/ */
Zotero.Item.prototype.__defineGetter__('attachmentLinkMode', function () { Zotero.defineProperty(Zotero.Item.prototype, 'attachmentLinkMode', {
get: function() {
if (!this.isAttachment()) { if (!this.isAttachment()) {
return undefined; return undefined;
} }
return this._attachmentLinkMode; return this._attachmentLinkMode;
}); },
set: function(val) {
Zotero.Item.prototype.__defineSetter__('attachmentLinkMode', function (val) {
if (!this.isAttachment()) { if (!this.isAttachment()) {
throw (".attachmentLinkMode can only be set for attachment items"); throw (".attachmentLinkMode can only be set for attachment items");
} }
@ -2721,6 +2746,7 @@ Zotero.Item.prototype.__defineSetter__('attachmentLinkMode', function (val) {
} }
this._changed.attachmentData.linkMode = true; this._changed.attachmentData.linkMode = true;
this._attachmentLinkMode = val; this._attachmentLinkMode = val;
}
}); });
@ -2729,23 +2755,24 @@ Zotero.Item.prototype.getAttachmentMIMEType = function() {
return this.attachmentContentType; return this.attachmentContentType;
}; };
Zotero.Item.prototype.__defineGetter__('attachmentMIMEType', function () { Zotero.defineProperty(Zotero.Item.prototype, 'attachmentMIMEType', {
get: function() {
Zotero.debug(".attachmentMIMEType deprecated -- use .attachmentContentType"); Zotero.debug(".attachmentMIMEType deprecated -- use .attachmentContentType");
return this.attachmentContentType; return this.attachmentContentType;
}
}); });
/** /**
* Content type of an attachment (e.g. 'text/plain') * Content type of an attachment (e.g. 'text/plain')
*/ */
Zotero.Item.prototype.__defineGetter__('attachmentContentType', function () { Zotero.defineProperty(Zotero.Item.prototype, 'attachmentContentType', {
get: function() {
if (!this.isAttachment()) { if (!this.isAttachment()) {
return undefined; return undefined;
} }
return this._attachmentContentType; return this._attachmentContentType;
}); },
set: function(val) {
Zotero.Item.prototype.__defineSetter__('attachmentContentType', function (val) {
if (!this.isAttachment()) { if (!this.isAttachment()) {
throw (".attachmentContentType can only be set for attachment items"); throw (".attachmentContentType can only be set for attachment items");
} }
@ -2763,6 +2790,7 @@ Zotero.Item.prototype.__defineSetter__('attachmentContentType', function (val) {
} }
this._changed.attachmentData.contentType = true; this._changed.attachmentData.contentType = true;
this._attachmentContentType = val; this._attachmentContentType = val;
}
}); });
@ -2775,15 +2803,14 @@ Zotero.Item.prototype.getAttachmentCharset = function() {
/** /**
* Character set of an attachment * Character set of an attachment
*/ */
Zotero.Item.prototype.__defineGetter__('attachmentCharset', function () { Zotero.defineProperty(Zotero.Item.prototype, 'attachmentCharset', {
get: function() {
if (!this.isAttachment()) { if (!this.isAttachment()) {
return undefined; return undefined;
} }
return this._attachmentCharset return this._attachmentCharset
}); },
set: function(val) {
Zotero.Item.prototype.__defineSetter__('attachmentCharset', function (val) {
if (!this.isAttachment()) { if (!this.isAttachment()) {
throw (".attachmentCharset can only be set for attachment items"); throw (".attachmentCharset can only be set for attachment items");
} }
@ -2812,18 +2839,17 @@ Zotero.Item.prototype.__defineSetter__('attachmentCharset', function (val) {
} }
this._changed.attachmentData.charset = true; this._changed.attachmentData.charset = true;
this._attachmentCharset = val; this._attachmentCharset = val;
}
}); });
Zotero.defineProperty(Zotero.Item.prototype, 'attachmentPath', {
Zotero.Item.prototype.__defineGetter__('attachmentPath', function () { get: function() {
if (!this.isAttachment()) { if (!this.isAttachment()) {
return undefined; return undefined;
} }
return this._attachmentPath; return this._attachmentPath;
}); },
set: function(val) {
Zotero.Item.prototype.__defineSetter__('attachmentPath', function (val) {
if (!this.isAttachment()) { if (!this.isAttachment()) {
throw (".attachmentPath can only be set for attachment items"); throw (".attachmentPath can only be set for attachment items");
} }
@ -2845,6 +2871,7 @@ Zotero.Item.prototype.__defineSetter__('attachmentPath', function (val) {
} }
this._changed.attachmentData.path = true; this._changed.attachmentData.path = true;
this._attachmentPath = val; this._attachmentPath = val;
}
}); });
@ -2865,15 +2892,14 @@ Zotero.Item.prototype.updateAttachmentPath = function () {
}; };
Zotero.Item.prototype.__defineGetter__('attachmentSyncState', function () { Zotero.defineProperty(Zotero.Item.prototype, 'attachmentSyncState', {
get: function() {
if (!this.isAttachment()) { if (!this.isAttachment()) {
return undefined; return undefined;
} }
return this._attachmentSyncState; return this._attachmentSyncState;
}); },
set: function(val) {
Zotero.Item.prototype.__defineSetter__('attachmentSyncState', function (val) {
if (!this.isAttachment()) { if (!this.isAttachment()) {
throw ("attachmentSyncState can only be set for attachment items"); throw ("attachmentSyncState can only be set for attachment items");
} }
@ -2910,6 +2936,7 @@ Zotero.Item.prototype.__defineSetter__('attachmentSyncState', function (val) {
} }
this._changed.attachmentData.syncState = true; this._changed.attachmentData.syncState = true;
this._attachmentSyncState = val; this._attachmentSyncState = val;
}
}); });
@ -2922,7 +2949,8 @@ Zotero.Item.prototype.__defineSetter__('attachmentSyncState', function (val) {
* @return {Promise<Number|undefined>} File modification time as timestamp in milliseconds, * @return {Promise<Number|undefined>} File modification time as timestamp in milliseconds,
* or undefined if no file * or undefined if no file
*/ */
Zotero.Item.prototype.__defineGetter__('attachmentModificationTime', Zotero.Promise.coroutine(function* () { Zotero.defineProperty(Zotero.Item.prototype, 'attachmentModificationTime', {
get: Zotero.Promise.coroutine(function* () {
if (!this.isAttachment()) { if (!this.isAttachment()) {
return undefined; return undefined;
} }
@ -2944,7 +2972,8 @@ Zotero.Item.prototype.__defineGetter__('attachmentModificationTime', Zotero.Prom
} }
return fmtime; return fmtime;
})); })
});
/** /**
@ -2955,7 +2984,8 @@ Zotero.Item.prototype.__defineGetter__('attachmentModificationTime', Zotero.Prom
* *
* @return {String} MD5 hash of file as hex string * @return {String} MD5 hash of file as hex string
*/ */
Zotero.Item.prototype.__defineGetter__('attachmentHash', function () { Zotero.defineProperty(Zotero.Item.prototype, 'attachmentHash', {
get: function () {
if (!this.isAttachment()) { if (!this.isAttachment()) {
return undefined; return undefined;
} }
@ -2970,6 +3000,7 @@ Zotero.Item.prototype.__defineGetter__('attachmentHash', function () {
} }
return Zotero.Utilities.Internal.md5(file) || undefined; return Zotero.Utilities.Internal.md5(file) || undefined;
}
}); });
@ -2982,7 +3013,8 @@ Zotero.Item.prototype.__defineGetter__('attachmentHash', function () {
* *
* @return {Promise<String>} - A promise for attachment text or empty string if unavailable * @return {Promise<String>} - A promise for attachment text or empty string if unavailable
*/ */
Zotero.Item.prototype.__defineGetter__('attachmentText', Zotero.Promise.coroutine(function* () { Zotero.defineProperty(Zotero.Item.prototype, 'attachmentText', {
get: Zotero.Promise.coroutine(function* () {
if (!this.isAttachment()) { if (!this.isAttachment()) {
return undefined; return undefined;
} }
@ -3059,7 +3091,8 @@ Zotero.Item.prototype.__defineGetter__('attachmentText', Zotero.Promise.coroutin
} }
return str.trim(); return str.trim();
})); })
});

View file

@ -62,21 +62,33 @@ Zotero.Search.prototype.setName = function(val) {
this.name = val; this.name = val;
} }
Zotero.defineProperty(Zotero.Search.prototype, 'id', {
Zotero.Search.prototype.__defineGetter__('id', function () { return this._get('id'); }); get: function() this._get('id'),
Zotero.Search.prototype.__defineSetter__('id', function (val) { this._set('id', val); }); set: function(val) this._set('id', val)
Zotero.Search.prototype.__defineGetter__('libraryID', function () { return this._get('libraryID'); }); });
Zotero.Search.prototype.__defineSetter__('libraryID', function (val) { return this._set('libraryID', val); }); Zotero.defineProperty(Zotero.Search.prototype, 'libraryID', {
Zotero.Search.prototype.__defineGetter__('key', function () { return this._get('key'); }); get: function() this._get('libraryID'),
Zotero.Search.prototype.__defineSetter__('key', function (val) { this._set('key', val) }); set: function(val) this._set('libraryID', val)
Zotero.Search.prototype.__defineGetter__('name', function () { return this._get('name'); }); });
Zotero.Search.prototype.__defineSetter__('name', function (val) { this._set('name', val); }); Zotero.defineProperty(Zotero.Search.prototype, 'key', {
Zotero.Search.prototype.__defineGetter__('version', function () { return this._get('version'); }); get: function() this._get('key'),
Zotero.Search.prototype.__defineSetter__('version', function (val) { this._set('version', val); }); set: function(val) this._set('key', val)
Zotero.Search.prototype.__defineGetter__('synced', function () { return this._get('synced'); }); });
Zotero.Search.prototype.__defineSetter__('synced', function (val) { this._set('synced', val); }); Zotero.defineProperty(Zotero.Search.prototype, 'name', {
get: function() this._get('name'),
Zotero.Search.prototype.__defineGetter__('conditions', function (arr) { this.getSearchConditions(); }); set: function(val) this._set('name', val)
});
Zotero.defineProperty(Zotero.Search.prototype, 'version', {
get: function() this._get('version'),
set: function(val) this._set('version', val)
});
Zotero.defineProperty(Zotero.Search.prototype, 'synced', {
get: function() this._get('synced'),
set: function(val) this._set('synced', val)
});
Zotero.defineProperty(Zotero.Search.prototype, 'conditions', {
get: function() this.getSearchConditions()
});
Zotero.Search.prototype._set = function (field, value) { Zotero.Search.prototype._set = function (field, value) {
if (field == 'id' || field == 'libraryID' || field == 'key') { if (field == 'id' || field == 'libraryID' || field == 'key') {