diff --git a/chrome/content/zotero/xpcom/data_access.js b/chrome/content/zotero/xpcom/data_access.js index 6e84e3208..4a3d69945 100644 --- a/chrome/content/zotero/xpcom/data_access.js +++ b/chrome/content/zotero/xpcom/data_access.js @@ -641,7 +641,7 @@ Zotero.Item.prototype.setField = function(field, value, loadIn){ * This is the same as the standard title field except for letters and interviews, * which get placeholder titles in square braces (e.g. "[Letter to Thoreau]") */ -Zotero.Item.prototype.getDisplayTitle = function () { +Zotero.Item.prototype.getDisplayTitle = function (includeAuthorAndDate) { var title = this.getField('title'); var itemTypeID = this.getType(); @@ -649,17 +649,35 @@ Zotero.Item.prototype.getDisplayTitle = function () { if (!title && (itemTypeID == 8 || itemTypeID == 10)) { // 'letter' and 'interview' itemTypeIDs var creators = this.getCreators(); + var authors = []; var participants = []; if (creators) { for each(var creator in creators) { if ((itemTypeID == 8 && creator.creatorTypeID == 16) || // 'letter'/'recipient' - (itemTypeID == 10 && creator.creatorTypeID == 7)) { // 'interview'/'interviewee' + (itemTypeID == 10 && creator.creatorTypeID == 7)) { // 'interview'/'interviewer' participants.push(creator); } + else if ((itemTypeID == 8 && creator.creatorTypeID == 1) || // 'letter'/'author' + (itemTypeID == 10 && creator.creatorTypeID == 6)) { // 'interview'/'interviewee' + authors.push(creator); + } + } + } + + var strParts = []; + + if (includeAuthorAndDate) { + var names = []; + for each(author in authors) { + names.push(author.lastName); + } + + // TODO: Use same logic as getFirstCreatorSQL() (including "et al.") + if (names.length) { + strParts.push(Zotero.localeJoin(names, ', ')); } } - title = '['; if (participants.length > 0) { var names = []; for each(participant in participants) { @@ -681,11 +699,21 @@ Zotero.Item.prototype.getDisplayTitle = function () { default: var str = 'manyParticipants'; } - title += Zotero.getString('pane.items.' + itemTypeName + '.' + str, names); + strParts.push(Zotero.getString('pane.items.' + itemTypeName + '.' + str, names)); } else { - title += Zotero.getString('itemTypes.' + itemTypeName); + strParts.push(Zotero.getString('itemTypes.' + itemTypeName)); } + + if (includeAuthorAndDate) { + var d = this.getField('date'); + if (d) { + strParts.push(d); + } + } + + title = '['; + title += Zotero.localeJoin(strParts, '; '); title += ']'; } @@ -2374,11 +2402,16 @@ Zotero.Item.prototype.isCollection = function(){ } -/** -* Convert the item data into a multidimensional associative array -* for use by the export functions -**/ -Zotero.Item.prototype.toArray = function(){ +/* + * Convert the item data into a multidimensional associative array + * for use by the export functions + * + * Modes: + * + * 1 == e.g. [Letter to Valee] + * 2 == e.g. [Stothard; Letter to Valee; May 8, 1928] + */ +Zotero.Item.prototype.toArray = function(mode) { if (this.getID() && !this._itemDataLoaded){ this._loadItemData(); } @@ -2415,6 +2448,14 @@ Zotero.Item.prototype.toArray = function(){ arr[Zotero.ItemFields.getName(i)] = this._itemData[i] ? this._itemData[i] : ''; } + if (mode == 1 || mode == 2) { + if (!arr.title && + (this.getType() == Zotero.ItemTypes.getID('letter') || + this.getType() == Zotero.ItemTypes.getID('interview'))) { + arr.title = this.getDisplayTitle(mode == 2); + } + } + if (!this.isNote() && !this.isAttachment()){ // Creators arr['creators'] = []; diff --git a/components/zotero-protocol-handler.js b/components/zotero-protocol-handler.js index 0417a08a2..a9c75cc5b 100644 --- a/components/zotero-protocol-handler.js +++ b/components/zotero-protocol-handler.js @@ -157,7 +157,7 @@ function ChromeExtensionHandler() { // If combining children, add matching parents else if (combineChildItems) { itemsHash[results[i].getID()] = items.length; - items.push(results[i].toArray()); + items.push(results[i].toArray(2)); // Flag item as a search match items[items.length - 1].reportSearchMatch = true; } @@ -185,12 +185,12 @@ function ChromeExtensionHandler() { } if (combineChildItems) { - // Add parents of matches if not parents aren't matches themselves + // Add parents of matches if parents aren't matches themselves for (var id in searchParentIDs) { if (!searchItemIDs[id]) { var item = Zotero.Items.get(id); itemsHash[id] = items.length; - items.push(item.toArray()); + items.push(item.toArray(2)); } } @@ -225,7 +225,7 @@ function ChromeExtensionHandler() { // add on its own if (searchItemIDs[parentID]) { itemsHash[parentID] = [items.length]; - items.push(parentItem.toArray()); + items.push(parentItem.toArray(2)); items[items.length - 1].reportSearchMatch = true; } else { @@ -235,7 +235,7 @@ function ChromeExtensionHandler() { // Now add parent and child itemsHash[parentID].push(items.length); - items.push(parentItem.toArray()); + items.push(parentItem.toArray(2)); if (item.isNote()) { items[items.length - 1].reportChildren = { notes: [item.toArray()],