Use _canHaveParent property to determine if object can have parent

This commit is contained in:
Aurimas Vinckevicius 2015-06-01 23:31:38 -05:00
parent 87d5625bac
commit 07ca00edd5
2 changed files with 10 additions and 3 deletions

View File

@ -89,6 +89,10 @@ Zotero.defineProperty(Zotero.DataObject.prototype, 'parentID', {
set: function(v) this._setParentID(v) set: function(v) this._setParentID(v)
}); });
Zotero.defineProperty(Zotero.DataObject.prototype, '_canHaveParent', {
value: true
});
Zotero.defineProperty(Zotero.DataObject.prototype, 'ObjectsClass', { Zotero.defineProperty(Zotero.DataObject.prototype, 'ObjectsClass', {
get: function() this._ObjectsClass get: function() this._ObjectsClass
}); });
@ -241,7 +245,7 @@ Zotero.DataObject.prototype._setParentID = function (id) {
Zotero.DataObject.prototype._getParentKey = function () { Zotero.DataObject.prototype._getParentKey = function () {
if (this._objectType == 'search') { if (!this._canHaveParent) {
return undefined; return undefined;
} }
return this._parentKey ? this._parentKey : false return this._parentKey ? this._parentKey : false
@ -254,8 +258,8 @@ Zotero.DataObject.prototype._getParentKey = function () {
* @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 == 'search') { if (!this._canHaveParent) {
throw new Error("Cannot set parent key for search"); throw new Error("Cannot set parent key for " + this._objectType);
} }
key = Zotero.DataObjectUtilities.checkKey(key) || false; key = Zotero.DataObjectUtilities.checkKey(key) || false;

View File

@ -86,6 +86,9 @@ Zotero.defineProperty(Zotero.Search.prototype, 'synced', {
Zotero.defineProperty(Zotero.Search.prototype, 'conditions', { Zotero.defineProperty(Zotero.Search.prototype, 'conditions', {
get: function() this.getConditions() get: function() this.getConditions()
}); });
Zotero.defineProperty(Zotero.Search.prototype, '_canHaveParent', {
value: false
});
Zotero.Search.prototype.loadFromRow = function (row) { Zotero.Search.prototype.loadFromRow = function (row) {