Allow an array of strings in Zotero.Item::setTags()

New tags will all be of type 0 (manual)
This commit is contained in:
Dan Stillman 2017-07-18 17:14:20 -04:00
parent 3715c8da1b
commit 09a859d7e3

View file

@ -3372,11 +3372,14 @@ Zotero.Item.prototype.getTagType = function (tagName) {
*
* A separate save() is required to update the database.
*
* @param {Array} tags Tag data in API JSON format (e.g., [{tag: 'tag', type: 1}])
* @param {String[]|Object[]} tags - Array of strings or object in API JSON format
* (e.g., [{tag: 'tag', type: 1}])
*/
Zotero.Item.prototype.setTags = function (tags) {
var oldTags = this.getTags();
var newTags = tags.concat();
var newTags = tags.concat()
// Allow array of strings
.map(tag => typeof tag == 'string' ? { tag } : tag);
for (let i=0; i<oldTags.length; i++) {
oldTags[i] = Zotero.Tags.cleanData(oldTags[i]);
}