Merged revisions 2710-2712,2714-2716,2718-2728,2730-2731,2734,2736-2738,2740-2750,2752-2753,2755,2758-2768,2770-2779,2782,2789-2790,2794,2797-2802,2804,2808-2810,2812,2814-2824,2826-2832,2834-2835 via svnmerge from 1.0 branch

This commit is contained in:
Dan Stillman 2008-06-11 08:55:59 +00:00
parent 1b12446bc0
commit 97f214c9dc
46 changed files with 2969 additions and 1139 deletions

View file

@ -142,6 +142,7 @@ function ChromeExtensionHandler() {
var includeAllChildItems = Zotero.Prefs.get('report.includeAllChildItems');
var combineChildItems = Zotero.Prefs.get('report.combineChildItems');
var unhandledParents = {};
for (var i=0; i<results.length; i++) {
// Don't add child items directly
// (instead mark their parents for inclusion below)
@ -155,12 +156,16 @@ function ChromeExtensionHandler() {
includeAllChildItems = false;
}
// If combining children or standalone note/attachment, add matching parents
else if (combineChildItems || !results[i].isRegularItem()) {
itemsHash[results[i].getID()] = items.length;
else if (combineChildItems || !results[i].isRegularItem()
|| results[i].numChildren() == 0) {
itemsHash[results[i].getID()] = [items.length];
items.push(results[i].toArray(2));
// Flag item as a search match
items[items.length - 1].reportSearchMatch = true;
}
else {
unhandledParents[i] = true;
}
searchItemIDs[results[i].getID()] = true;
}
@ -186,11 +191,21 @@ function ChromeExtensionHandler() {
}
}
}
// If not including all children, add matching parents,
// in case they don't have any matching children below
else {
for (var i in unhandledParents) {
itemsHash[results[i].id] = [items.length];
items.push(results[i].toArray(2));
// Flag item as a search match
items[items.length - 1].reportSearchMatch = true;
}
}
if (combineChildItems) {
// Add parents of matches if parents aren't matches themselves
for (var id in searchParentIDs) {
if (!searchItemIDs[id]) {
if (!searchItemIDs[id] && !itemsHash[id]) {
var item = Zotero.Items.get(id);
itemsHash[id] = items.length;
items.push(item.toArray(2));
@ -290,51 +305,68 @@ function ChromeExtensionHandler() {
// Multidimensional sort
do {
// 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 = '';
// In combineChildItems, use note or attachment as item
if (!combineChildItems) {
if (a.reportChildren) {
if (a.reportChildren.notes.length) {
a = a.reportChildren.notes[0];
}
else {
a = a.reportChildren.attachments[0];
}
}
if (b.itemType == 'note' || b.itemType == 'attachment') {
var valB = b.note;
if (b.reportChildren) {
if (b.reportChildren.notes.length) {
b = b.reportChildren.notes[0];
}
else {
b = b.reportChildren.attachments[0];
}
}
else if (b.reportChildren) {
var valB = b.reportChildren.notes[0].note;
}
var valA, valB;
if (sorts[index].field == 'title') {
// For notes, use content for 'title'
if (a.itemType == 'note') {
valA = a.note;
}
else {
var valB = '';
valA = a.title;
}
// Put items without notes last
if (valA == '' && valB != '') {
var cmp = 1;
}
else if (valA != '' && valB == '') {
var cmp = -1;
if (b.itemType == 'note') {
valB = b.note;
}
else {
var cmp = collation.compareString(0, valA, valB);
valB = b.title;
}
valA = Zotero.Items.getSortTitle(valA);
valB = Zotero.Items.getSortTitle(valB);
}
else {
var cmp = collation.compareString(0,
a[sorts[index].field],
b[sorts[index].field]
);
var valA = a[sorts[index].field];
var valB = b[sorts[index].field];
}
if (cmp == 0) {
continue;
// Put empty values last
if (!valA && valB) {
var cmp = 1;
}
else if (valA && !valB) {
var cmp = -1;
}
else {
var cmp = collation.compareString(0, valA, valB);
}
var result = cmp * sorts[index].order;
var result = 0;
if (cmp != 0) {
result = cmp * sorts[index].order;
}
index++;
}
while (result == 0 && sorts[index]);