www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 511222bcaf2bff7d7482b1e46c011e2c8844efa6
parent 0238a2c13c752b1c0b0ea4ef4c5a7cfac1455c2d
Author: Dan Stillman <dstillman@zotero.org>
Date:   Thu, 23 Jun 2016 04:26:24 -0400

Skip child items when generating export format for CSL JSON

itemToCSLJSON() doesn't seem to need child items, so when a Zotero.Item
is passed to it, don't bother loading child items when calling
itemToExportFormat() to convert the item into the necessary format.

Diffstat:
Mchrome/content/zotero/integration/quickFormat.js | 9---------
Mchrome/content/zotero/xpcom/utilities.js | 4+++-
Mchrome/content/zotero/xpcom/utilities_internal.js | 4++--
3 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/chrome/content/zotero/integration/quickFormat.js b/chrome/content/zotero/integration/quickFormat.js @@ -419,15 +419,6 @@ var Zotero_QuickFormat = new function () { // necessary data var items = yield Zotero.Items.getAsync(searchResultIDs); yield Zotero.Items.loadDataTypes(items); - // Load child items of search matches - // TODO: exclude child items from itemToExportFormat() so this isn't necessary? - for (let item of items) { - let ids = item.getAttachments().concat(item.getNotes()); - if (ids.length) { - let childItems = yield Zotero.Items.getAsync(ids); - yield Zotero.Items.loadDataTypes(childItems) - } - } searchString = searchString.toLowerCase(); var collation = Zotero.getLocaleCollation(); diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js @@ -1613,9 +1613,11 @@ Zotero.Utilities = { * is passed */ "itemToCSLJSON":function(zoteroItem) { + // If a Zotero.Item was passed, convert it to the proper format (skipping child items) and + // call this function again with that object if (zoteroItem instanceof Zotero.Item) { return this.itemToCSLJSON( - Zotero.Utilities.Internal.itemToExportFormat(zoteroItem) + Zotero.Utilities.Internal.itemToExportFormat(zoteroItem, false, true) ); } diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js @@ -765,7 +765,7 @@ Zotero.Utilities.Internal = { * @param {Boolean} legacy Add mappings for legacy (pre-4.0.27) translators * @return {Object} */ - itemToExportFormat: function (zoteroItem, legacy) { + itemToExportFormat: function (zoteroItem, legacy, skipChildItems) { function addCompatibilityMappings(item, zoteroItem) { item.uniqueFields = {}; @@ -862,7 +862,7 @@ Zotero.Utilities.Internal = { item.uri = Zotero.URI.getItemURI(zoteroItem); delete item.key; - if (!zoteroItem.isAttachment() && !zoteroItem.isNote()) { + if (!skipChildItems && !zoteroItem.isAttachment() && !zoteroItem.isNote()) { // Include attachments item.attachments = []; let attachments = zoteroItem.getAttachments();