From ee23bb6bcb2a5302d35689bdce13636f59ba8c96 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 3 Jan 2008 23:10:58 +0000 Subject: [PATCH] Addresses #672, allow child items to exist in collections by themselves for sorting and outlines - Makes sort=note work as expected when combineChildItems is disabled - Fix for standalone notes and attachments not displaying when combineChildItems is disabled --- components/zotero-protocol-handler.js | 47 +++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/components/zotero-protocol-handler.js b/components/zotero-protocol-handler.js index e76e46c64..b41d64a8f 100644 --- a/components/zotero-protocol-handler.js +++ b/components/zotero-protocol-handler.js @@ -154,8 +154,8 @@ function ChromeExtensionHandler() { // items were selected includeAllChildItems = false; } - // If combining children, add matching parents - else if (combineChildItems) { + // If combining children or standalone note/attachment, add matching parents + else if (combineChildItems || !results[i].isRegularItem()) { itemsHash[results[i].getID()] = items.length; items.push(results[i].toArray(2)); // Flag item as a search match @@ -290,10 +290,45 @@ function ChromeExtensionHandler() { // Multidimensional sort do { - var cmp = collation.compareString(0, - a[sorts[index].field], - b[sorts[index].field] - ); + // Note and attachment sorting when combineChildItems is false + if (!combineChildItems && sorts[index].field == 'note') { + if (a.itemType == 'note' || a.itemType == 'attachment') { + var valA = a.note; + } + else if (a.reportChildren) { + var valA = a.reportChildren.notes[0].note; + } + else { + var valA = ''; + } + + if (b.itemType == 'note' || b.itemType == 'attachment') { + var valB = b.note; + } + else if (b.reportChildren) { + var valB = b.reportChildren.notes[0].note; + } + else { + var valB = ''; + } + + // Put items without notes last + if (valA == '' && valB != '') { + var cmp = 1; + } + else if (valA != '' && valB == '') { + var cmp = -1; + } + else { + var cmp = collation.compareString(0, valA, valB); + } + } + else { + var cmp = collation.compareString(0, + a[sorts[index].field], + b[sorts[index].field] + ); + } if (cmp == 0) { continue;