Closes #756, add "parent item" info for child notes from letters and interviews

Also:

- Adds two modes to toArray() for including letter/interview titles
- Adds mode to getDisplayTitle() for including author and date
This commit is contained in:
Dan Stillman 2007-10-18 18:26:59 +00:00
parent 8af08366e8
commit 4ab9ee060d
2 changed files with 56 additions and 15 deletions

View File

@ -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, * 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]") * 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 title = this.getField('title');
var itemTypeID = this.getType(); var itemTypeID = this.getType();
@ -649,17 +649,35 @@ Zotero.Item.prototype.getDisplayTitle = function () {
if (!title && (itemTypeID == 8 || itemTypeID == 10)) { // 'letter' and 'interview' itemTypeIDs if (!title && (itemTypeID == 8 || itemTypeID == 10)) { // 'letter' and 'interview' itemTypeIDs
var creators = this.getCreators(); var creators = this.getCreators();
var authors = [];
var participants = []; var participants = [];
if (creators) { if (creators) {
for each(var creator in creators) { for each(var creator in creators) {
if ((itemTypeID == 8 && creator.creatorTypeID == 16) || // 'letter'/'recipient' 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); 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) { if (participants.length > 0) {
var names = []; var names = [];
for each(participant in participants) { for each(participant in participants) {
@ -681,11 +699,21 @@ Zotero.Item.prototype.getDisplayTitle = function () {
default: default:
var str = 'manyParticipants'; var str = 'manyParticipants';
} }
title += Zotero.getString('pane.items.' + itemTypeName + '.' + str, names); strParts.push(Zotero.getString('pane.items.' + itemTypeName + '.' + str, names));
} }
else { 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 += ']'; title += ']';
} }
@ -2374,11 +2402,16 @@ Zotero.Item.prototype.isCollection = function(){
} }
/** /*
* Convert the item data into a multidimensional associative array * Convert the item data into a multidimensional associative array
* for use by the export functions * for use by the export functions
**/ *
Zotero.Item.prototype.toArray = function(){ * 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){ if (this.getID() && !this._itemDataLoaded){
this._loadItemData(); this._loadItemData();
} }
@ -2415,6 +2448,14 @@ Zotero.Item.prototype.toArray = function(){
arr[Zotero.ItemFields.getName(i)] = this._itemData[i] ? this._itemData[i] : ''; 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()){ if (!this.isNote() && !this.isAttachment()){
// Creators // Creators
arr['creators'] = []; arr['creators'] = [];

View File

@ -157,7 +157,7 @@ function ChromeExtensionHandler() {
// If combining children, add matching parents // If combining children, add matching parents
else if (combineChildItems) { else if (combineChildItems) {
itemsHash[results[i].getID()] = items.length; itemsHash[results[i].getID()] = items.length;
items.push(results[i].toArray()); items.push(results[i].toArray(2));
// Flag item as a search match // Flag item as a search match
items[items.length - 1].reportSearchMatch = true; items[items.length - 1].reportSearchMatch = true;
} }
@ -185,12 +185,12 @@ function ChromeExtensionHandler() {
} }
if (combineChildItems) { 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) { for (var id in searchParentIDs) {
if (!searchItemIDs[id]) { if (!searchItemIDs[id]) {
var item = Zotero.Items.get(id); var item = Zotero.Items.get(id);
itemsHash[id] = items.length; itemsHash[id] = items.length;
items.push(item.toArray()); items.push(item.toArray(2));
} }
} }
@ -225,7 +225,7 @@ function ChromeExtensionHandler() {
// add on its own // add on its own
if (searchItemIDs[parentID]) { if (searchItemIDs[parentID]) {
itemsHash[parentID] = [items.length]; itemsHash[parentID] = [items.length];
items.push(parentItem.toArray()); items.push(parentItem.toArray(2));
items[items.length - 1].reportSearchMatch = true; items[items.length - 1].reportSearchMatch = true;
} }
else { else {
@ -235,7 +235,7 @@ function ChromeExtensionHandler() {
// Now add parent and child // Now add parent and child
itemsHash[parentID].push(items.length); itemsHash[parentID].push(items.length);
items.push(parentItem.toArray()); items.push(parentItem.toArray(2));
if (item.isNote()) { if (item.isNote()) {
items[items.length - 1].reportChildren = { items[items.length - 1].reportChildren = {
notes: [item.toArray()], notes: [item.toArray()],