Update display title after item edit
This commit is contained in:
parent
f310c39162
commit
394aa8dded
|
@ -849,6 +849,105 @@ Zotero.Item.prototype.getDisplayTitle = function (includeAuthorAndDate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the generated display title from the loaded data
|
||||||
|
*/
|
||||||
|
Zotero.Item.prototype.updateDisplayTitle = function () {
|
||||||
|
var title = this.getField('title', false, true);
|
||||||
|
var itemTypeID = this.itemTypeID;
|
||||||
|
var itemTypeName = Zotero.ItemTypes.getName(itemTypeID);
|
||||||
|
|
||||||
|
if (title === "" && (itemTypeID == 8 || itemTypeID == 10)) { // 'letter' and 'interview' itemTypeIDs
|
||||||
|
var creatorsData = this.getCreators();
|
||||||
|
var authors = [];
|
||||||
|
var participants = [];
|
||||||
|
for (let i=0; i<creatorsData.length; i++) {
|
||||||
|
let creatorData = creatorsData[i];
|
||||||
|
let creatorTypeID = creatorsData[i].creatorTypeID;
|
||||||
|
if ((itemTypeID == 8 && creatorTypeID == 16) || // 'letter'
|
||||||
|
(itemTypeID == 10 && creatorTypeID == 7)) { // 'interview'
|
||||||
|
participants.push(creatorData);
|
||||||
|
}
|
||||||
|
else if ((itemTypeID == 8 && creatorTypeID == 1) || // 'letter'/'author'
|
||||||
|
(itemTypeID == 10 && creatorTypeID == 6)) { // 'interview'/'interviewee'
|
||||||
|
authors.push(creatorData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var strParts = [];
|
||||||
|
if (participants.length > 0) {
|
||||||
|
let names = [];
|
||||||
|
let max = Math.min(4, participants.length);
|
||||||
|
for (let i=0; i<max; i++) {
|
||||||
|
names.push(
|
||||||
|
participants[i].name !== undefined
|
||||||
|
? participants[i].name
|
||||||
|
: participants[i].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';
|
||||||
|
}
|
||||||
|
strParts.push(Zotero.getString('pane.items.' + itemTypeName + '.' + str, names));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
strParts.push(Zotero.ItemTypes.getLocalizedString(itemTypeID));
|
||||||
|
}
|
||||||
|
|
||||||
|
title = '[' + strParts.join('; ') + ']';
|
||||||
|
}
|
||||||
|
else if (itemTypeID == 17) { // 'case' itemTypeID
|
||||||
|
if (title) { // common law cases always have case names
|
||||||
|
var reporter = this.getField('reporter');
|
||||||
|
if (reporter) {
|
||||||
|
title = title + ' (' + reporter + ')';
|
||||||
|
} else {
|
||||||
|
var court = this.getField('court');
|
||||||
|
if (court) {
|
||||||
|
title = title + ' (' + court + ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { // civil law cases have only shortTitle as case name
|
||||||
|
var strParts = [];
|
||||||
|
var caseinfo = "";
|
||||||
|
|
||||||
|
var part = this.getField('court');
|
||||||
|
if (part) {
|
||||||
|
strParts.push(part);
|
||||||
|
}
|
||||||
|
|
||||||
|
part = Zotero.Date.multipartToSQL(this.getField('date', true, true));
|
||||||
|
if (part) {
|
||||||
|
strParts.push(part);
|
||||||
|
}
|
||||||
|
|
||||||
|
var creatorData = this.getCreator(0);
|
||||||
|
if (creatorData && creatorData.creatorTypeID === 1) { // author
|
||||||
|
strParts.push(creatorData.lastName);
|
||||||
|
}
|
||||||
|
|
||||||
|
title = '[' + strParts.join(', ') + ']';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this._displayTitle = title;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the number of creators for this item
|
* Returns the number of creators for this item
|
||||||
*/
|
*/
|
||||||
|
@ -1836,7 +1935,9 @@ Zotero.Item.prototype.setNote = function(text) {
|
||||||
this._hasNote = text !== '';
|
this._hasNote = text !== '';
|
||||||
this._noteText = text;
|
this._noteText = text;
|
||||||
this._noteTitle = Zotero.Notes.noteToTitle(text);
|
this._noteTitle = Zotero.Notes.noteToTitle(text);
|
||||||
|
if (this.isNote()) {
|
||||||
this._displayTitle = this._noteTitle;
|
this._displayTitle = this._noteTitle;
|
||||||
|
}
|
||||||
|
|
||||||
this._markFieldChange('note', oldText);
|
this._markFieldChange('note', oldText);
|
||||||
this._changed.note = true;
|
this._changed.note = true;
|
||||||
|
@ -4072,108 +4173,6 @@ Zotero.Item.prototype.toResponseJSON = function (options = {}) {
|
||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/*
|
|
||||||
* Load in the field data from the database
|
|
||||||
*/
|
|
||||||
Zotero.Item.prototype.loadDisplayTitle = Zotero.Promise.coroutine(function* (reload) {
|
|
||||||
if (this._displayTitle !== null && !reload) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var title = this.getField('title', false, true);
|
|
||||||
var itemTypeID = this.itemTypeID;
|
|
||||||
var itemTypeName = Zotero.ItemTypes.getName(itemTypeID);
|
|
||||||
|
|
||||||
if (title === "" && (itemTypeID == 8 || itemTypeID == 10)) { // 'letter' and 'interview' itemTypeIDs
|
|
||||||
var creatorsData = this.getCreators();
|
|
||||||
var authors = [];
|
|
||||||
var participants = [];
|
|
||||||
for (let i=0; i<creatorsData.length; i++) {
|
|
||||||
let creatorData = creatorsData[i];
|
|
||||||
let creatorTypeID = creatorsData[i].creatorTypeID;
|
|
||||||
if ((itemTypeID == 8 && creatorTypeID == 16) || // 'letter'
|
|
||||||
(itemTypeID == 10 && creatorTypeID == 7)) { // 'interview'
|
|
||||||
participants.push(creatorData);
|
|
||||||
}
|
|
||||||
else if ((itemTypeID == 8 && creatorTypeID == 1) || // 'letter'/'author'
|
|
||||||
(itemTypeID == 10 && creatorTypeID == 6)) { // 'interview'/'interviewee'
|
|
||||||
authors.push(creatorData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var strParts = [];
|
|
||||||
if (participants.length > 0) {
|
|
||||||
let names = [];
|
|
||||||
let max = Math.min(4, participants.length);
|
|
||||||
for (let i=0; i<max; i++) {
|
|
||||||
names.push(
|
|
||||||
participants[i].name !== undefined
|
|
||||||
? participants[i].name
|
|
||||||
: participants[i].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';
|
|
||||||
}
|
|
||||||
strParts.push(Zotero.getString('pane.items.' + itemTypeName + '.' + str, names));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
strParts.push(Zotero.ItemTypes.getLocalizedString(itemTypeID));
|
|
||||||
}
|
|
||||||
|
|
||||||
title = '[' + strParts.join('; ') + ']';
|
|
||||||
}
|
|
||||||
else if (itemTypeID == 17) { // 'case' itemTypeID
|
|
||||||
if (title) { // common law cases always have case names
|
|
||||||
var reporter = this.getField('reporter');
|
|
||||||
if (reporter) {
|
|
||||||
title = title + ' (' + reporter + ')';
|
|
||||||
} else {
|
|
||||||
var court = this.getField('court');
|
|
||||||
if (court) {
|
|
||||||
title = title + ' (' + court + ')';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else { // civil law cases have only shortTitle as case name
|
|
||||||
var strParts = [];
|
|
||||||
var caseinfo = "";
|
|
||||||
|
|
||||||
var part = this.getField('court');
|
|
||||||
if (part) {
|
|
||||||
strParts.push(part);
|
|
||||||
}
|
|
||||||
|
|
||||||
part = Zotero.Date.multipartToSQL(this.getField('date', true, true));
|
|
||||||
if (part) {
|
|
||||||
strParts.push(part);
|
|
||||||
}
|
|
||||||
|
|
||||||
var creatorData = this.getCreator(0);
|
|
||||||
if (creatorData && creatorData.creatorTypeID === 1) { // author
|
|
||||||
strParts.push(creatorData.lastName);
|
|
||||||
}
|
|
||||||
|
|
||||||
title = '[' + strParts.join(', ') + ']';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this._displayTitle = title;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an item in the specified library equivalent to this item
|
* Return an item in the specified library equivalent to this item
|
||||||
|
|
|
@ -287,7 +287,6 @@ Zotero.Items = function() {
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// If 'title' is one of the fields, load in display titles (note titles, letter titles...)
|
|
||||||
var titleFieldID = Zotero.ItemFields.getID('title');
|
var titleFieldID = Zotero.ItemFields.getID('title');
|
||||||
|
|
||||||
// Note titles
|
// Note titles
|
||||||
|
@ -326,7 +325,7 @@ Zotero.Items = function() {
|
||||||
item._clearChanged('itemData');
|
item._clearChanged('itemData');
|
||||||
|
|
||||||
// Display titles
|
// Display titles
|
||||||
yield item.loadDisplayTitle()
|
item.updateDisplayTitle()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,17 @@ describe("Zotero.ItemTreeView", function() {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("#getCellText()", function () {
|
||||||
|
it("should return new value after edit", function* () {
|
||||||
|
var str = Zotero.Utilities.randomString();
|
||||||
|
var item = yield createDataObject('item', { title: str });
|
||||||
|
var row = itemsView.getRowIndexByID(item.id);
|
||||||
|
assert.equal(itemsView.getCellText(row, { id: 'zotero-items-column-title' }), str);
|
||||||
|
yield modifyDataObject(item);
|
||||||
|
assert.notEqual(itemsView.getCellText(row, { id: 'zotero-items-column-title' }), str);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("#notify()", function () {
|
describe("#notify()", function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sinon.spy(win.ZoteroPane, "itemSelected");
|
sinon.spy(win.ZoteroPane, "itemSelected");
|
||||||
|
|
|
@ -64,13 +64,13 @@ function saveItemsThroughTranslator(translatorType, items) {
|
||||||
* Convert an array of items to an object in which they are indexed by
|
* Convert an array of items to an object in which they are indexed by
|
||||||
* their display titles
|
* their display titles
|
||||||
*/
|
*/
|
||||||
var itemsArrayToObject = Zotero.Promise.coroutine(function* itemsArrayToObject(items) {
|
function itemsArrayToObject(items) {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
for (let item of items) {
|
for (let item of items) {
|
||||||
obj[yield item.loadDisplayTitle(true)] = item;
|
obj[item.getDisplayTitle()] = item;
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
});
|
}
|
||||||
|
|
||||||
const TEST_TAGS = [
|
const TEST_TAGS = [
|
||||||
"manual tag as string",
|
"manual tag as string",
|
||||||
|
@ -223,7 +223,7 @@ describe("Zotero.Translate", function() {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
let newItems = yield itemsArrayToObject(yield saveItemsThroughTranslator("import", myItems));
|
let newItems = itemsArrayToObject(yield saveItemsThroughTranslator("import", myItems));
|
||||||
let noteIDs = newItems["Test Item"].getNotes();
|
let noteIDs = newItems["Test Item"].getNotes();
|
||||||
let note1 = yield Zotero.Items.getAsync(noteIDs[0]);
|
let note1 = yield Zotero.Items.getAsync(noteIDs[0]);
|
||||||
assert.equal(Zotero.ItemTypes.getName(note1.itemTypeID), "note");
|
assert.equal(Zotero.ItemTypes.getName(note1.itemTypeID), "note");
|
||||||
|
@ -261,7 +261,7 @@ describe("Zotero.Translate", function() {
|
||||||
'}'));
|
'}'));
|
||||||
let newItems = yield translate.translate();
|
let newItems = yield translate.translate();
|
||||||
assert.equal(newItems.length, 3);
|
assert.equal(newItems.length, 3);
|
||||||
newItems = yield itemsArrayToObject(newItems);
|
newItems = itemsArrayToObject(newItems);
|
||||||
assert.equal(newItems["Not in Collection"].getCollections().length, 0);
|
assert.equal(newItems["Not in Collection"].getCollections().length, 0);
|
||||||
|
|
||||||
let parentCollection = newItems["In Parent Collection"].getCollections();
|
let parentCollection = newItems["In Parent Collection"].getCollections();
|
||||||
|
@ -313,7 +313,7 @@ describe("Zotero.Translate", function() {
|
||||||
"attachments":childAttachments
|
"attachments":childAttachments
|
||||||
});
|
});
|
||||||
|
|
||||||
let newItems = yield itemsArrayToObject(yield saveItemsThroughTranslator("import", myItems));
|
let newItems = itemsArrayToObject(yield saveItemsThroughTranslator("import", myItems));
|
||||||
let containedAttachments = yield Zotero.Items.getAsync(newItems["Container Item"].getAttachments());
|
let containedAttachments = yield Zotero.Items.getAsync(newItems["Container Item"].getAttachments());
|
||||||
assert.equal(containedAttachments.length, 3);
|
assert.equal(containedAttachments.length, 3);
|
||||||
|
|
||||||
|
@ -447,7 +447,7 @@ describe("Zotero.Translate", function() {
|
||||||
|
|
||||||
let newItems = yield saveItemsThroughTranslator("web", myItems);
|
let newItems = yield saveItemsThroughTranslator("web", myItems);
|
||||||
assert.equal(newItems.length, 1);
|
assert.equal(newItems.length, 1);
|
||||||
let containedAttachments = yield itemsArrayToObject(yield Zotero.Items.getAsync(newItems[0].getAttachments()));
|
let containedAttachments = itemsArrayToObject(yield Zotero.Items.getAsync(newItems[0].getAttachments()));
|
||||||
|
|
||||||
let link = containedAttachments["Link to zotero.org"];
|
let link = containedAttachments["Link to zotero.org"];
|
||||||
assert.equal(link.getField("url"), "http://www.zotero.org/");
|
assert.equal(link.getField("url"), "http://www.zotero.org/");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user