Addresses #756, add "parent item" info for child notes from letters and interviews
- Displays placeholder title in square braces for letters and interviews without titles - Ignores square braces and quotation marks when sorting fields
This commit is contained in:
parent
bef4ff4db9
commit
03494d7405
|
@ -635,6 +635,64 @@ Zotero.Item.prototype.setField = function(field, value, loadIn){
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get the title for an item for display in the interface
|
||||
*
|
||||
* 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 () {
|
||||
var title = this.getField('title');
|
||||
|
||||
var itemTypeID = this.getType();
|
||||
var itemTypeName = Zotero.ItemTypes.getName(itemTypeID);
|
||||
|
||||
if (!title && (itemTypeID == 8 || itemTypeID == 10)) { // 'letter' and 'interview' itemTypeIDs
|
||||
var creators = this.getCreators();
|
||||
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'
|
||||
participants.push(creator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
title = '[';
|
||||
if (participants.length > 0) {
|
||||
var names = [];
|
||||
for each(participant in participants) {
|
||||
names.push(participant.lastName);
|
||||
}
|
||||
switch (names.length) {
|
||||
case 1:
|
||||
var str = 'oneParticipant';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
var str = 'twoParticipants';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
var str = 'threeParticipants';
|
||||
break;
|
||||
|
||||
default:
|
||||
var str = 'manyParticipants';
|
||||
}
|
||||
title += Zotero.getString('pane.items.' + itemTypeName + '.' + str, names);
|
||||
}
|
||||
else {
|
||||
title += Zotero.getString('itemTypes.' + itemTypeName);
|
||||
}
|
||||
title += ']';
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Save changes back to database
|
||||
*
|
||||
|
@ -1402,7 +1460,9 @@ Zotero.Item.prototype.getNotes = function(){
|
|||
// Sort by title
|
||||
var collation = Zotero.getLocaleCollation();
|
||||
var f = function (a, b) {
|
||||
return collation.compareString(1, a.title, b.title);
|
||||
var aTitle = Zotero.Items.getSortTitle(a.title);
|
||||
var bTitle = Zotero.Items.getSortTitle(b.title);
|
||||
return collation.compareString(1, aTitle, bTitle);
|
||||
}
|
||||
|
||||
var noteIDs = [];
|
||||
|
@ -2497,6 +2557,8 @@ Zotero.Items = new function(){
|
|||
this.erase = erase;
|
||||
this.purge = purge;
|
||||
this.unload = unload;
|
||||
this.getFirstCreatorSQL = getFirstCreatorSQL;
|
||||
this.getSortTitle = getSortTitle;
|
||||
|
||||
// Private members
|
||||
var _items = [];
|
||||
|
@ -2919,6 +2981,11 @@ Zotero.Items = new function(){
|
|||
}
|
||||
|
||||
|
||||
function getSortTitle(title) {
|
||||
return title.replace(/^[\[\'\"](.*)[\'\"\]]?$/, '$1')
|
||||
}
|
||||
|
||||
|
||||
function _load() {
|
||||
if (!arguments[0] && _itemsLoaded) {
|
||||
return;
|
||||
|
|
|
@ -228,7 +228,7 @@ Zotero.ItemTreeView.prototype.refresh = function()
|
|||
/*
|
||||
* Called by Zotero.Notifier on any changes to items in the data layer
|
||||
*/
|
||||
Zotero.ItemTreeView.prototype.notify = function(action, type, ids)
|
||||
Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
|
||||
{
|
||||
if (!this._treebox || !this._treebox.treeBody) {
|
||||
Components.utils.reportError("Treebox didn't exist in itemTreeView.notify()");
|
||||
|
@ -543,9 +543,15 @@ Zotero.ItemTreeView.prototype.getCellText = function(row, column)
|
|||
else if (column.id == "zotero-items-column-year") {
|
||||
val = obj.getField('date', true).substr(0, 4)
|
||||
}
|
||||
else
|
||||
{
|
||||
val = obj.getField(column.id.substring(20));
|
||||
else {
|
||||
var col = column.id.substring(20);
|
||||
|
||||
if (col == 'title') {
|
||||
val = obj.ref.getDisplayTitle();
|
||||
}
|
||||
else {
|
||||
val = obj.getField(col);
|
||||
}
|
||||
}
|
||||
|
||||
if(column.id == 'zotero-items-column-dateAdded' || column.id == 'zotero-items-column-dateModified') //this is not so much that we will use this format for date, but a simple template for later revisions.
|
||||
|
@ -776,14 +782,34 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
|
|||
// calls are relatively expensive
|
||||
var cache = [];
|
||||
|
||||
function columnSort(a,b) {
|
||||
// Get the display field for a row (which might be a placeholder title)
|
||||
function getField(row) {
|
||||
var field;
|
||||
var type = row.getType();
|
||||
if (columnField == 'title') {
|
||||
if (type == 8 || type == 10) { // 'letter' and 'interview' itemTypeIDs
|
||||
field = row.ref.getDisplayTitle();
|
||||
}
|
||||
else {
|
||||
field = row.getField(columnField, unformatted, true);
|
||||
}
|
||||
// Ignore some leading and trailing characters when sorting
|
||||
field = Zotero.Items.getSortTitle(field);
|
||||
}
|
||||
else {
|
||||
field = row.getField(columnField, unformatted, true);
|
||||
}
|
||||
return field;
|
||||
}
|
||||
|
||||
function rowSort(a,b) {
|
||||
var cmp, fieldA, fieldB;
|
||||
|
||||
var aItemID = a.ref.getID();
|
||||
var aItemID = a.ref.id;
|
||||
if (cache[aItemID]) {
|
||||
fieldA = cache[aItemID];
|
||||
}
|
||||
var bItemID = b.ref.getID();
|
||||
var bItemID = b.ref.id;
|
||||
if (cache[bItemID]) {
|
||||
fieldB = cache[bItemID];
|
||||
}
|
||||
|
@ -808,12 +834,12 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
|
|||
|
||||
default:
|
||||
if (fieldA == undefined) {
|
||||
fieldA = a.getField(columnField, unformatted, true);
|
||||
fieldA = getField(a);
|
||||
cache[aItemID] = fieldA;
|
||||
}
|
||||
|
||||
if (fieldB == undefined) {
|
||||
fieldB = b.getField(columnField, unformatted, true);
|
||||
fieldB = getField(b);
|
||||
cache[bItemID] = fieldB;
|
||||
}
|
||||
|
||||
|
@ -826,7 +852,6 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
|
|||
}
|
||||
}
|
||||
|
||||
//cmp = (fieldA > fieldB) ? -1 : (fieldA < fieldB) ? 1 : 0;
|
||||
cmp = collation.compareString(1, fieldB, fieldA);
|
||||
if (cmp) {
|
||||
return cmp;
|
||||
|
@ -875,12 +900,12 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
|
|||
|
||||
function doSort(a,b)
|
||||
{
|
||||
return columnSort(a,b);
|
||||
return rowSort(a,b);
|
||||
}
|
||||
|
||||
function reverseSort(a,b)
|
||||
{
|
||||
return columnSort(a,b) * -1;
|
||||
return rowSort(a,b) * -1;
|
||||
}
|
||||
|
||||
// Need to close all containers before sorting
|
||||
|
|
|
@ -92,6 +92,15 @@ pane.items.menu.generateReport.multiple = Generate Report from Selected Items...
|
|||
pane.items.menu.reindexItem = Reindex Item
|
||||
pane.items.menu.reindexItem.multiple = Reindex Items
|
||||
|
||||
pane.items.letter.oneParticipant = Letter to %S
|
||||
pane.items.letter.twoParticipants = Letter to %S and %S
|
||||
pane.items.letter.threeParticipants = Letter to %S, %S, and %S
|
||||
pane.items.letter.manyParticipants = Letter to %S et al.
|
||||
pane.items.interview.oneParticipant = Interview by %S
|
||||
pane.items.interview.twoParticipants = Interview by %S and %S
|
||||
pane.items.interview.threeParticipants = Interview by %S, %S, and %S
|
||||
pane.items.interview.manyParticipants = Interview by %S et al.
|
||||
|
||||
pane.item.selected.zero = No items selected
|
||||
pane.item.selected.multiple = %S items selected
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user