From 07ca00edd538bc6e3111ba5d83349cfe47d632fb Mon Sep 17 00:00:00 2001 From: Aurimas Vinckevicius Date: Mon, 1 Jun 2015 23:31:38 -0500 Subject: [PATCH] Use _canHaveParent property to determine if object can have parent --- chrome/content/zotero/xpcom/data/dataObject.js | 10 +++++++--- chrome/content/zotero/xpcom/search.js | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js index 7eaebb807..e5c02fc43 100644 --- a/chrome/content/zotero/xpcom/data/dataObject.js +++ b/chrome/content/zotero/xpcom/data/dataObject.js @@ -89,6 +89,10 @@ Zotero.defineProperty(Zotero.DataObject.prototype, 'parentID', { set: function(v) this._setParentID(v) }); +Zotero.defineProperty(Zotero.DataObject.prototype, '_canHaveParent', { + value: true +}); + Zotero.defineProperty(Zotero.DataObject.prototype, 'ObjectsClass', { get: function() this._ObjectsClass }); @@ -241,7 +245,7 @@ Zotero.DataObject.prototype._setParentID = function (id) { Zotero.DataObject.prototype._getParentKey = function () { - if (this._objectType == 'search') { + if (!this._canHaveParent) { return undefined; } 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 */ Zotero.DataObject.prototype._setParentKey = function(key) { - if (this._objectType == 'search') { - throw new Error("Cannot set parent key for search"); + if (!this._canHaveParent) { + throw new Error("Cannot set parent key for " + this._objectType); } key = Zotero.DataObjectUtilities.checkKey(key) || false; diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js index bd1028d52..fbea83df0 100644 --- a/chrome/content/zotero/xpcom/search.js +++ b/chrome/content/zotero/xpcom/search.js @@ -86,6 +86,9 @@ Zotero.defineProperty(Zotero.Search.prototype, 'synced', { Zotero.defineProperty(Zotero.Search.prototype, 'conditions', { get: function() this.getConditions() }); +Zotero.defineProperty(Zotero.Search.prototype, '_canHaveParent', { + value: false +}); Zotero.Search.prototype.loadFromRow = function (row) {