Additional tweaks to DataObject & descendents to support inheritance
This commit is contained in:
parent
442388304b
commit
adab8e45a7
4 changed files with 88 additions and 77 deletions
|
@ -37,17 +37,18 @@ Zotero.Collection = function() {
|
|||
this._childItems = [];
|
||||
}
|
||||
|
||||
Zotero.Collection._super = Zotero.DataObject;
|
||||
Zotero.Collection.prototype = Object.create(Zotero.Collection._super.prototype);
|
||||
Zotero.Collection.constructor = Zotero.Collection;
|
||||
Zotero.extendClass(Zotero.DataObject, Zotero.Collection);
|
||||
|
||||
Zotero.Collection.prototype._objectType = 'collection';
|
||||
Zotero.Collection.prototype._dataTypes = Zotero.Collection._super.prototype._dataTypes.concat([
|
||||
'primaryData',
|
||||
'childCollections',
|
||||
'childItems'
|
||||
]);
|
||||
|
||||
Zotero.defineProperty(Zotero.Collection.prototype, 'ChildObjects', {
|
||||
get: function() Zotero.Items
|
||||
});
|
||||
|
||||
Zotero.defineProperty(Zotero.Collection.prototype, 'id', {
|
||||
get: function() this._get('id'),
|
||||
set: function(val) this._set('id', val)
|
||||
|
@ -136,7 +137,7 @@ Zotero.Collection.prototype.loadPrimaryData = Zotero.Promise.coroutine(function*
|
|||
var key = this._key;
|
||||
var libraryID = this._libraryID;
|
||||
|
||||
var sql = Zotero.Collections.getPrimaryDataSQL();
|
||||
var sql = this.ObjectsClass.getPrimaryDataSQL();
|
||||
if (id) {
|
||||
sql += " AND O.collectionID=?";
|
||||
var params = id;
|
||||
|
@ -164,7 +165,7 @@ Zotero.Collection.prototype.loadPrimaryData = Zotero.Promise.coroutine(function*
|
|||
Zotero.Collection.prototype.loadFromRow = function(row) {
|
||||
Zotero.debug("Loading collection from row");
|
||||
|
||||
for each(let col in Zotero.Collections.primaryFields) {
|
||||
for each(let col in this.ObjectsClass.primaryFields) {
|
||||
if (row[col] === undefined) {
|
||||
Zotero.debug('Skipping missing collection field ' + col);
|
||||
}
|
||||
|
@ -284,21 +285,12 @@ Zotero.Collection.prototype._initSave = Zotero.Promise.coroutine(function* (env)
|
|||
throw new Error('Collection name is empty');
|
||||
}
|
||||
|
||||
return Zotero.Collection._super.prototype._initSave.apply(this, arguments);
|
||||
});
|
||||
|
||||
Zotero.Collection.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
||||
var isNew = env.isNew;
|
||||
|
||||
var collectionID = env.id = this._id = this.id ? this.id : yield Zotero.ID.get('collections');
|
||||
var libraryID = env.libraryID = this.libraryID;
|
||||
var key = env.key = this._key = this.key ? this.key : this._generateKey();
|
||||
|
||||
Zotero.debug("Saving collection " + this.id);
|
||||
var proceed = yield Zotero.Collection._super.prototype._initSave.apply(this, arguments);
|
||||
if (!proceed) return false;
|
||||
|
||||
// Verify parent
|
||||
if (this._parentKey) {
|
||||
let newParent = Zotero.Collections.getByLibraryAndKey(
|
||||
let newParent = this.ObjectsClass.getByLibraryAndKey(
|
||||
this.libraryID, this._parentKey
|
||||
);
|
||||
|
||||
|
@ -314,12 +306,24 @@ Zotero.Collection.prototype._saveData = Zotero.Promise.coroutine(function* (env)
|
|||
throw ('Cannot move collection "' + this.name + '" into one of its own descendents');
|
||||
}
|
||||
|
||||
var parent = newParent.id;
|
||||
env.parent = newParent.id;
|
||||
}
|
||||
else {
|
||||
var parent = null;
|
||||
env.parent = null;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
Zotero.Collection.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
||||
var isNew = env.isNew;
|
||||
|
||||
var collectionID = env.id = this._id = this.id ? this.id : yield Zotero.ID.get('collections');
|
||||
var libraryID = env.libraryID = this.libraryID;
|
||||
var key = env.key = this._key = this.key ? this.key : this._generateKey();
|
||||
|
||||
Zotero.debug("Saving collection " + this.id);
|
||||
|
||||
var columns = [
|
||||
'collectionID',
|
||||
'collectionName',
|
||||
|
@ -333,7 +337,7 @@ Zotero.Collection.prototype._saveData = Zotero.Promise.coroutine(function* (env)
|
|||
var sqlValues = [
|
||||
collectionID ? { int: collectionID } : null,
|
||||
{ string: this.name },
|
||||
parent ? parent : null,
|
||||
env.parent ? env.parent : null,
|
||||
Zotero.DB.transactionDateTime,
|
||||
this.libraryID ? this.libraryID : 0,
|
||||
key,
|
||||
|
@ -362,12 +366,12 @@ Zotero.Collection.prototype._saveData = Zotero.Promise.coroutine(function* (env)
|
|||
if (this._changed.parentKey) {
|
||||
var parentIDs = [];
|
||||
if (this.id && this._previousData.parentKey) {
|
||||
parentIDs.push(Zotero.Collections.getIDFromLibraryAndKey(
|
||||
parentIDs.push(this.ObjectsClass.getIDFromLibraryAndKey(
|
||||
this.libraryID, this._previousData.parentKey
|
||||
));
|
||||
}
|
||||
if (this.parentKey) {
|
||||
parentIDs.push(Zotero.Collections.getIDFromLibraryAndKey(
|
||||
parentIDs.push(this.ObjectsClass.getIDFromLibraryAndKey(
|
||||
this.libraryID, this.parentKey
|
||||
));
|
||||
}
|
||||
|
@ -380,7 +384,7 @@ Zotero.Collection.prototype._saveData = Zotero.Promise.coroutine(function* (env)
|
|||
|
||||
Zotero.Collection.prototype._finalizeSave = Zotero.Promise.coroutine(function* (env) {
|
||||
var isNew = env.isNew;
|
||||
if (isNew && this.libraryID) {
|
||||
if (isNew && Zotero.Libraries.isGroupLibrary(this.libraryID)) {
|
||||
var groupID = Zotero.Groups.getGroupIDFromLibraryID(this.libraryID);
|
||||
var group = Zotero.Groups.get(groupID);
|
||||
group.clearCollectionCache();
|
||||
|
@ -395,7 +399,7 @@ Zotero.Collection.prototype._finalizeSave = Zotero.Promise.coroutine(function* (
|
|||
|
||||
// Invalidate cached child collections
|
||||
if (env.parentIDs) {
|
||||
Zotero.Collections.refreshChildCollections(env.parentIDs);
|
||||
this.ObjectsClass.refreshChildCollections(env.parentIDs);
|
||||
}
|
||||
|
||||
// New collections have to be reloaded via Zotero.Collections.get(), so mark them as disabled
|
||||
|
@ -446,7 +450,7 @@ Zotero.Collection.prototype.addItems = Zotero.Promise.coroutine(function* (itemI
|
|||
continue;
|
||||
}
|
||||
|
||||
let item = yield Zotero.Items.getAsync(itemID);
|
||||
let item = yield this.ChildObjects.getAsync(itemID);
|
||||
yield item.loadCollections();
|
||||
item.addToCollection(this.id);
|
||||
yield item.save({
|
||||
|
@ -493,7 +497,7 @@ Zotero.Collection.prototype.removeItems = Zotero.Promise.coroutine(function* (it
|
|||
continue;
|
||||
}
|
||||
|
||||
let item = yield Zotero.Items.getAsync(itemID);
|
||||
let item = yield this.ChildObjects.getAsync(itemID);
|
||||
yield item.loadCollections();
|
||||
item.removeFromCollection(this.id);
|
||||
yield item.save({
|
||||
|
@ -545,7 +549,7 @@ Zotero.Collection.prototype.diff = function (collection, includeMatches) {
|
|||
var diff = [];
|
||||
var thisData = this.serialize();
|
||||
var otherData = collection.serialize();
|
||||
var numDiffs = Zotero.Collections.diff(thisData, otherData, diff, includeMatches);
|
||||
var numDiffs = this.ObjectsClass.diff(thisData, otherData, diff, includeMatches);
|
||||
|
||||
// For the moment, just compare children and increase numDiffs if any differences
|
||||
var d1 = Zotero.Utilities.arrayDiff(
|
||||
|
@ -605,7 +609,7 @@ Zotero.Collection.prototype.clone = function (includePrimary, newCollection) {
|
|||
var sameLibrary = newCollection.libraryID == this.libraryID;
|
||||
}
|
||||
else {
|
||||
var newCollection = new Zotero.Collection;
|
||||
var newCollection = new this.constructor;
|
||||
var sameLibrary = true;
|
||||
|
||||
if (includePrimary) {
|
||||
|
@ -641,7 +645,7 @@ Zotero.Collection.prototype.erase = function(deleteItems) {
|
|||
// Descendent collections
|
||||
if (descendents[i].type == 'collection') {
|
||||
collections.push(descendents[i].id);
|
||||
var c = yield Zotero.Collections.getAsync(descendents[i].id);
|
||||
var c = yield this.ObjectsClass.getAsync(descendents[i].id);
|
||||
if (c) {
|
||||
notifierData[c.id] = { old: c.toJSON() };
|
||||
}
|
||||
|
@ -655,7 +659,7 @@ Zotero.Collection.prototype.erase = function(deleteItems) {
|
|||
}
|
||||
}
|
||||
if (del.length) {
|
||||
yield Zotero.Items.trash(del);
|
||||
yield this.ChildObjects.trash(del);
|
||||
}
|
||||
|
||||
// Remove relations
|
||||
|
@ -678,9 +682,9 @@ Zotero.Collection.prototype.erase = function(deleteItems) {
|
|||
|
||||
// TODO: Update member items
|
||||
}.bind(this))
|
||||
.then(function () {
|
||||
.then(() => {
|
||||
// Clear deleted collection from internal memory
|
||||
Zotero.Collections.unload(collections);
|
||||
this.ObjectsClass.unload(collections);
|
||||
//return Zotero.Collections.reloadAll();
|
||||
})
|
||||
.then(function () {
|
||||
|
@ -795,7 +799,7 @@ Zotero.Collection.prototype.getChildren = Zotero.Promise.coroutine(function* (re
|
|||
}
|
||||
|
||||
if (recursive) {
|
||||
let child = yield Zotero.Collections.getAsync(children[i].id);
|
||||
let child = yield this.ObjectsClass.getAsync(children[i].id);
|
||||
let descendents = yield child.getChildren(
|
||||
true, nested, type, includeDeletedItems, level+1
|
||||
);
|
||||
|
@ -851,7 +855,7 @@ Zotero.Collection.prototype.addLinkedCollection = Zotero.Promise.coroutine(funct
|
|||
var predicate = Zotero.Relations.linkedObjectPredicate;
|
||||
if ((yield Zotero.Relations.getByURIs(url1, predicate, url2)).length
|
||||
|| (yield Zotero.Relations.getByURIs(url2, predicate, url1)).length) {
|
||||
Zotero.debug("Collections " + this.key + " and " + collection.key + " are already linked");
|
||||
Zotero.debug(this._ObjectTypePlural + " " + this.key + " and " + collection.key + " are already linked");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -883,7 +887,7 @@ Zotero.Collection.prototype.loadChildCollections = Zotero.Promise.coroutine(func
|
|||
|
||||
if (ids) {
|
||||
for each(var id in ids) {
|
||||
var col = yield Zotero.Collections.getAsync(id);
|
||||
var col = yield this.ObjectsClass.getAsync(id);
|
||||
if (!col) {
|
||||
throw new Error('Collection ' + id + ' not found');
|
||||
}
|
||||
|
@ -923,7 +927,7 @@ Zotero.Collection.prototype.loadChildItems = Zotero.Promise.coroutine(function*
|
|||
this._childItems = [];
|
||||
|
||||
if (ids) {
|
||||
var items = yield Zotero.Items.getAsync(ids)
|
||||
var items = yield this.ChildObjects.getAsync(ids)
|
||||
if (items) {
|
||||
this._childItems = items;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ Zotero.DataObject = function () {
|
|||
let objectType = this._objectType;
|
||||
this._ObjectType = objectType[0].toUpperCase() + objectType.substr(1);
|
||||
this._objectTypePlural = Zotero.DataObjectUtilities.getObjectTypePlural(objectType);
|
||||
this._ObjectTypePlural = this._objectTypePlural[0].toUpperCase() + this._objectTypePlural.substr(1);
|
||||
this._ObjectsClass = Zotero.DataObjectUtilities.getObjectsClassForObjectType(objectType);
|
||||
|
||||
this._id = null;
|
||||
this._libraryID = null;
|
||||
|
@ -53,7 +55,7 @@ Zotero.DataObject = function () {
|
|||
};
|
||||
|
||||
Zotero.DataObject.prototype._objectType = 'dataObject';
|
||||
Zotero.DataObject.prototype._dataTypes = [];
|
||||
Zotero.DataObject.prototype._dataTypes = ['primaryData'];
|
||||
|
||||
Zotero.defineProperty(Zotero.DataObject.prototype, 'objectType', {
|
||||
get: function() this._objectType
|
||||
|
@ -64,6 +66,9 @@ Zotero.defineProperty(Zotero.DataObject.prototype, 'id', {
|
|||
Zotero.defineProperty(Zotero.DataObject.prototype, 'libraryID', {
|
||||
get: function() this._libraryID
|
||||
});
|
||||
Zotero.defineProperty(Zotero.DataObject.prototype, 'key', {
|
||||
get: function() this._key
|
||||
});
|
||||
Zotero.defineProperty(Zotero.DataObject.prototype, 'libraryKey', {
|
||||
get: function() this._libraryID + "/" + this._key
|
||||
});
|
||||
|
@ -77,7 +82,7 @@ Zotero.defineProperty(Zotero.DataObject.prototype, 'parentID', {
|
|||
});
|
||||
|
||||
Zotero.defineProperty(Zotero.DataObject.prototype, 'ObjectsClass', {
|
||||
get: function() Zotero.DataObjectUtilities.getObjectsClassForObjectType(this.objectType)
|
||||
get: function() this._ObjectsClass
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -92,8 +92,11 @@ Zotero.Item = function(itemTypeOrID) {
|
|||
Zotero.extendClass(Zotero.DataObject, Zotero.Item);
|
||||
|
||||
Zotero.Item.prototype._objectType = 'item';
|
||||
Zotero.defineProperty(Zotero.Item.prototype, 'ContainerObjectsClass', {
|
||||
get: function() Zotero.Collections
|
||||
});
|
||||
|
||||
Zotero.Item.prototype._dataTypes = Zotero.Item._super.prototype._dataTypes.concat([
|
||||
'primaryData',
|
||||
'itemData',
|
||||
'note',
|
||||
'creators',
|
||||
|
@ -173,7 +176,7 @@ Zotero.Item.prototype.getType = function() {
|
|||
|
||||
Zotero.Item.prototype.isPrimaryField = function (fieldName) {
|
||||
Zotero.debug("Zotero.Item.isPrimaryField() is deprecated -- use Zotero.Items.isPrimaryField()");
|
||||
return Zotero.Items.isPrimaryField(fieldName);
|
||||
return this.ObjectsClass.isPrimaryField(fieldName);
|
||||
}
|
||||
|
||||
Zotero.Item.prototype._get = function (fieldName) {
|
||||
|
@ -228,7 +231,7 @@ Zotero.Item.prototype.getField = function(field, unformatted, includeBaseMapped)
|
|||
} else if (creators.length > 3) {
|
||||
return creatorsData[0].lastName + " " + Zotero.getString('general.etAl');
|
||||
}
|
||||
} else if (field === 'id' || Zotero.Items.isPrimaryField(field)) {
|
||||
} else if (field === 'id' || this.ObjectsClass.isPrimaryField(field)) {
|
||||
var privField = '_' + field;
|
||||
//Zotero.debug('Returning ' + (this[privField] ? this[privField] : '') + ' (typeof ' + typeof this[privField] + ')');
|
||||
return this[privField];
|
||||
|
@ -313,12 +316,12 @@ Zotero.Item.prototype.loadPrimaryData = Zotero.Promise.coroutine(function* (relo
|
|||
}
|
||||
|
||||
var columns = [], join = [], where = [];
|
||||
var primaryFields = Zotero.Items.primaryFields;
|
||||
var primaryFields = this.ObjectsClass.primaryFields;
|
||||
for (let i=0; i<primaryFields.length; i++) {
|
||||
let field = primaryFields[i];
|
||||
// If field not already set
|
||||
if (field == 'itemID' || this['_' + field] === null || reload) {
|
||||
columns.push(Zotero.Items.getPrimaryDataSQLPart(field));
|
||||
columns.push(this.ObjectsClass.getPrimaryDataSQLPart(field));
|
||||
}
|
||||
}
|
||||
if (!columns.length) {
|
||||
|
@ -326,7 +329,7 @@ Zotero.Item.prototype.loadPrimaryData = Zotero.Promise.coroutine(function* (relo
|
|||
}
|
||||
// This should match Zotero.Items.getPrimaryDataSQL(), but without
|
||||
// necessarily including all columns
|
||||
var sql = "SELECT " + columns.join(", ") + Zotero.Items.primaryDataSQLFrom;
|
||||
var sql = "SELECT " + columns.join(", ") + this.ObjectsClass.primaryDataSQLFrom;
|
||||
if (id) {
|
||||
sql += " AND O.itemID=? ";
|
||||
var params = id;
|
||||
|
@ -363,7 +366,7 @@ Zotero.Item.prototype.loadFromRow = function(row, reload) {
|
|||
}
|
||||
|
||||
if (false) {
|
||||
var primaryFields = Zotero.Items.primaryFields;
|
||||
var primaryFields = this.ObjectsClass.primaryFields;
|
||||
for (let i=0; i<primaryFields.length; i++) {
|
||||
if (primaryFields[i] === undefined) {
|
||||
Zotero.debug('Skipping missing field ' + primaryFields[i]);
|
||||
|
@ -442,7 +445,7 @@ Zotero.Item.prototype.loadFromRow = function(row, reload) {
|
|||
}
|
||||
}
|
||||
else {
|
||||
var primaryFields = Zotero.Items.primaryFields;
|
||||
var primaryFields = this.ObjectsClass.primaryFields;
|
||||
for (let i=0; i<primaryFields.length; i++) {
|
||||
let col = primaryFields[i];
|
||||
|
||||
|
@ -751,7 +754,7 @@ Zotero.Item.prototype.setField = function(field, value, loadIn) {
|
|||
}
|
||||
|
||||
// Primary field
|
||||
if (Zotero.Items.isPrimaryField(field)) {
|
||||
if (this.ObjectsClass.isPrimaryField(field)) {
|
||||
this._requireData('primaryData');
|
||||
|
||||
if (loadIn) {
|
||||
|
@ -1118,7 +1121,7 @@ Zotero.Item.prototype.addRelatedItem = Zotero.Promise.coroutine(function* (itemI
|
|||
return false;
|
||||
}
|
||||
|
||||
var item = yield Zotero.Items.getAsync(itemID);
|
||||
var item = yield this.ObjectsClass.getAsync(itemID);
|
||||
if (!item) {
|
||||
throw ("Can't relate item to invalid item " + itemID
|
||||
+ " in Zotero.Item.addRelatedItem()");
|
||||
|
@ -1349,7 +1352,7 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
|||
|
||||
// Parent item
|
||||
let parentItem = this.parentKey;
|
||||
parentItem = parentItem ? Zotero.Items.getByLibraryAndKey(this.libraryID, parentItem) : null;
|
||||
parentItem = parentItem ? this.ObjectsClass.getByLibraryAndKey(this.libraryID, parentItem) : null;
|
||||
if (this._changed.parentKey) {
|
||||
if (isNew) {
|
||||
if (!parentItem) {
|
||||
|
@ -1387,7 +1390,7 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
|||
|
||||
var oldParentKey = this._previousData.parentKey;
|
||||
if (oldParentKey) {
|
||||
var oldParentItem = Zotero.Items.getByLibraryAndKey(this.libraryID, oldParentKey);
|
||||
var oldParentItem = this.ObjectsClass.getByLibraryAndKey(this.libraryID, oldParentKey);
|
||||
if (oldParentItem) {
|
||||
let oldParentItemNotifierData = {};
|
||||
//oldParentItemNotifierData[oldParentItem.id] = {};
|
||||
|
@ -1617,7 +1620,7 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
|||
+ "(collectionID, itemID, orderIndex) VALUES (?, ?, ?)";
|
||||
yield Zotero.DB.queryAsync(sql, [collectionID, this.id, orderIndex]);
|
||||
|
||||
Zotero.Collections.refreshChildItems(collectionID);
|
||||
yield this.ContainerObjectsClass.refreshChildItems(collectionID);
|
||||
Zotero.Notifier.trigger('add', 'collection-item', collectionID + '-' + this.id);
|
||||
}
|
||||
|
||||
|
@ -1629,7 +1632,7 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
|||
|
||||
for (let i=0; i<toRemove.length; i++) {
|
||||
let collectionID = toRemove[i];
|
||||
Zotero.Collections.refreshChildItems(collectionID);
|
||||
yield this.ContainerObjectsClass.refreshChildItems(collectionID);
|
||||
Zotero.Notifier.trigger('remove', 'collection-item', collectionID + '-' + this.id);
|
||||
}
|
||||
}
|
||||
|
@ -1704,7 +1707,7 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
|||
// Update child item counts and contents
|
||||
if (reloadParentChildItems) {
|
||||
for (let parentItemID in reloadParentChildItems) {
|
||||
let parentItem = yield Zotero.Items.getAsync(parentItemID);
|
||||
let parentItem = yield this.ObjectsClass.getAsync(parentItemID);
|
||||
yield parentItem.reload(['primaryData', 'childItems'], true);
|
||||
parentItem.clearBestAttachmentState();
|
||||
}
|
||||
|
@ -1980,9 +1983,9 @@ Zotero.Item.prototype.getNotes = function(includeTrashed) {
|
|||
// Sort by title if necessary
|
||||
if (!sortChronologically) {
|
||||
var collation = Zotero.getLocaleCollation();
|
||||
rows.sort(function (a, b) {
|
||||
var aTitle = Zotero.Items.getSortTitle(a.title);
|
||||
var bTitle = Zotero.Items.getSortTitle(b.title);
|
||||
rows.sort((a, b) => {
|
||||
var aTitle = this.ObjectsClass.getSortTitle(a.title);
|
||||
var bTitle = this.ObjectsClass.getSortTitle(b.title);
|
||||
return collation.compareString(1, aTitle, bTitle);
|
||||
});
|
||||
}
|
||||
|
@ -2461,7 +2464,7 @@ Zotero.Item.prototype._updateAttachmentStates = function (exists) {
|
|||
}
|
||||
|
||||
try {
|
||||
var item = Zotero.Items.getByLibraryAndKey(this.libraryID, parentKey);
|
||||
var item = this.ObjectsClass.getByLibraryAndKey(this.libraryID, parentKey);
|
||||
}
|
||||
catch (e) {
|
||||
if (e instanceof Zotero.Exception.UnloadedDataException) {
|
||||
|
@ -3121,7 +3124,7 @@ Zotero.Item.prototype.getBestAttachments = Zotero.Promise.coroutine(function* ()
|
|||
+ "AND IA.itemID NOT IN (SELECT itemID FROM deletedItems) "
|
||||
+ "ORDER BY contentType='application/pdf' DESC, value=? DESC, dateAdded ASC";
|
||||
var itemIDs = yield Zotero.DB.columnQueryAsync(sql, [this.id, Zotero.Attachments.LINK_MODE_LINKED_URL, url]);
|
||||
return Zotero.Items.get(itemIDs);
|
||||
return this.ObjectsClass.get(itemIDs);
|
||||
});
|
||||
|
||||
|
||||
|
@ -3377,7 +3380,7 @@ Zotero.Item.prototype.setCollections = function (collectionIDsOrKeys) {
|
|||
var collectionIDs = collectionIDsOrKeys.map(function (val) {
|
||||
return parseInt(val) == val
|
||||
? parseInt(val)
|
||||
: Zotero.Collections.getIDFromLibraryAndKey(this.libraryID, val);
|
||||
: this.ContainerObjectsClass.getIDFromLibraryAndKey(this.libraryID, val);
|
||||
}.bind(this));
|
||||
collectionIDs = Zotero.Utilities.arrayUnique(collectionIDs);
|
||||
|
||||
|
@ -3402,7 +3405,7 @@ Zotero.Item.prototype.setCollections = function (collectionIDsOrKeys) {
|
|||
Zotero.Item.prototype.addToCollection = function (collectionIDOrKey) {
|
||||
var collectionID = parseInt(collectionIDOrKey) == collectionIDOrKey
|
||||
? parseInt(collectionIDOrKey)
|
||||
: Zotero.Collections.getIDFromLibraryAndKey(this.libraryID, collectionIDOrKey)
|
||||
: this.ContainerObjectsClass.getIDFromLibraryAndKey(this.libraryID, collectionIDOrKey)
|
||||
|
||||
if (!collectionID) {
|
||||
throw new Error("Invalid collection '" + collectionIDOrKey + "'");
|
||||
|
@ -3427,7 +3430,7 @@ Zotero.Item.prototype.addToCollection = function (collectionIDOrKey) {
|
|||
Zotero.Item.prototype.removeFromCollection = function (collectionIDOrKey) {
|
||||
var collectionID = parseInt(collectionIDOrKey) == collectionIDOrKey
|
||||
? parseInt(collectionIDOrKey)
|
||||
: Zotero.Collections.getIDFromLibraryAndKey(this.libraryID, collectionIDOrKey)
|
||||
: this.ContainerObjectsClass.getIDFromLibraryAndKey(this.libraryID, collectionIDOrKey)
|
||||
|
||||
if (!collectionID) {
|
||||
throw new Error("Invalid collection '" + collectionIDOrKey + "'");
|
||||
|
@ -3576,7 +3579,7 @@ Zotero.Item.prototype.diff = function (item, includeMatches, ignoreFields) {
|
|||
var thisData = this.serialize();
|
||||
var otherData = item.serialize();
|
||||
|
||||
var numDiffs = Zotero.Items.diff(thisData, otherData, diff, includeMatches);
|
||||
var numDiffs = this.ObjectsClass.diff(thisData, otherData, diff, includeMatches);
|
||||
|
||||
diff[0].creators = [];
|
||||
diff[1].creators = [];
|
||||
|
@ -3712,7 +3715,7 @@ Zotero.Item.prototype.multiDiff = Zotero.Promise.coroutine(function* (otherItems
|
|||
let otherItem = otherItems[i];
|
||||
let diff = [];
|
||||
let otherData = yield otherItem.toJSON();
|
||||
let numDiffs = Zotero.Items.diff(thisData, otherData, diff);
|
||||
let numDiffs = this.ObjectsClass.diff(thisData, otherData, diff);
|
||||
|
||||
if (numDiffs) {
|
||||
for (let field in diff[1]) {
|
||||
|
@ -3846,13 +3849,13 @@ Zotero.Item.prototype.erase = Zotero.Promise.coroutine(function* () {
|
|||
var parentCollectionIDs = this.collections;
|
||||
if (parentCollectionIDs) {
|
||||
for (var i=0; i<parentCollectionIDs.length; i++) {
|
||||
let parentCollection = yield Zotero.Collections.getAsync(parentCollectionIDs[i]);
|
||||
let parentCollection = yield this.ContainerObjectsClass.getAsync(parentCollectionIDs[i]);
|
||||
yield parentCollection.removeItem(this.id);
|
||||
}
|
||||
}
|
||||
|
||||
var parentItem = this.parentKey;
|
||||
parentItem = parentItem ? Zotero.Items.getByLibraryAndKey(this.libraryID, parentItem) : null;
|
||||
parentItem = parentItem ? this.ObjectsClass.getByLibraryAndKey(this.libraryID, parentItem) : null;
|
||||
|
||||
// // Delete associated attachment files
|
||||
if (this.isAttachment()) {
|
||||
|
@ -3878,7 +3881,7 @@ Zotero.Item.prototype.erase = Zotero.Promise.coroutine(function* () {
|
|||
+ "SELECT itemID FROM itemAttachments WHERE parentItemID=?1";
|
||||
let toDelete = yield Zotero.DB.columnQueryAsync(sql, [this.id]);
|
||||
for (let i=0; i<toDelete.length; i++) {
|
||||
let obj = yield Zotero.Items.getAsync(toDelete[i]);
|
||||
let obj = yield this.ObjectsClass.getAsync(toDelete[i]);
|
||||
yield obj.erase();
|
||||
}
|
||||
}
|
||||
|
@ -3887,7 +3890,7 @@ Zotero.Item.prototype.erase = Zotero.Promise.coroutine(function* () {
|
|||
// TEMP: Do something with relations
|
||||
/*var relateds = this._getRelatedItems(true);
|
||||
for each(var id in relateds) {
|
||||
let relatedItem = Zotero.Items.get(id);
|
||||
let relatedItem = this.ObjectsClass.get(id);
|
||||
}*/
|
||||
|
||||
// Clear fulltext cache
|
||||
|
@ -3908,7 +3911,7 @@ Zotero.Item.prototype.erase = Zotero.Promise.coroutine(function* () {
|
|||
}
|
||||
}.bind(this));
|
||||
|
||||
Zotero.Items.unload(this.id);
|
||||
this.ObjectsClass.unload(this.id);
|
||||
|
||||
// Send notification of changed items
|
||||
if (changedItems.length) {
|
||||
|
@ -4110,7 +4113,7 @@ Zotero.Item.prototype.toJSON = Zotero.Promise.coroutine(function* (options, patc
|
|||
// Collections
|
||||
yield this.loadCollections();
|
||||
obj.collections = this.getCollections().map(function (id) {
|
||||
return Zotero.Collections.getLibraryAndKeyFromID(id)[1];
|
||||
return this.ContainerObjectsClass.getLibraryAndKeyFromID(id)[1];
|
||||
});
|
||||
|
||||
// Relations
|
||||
|
@ -4121,9 +4124,9 @@ Zotero.Item.prototype.toJSON = Zotero.Promise.coroutine(function* (options, patc
|
|||
obj.relations[rel.predicate] = rel.object;
|
||||
}
|
||||
var relatedItems = this._getRelatedItems().map(function (key) {
|
||||
return Zotero.Items.getIDFromLibraryAndKey(this.libraryID, key);
|
||||
return this.ObjectsClass.getIDFromLibraryAndKey(this.libraryID, key);
|
||||
}.bind(this)).filter(function (val) val !== false);
|
||||
relatedItems = Zotero.Items.get(relatedItems);
|
||||
relatedItems = this.ObjectsClass.get(relatedItems);
|
||||
var pred = Zotero.Relations.relatedItemPredicate;
|
||||
for (let i=0; i<relatedItems.length; i++) {
|
||||
let item = relatedItems[i];
|
||||
|
@ -4661,7 +4664,7 @@ Zotero.Item.prototype._setRelatedItems = Zotero.Promise.coroutine(function* (ite
|
|||
continue;
|
||||
}
|
||||
|
||||
var item = yield Zotero.Items.getAsync(id);
|
||||
var item = yield this.ObjectsClass.getAsync(id);
|
||||
if (!item) {
|
||||
throw ("Can't relate item to invalid item " + id
|
||||
+ " in Zotero.Item._setRelatedItems()");
|
||||
|
@ -4692,7 +4695,7 @@ Zotero.Item.prototype._setRelatedItems = Zotero.Promise.coroutine(function* (ite
|
|||
newIDs = oldIDs.concat(newIDs);
|
||||
this._relatedItems = [];
|
||||
for each(var itemID in newIDs) {
|
||||
this._relatedItems.push(yield Zotero.Items.getAsync(itemID));
|
||||
this._relatedItems.push(yield this.ObjectsClass.getAsync(itemID));
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -41,7 +41,6 @@ Zotero.extendClass(Zotero.DataObject, Zotero.Search);
|
|||
|
||||
Zotero.Search.prototype._objectType = 'search';
|
||||
Zotero.Search.prototype._dataTypes = Zotero.Search._super.prototype._dataTypes.concat([
|
||||
'primaryData',
|
||||
'conditions'
|
||||
]);
|
||||
|
||||
|
@ -264,7 +263,7 @@ Zotero.Search.prototype._finalizeSave = Zotero.Promise.coroutine(function* (env)
|
|||
Zotero.Notifier.trigger('modify', 'search', this.id, this._previousData);
|
||||
}
|
||||
|
||||
if (isNew && this.libraryID) {
|
||||
if (isNew && Zotero.Libraries.isGroupLibrary(this.libraryID)) {
|
||||
var groupID = Zotero.Groups.getGroupIDFromLibraryID(this.libraryID);
|
||||
var group = yield Zotero.Groups.get(groupID);
|
||||
group.clearSearchCache();
|
||||
|
|
Loading…
Add table
Reference in a new issue