Remove deprecated Zotero.Items.add
This commit is contained in:
parent
20444eceb7
commit
707a65c63e
|
@ -215,75 +215,6 @@ Zotero.Items = new function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Create a new item with optional metadata and pass back the primary reference
|
|
||||||
*
|
|
||||||
* Using "var item = new Zotero.Item()" and "item.save()" directly results
|
|
||||||
* in an orphaned reference to the created item. If other code retrieves the
|
|
||||||
* new item with Zotero.Items.get() and modifies it, the original reference
|
|
||||||
* will not reflect the changes.
|
|
||||||
*
|
|
||||||
* Using this method avoids the need to call Zotero.Items.get() after save()
|
|
||||||
* in order to get the primary item reference. Since it accepts metadata
|
|
||||||
* as a JavaScript object, it also offers a simpler syntax than
|
|
||||||
* item.setField() and item.setCreator().
|
|
||||||
*
|
|
||||||
* Callers with no need for an up-to-date reference after save() (or who
|
|
||||||
* don't mind doing an extra Zotero.Items.get()) can use Zotero.Item
|
|
||||||
* directly if they prefer.
|
|
||||||
*
|
|
||||||
* Sample usage:
|
|
||||||
*
|
|
||||||
* var data = {
|
|
||||||
* title: "Shakespeare: The Invention of the Human",
|
|
||||||
* publisher: "Riverhead Hardcover",
|
|
||||||
* date: '1998-10-26',
|
|
||||||
* ISBN: 1573221201,
|
|
||||||
* pages: 745,
|
|
||||||
* creators: [
|
|
||||||
* ['Harold', 'Bloom', 'author']
|
|
||||||
* ]
|
|
||||||
* };
|
|
||||||
* var item = Zotero.Items.add('book', data);
|
|
||||||
*/
|
|
||||||
function add(itemTypeOrID, data) {
|
|
||||||
var item = new Zotero.Item(itemTypeOrID);
|
|
||||||
for (var field in data) {
|
|
||||||
if (field == 'creators') {
|
|
||||||
var i = 0;
|
|
||||||
for each(var creator in data.creators) {
|
|
||||||
// TODO: accept format from toArray()
|
|
||||||
|
|
||||||
var fields = {
|
|
||||||
firstName: creator[0],
|
|
||||||
lastName: creator[1],
|
|
||||||
fieldMode: creator[3] ? creator[3] : 0
|
|
||||||
};
|
|
||||||
|
|
||||||
var creatorDataID = Zotero.Creators.getDataID(fields);
|
|
||||||
if (creatorDataID) {
|
|
||||||
var linkedCreators = Zotero.Creators.getCreatorsWithData(creatorDataID);
|
|
||||||
// TODO: identical creators?
|
|
||||||
var creatorID = linkedCreators[0];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var creatorObj = new Zotero.Creator;
|
|
||||||
creatorObj.setFields(fields);
|
|
||||||
var creatorID = creatorObj.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
item.setCreator(i, Zotero.Creators.get(creatorID), creator[2]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
item.setField(field, data[field]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var id = item.save();
|
|
||||||
|
|
||||||
return this.getAsync(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.cacheFields = Zotero.Promise.coroutine(function* (libraryID, fields, items) {
|
this.cacheFields = Zotero.Promise.coroutine(function* (libraryID, fields, items) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user