www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 394aa8ddedd007885744d93a082b832093b1f4ab
parent f310c391623af6d94e8b0e8ddf3cf2e921b48fcb
Author: Dan Stillman <dstillman@zotero.org>
Date:   Fri, 11 Mar 2016 04:50:55 -0500

Update display title after item edit

Diffstat:
Mchrome/content/zotero/xpcom/data/item.js | 205+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mchrome/content/zotero/xpcom/data/items.js | 3+--
Mtest/tests/itemTreeViewTest.js | 11+++++++++++
Mtest/tests/translateTest.js | 14+++++++-------
4 files changed, 121 insertions(+), 112 deletions(-)

diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js @@ -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 */ @@ -1836,7 +1935,9 @@ Zotero.Item.prototype.setNote = function(text) { this._hasNote = text !== ''; this._noteText = text; this._noteTitle = Zotero.Notes.noteToTitle(text); - this._displayTitle = this._noteTitle; + if (this.isNote()) { + this._displayTitle = this._noteTitle; + } this._markFieldChange('note', oldText); 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 diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js @@ -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'); // Note titles @@ -326,7 +325,7 @@ Zotero.Items = function() { item._clearChanged('itemData'); // Display titles - yield item.loadDisplayTitle() + item.updateDisplayTitle() } }); diff --git a/test/tests/itemTreeViewTest.js b/test/tests/itemTreeViewTest.js @@ -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 () { beforeEach(function () { sinon.spy(win.ZoteroPane, "itemSelected"); diff --git a/test/tests/translateTest.js b/test/tests/translateTest.js @@ -64,13 +64,13 @@ function saveItemsThroughTranslator(translatorType, items) { * Convert an array of items to an object in which they are indexed by * their display titles */ -var itemsArrayToObject = Zotero.Promise.coroutine(function* itemsArrayToObject(items) { +function itemsArrayToObject(items) { var obj = {}; for (let item of items) { - obj[yield item.loadDisplayTitle(true)] = item; + obj[item.getDisplayTitle()] = item; } return obj; -}); +} const TEST_TAGS = [ "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 note1 = yield Zotero.Items.getAsync(noteIDs[0]); assert.equal(Zotero.ItemTypes.getName(note1.itemTypeID), "note"); @@ -261,7 +261,7 @@ describe("Zotero.Translate", function() { '}')); let newItems = yield translate.translate(); assert.equal(newItems.length, 3); - newItems = yield itemsArrayToObject(newItems); + newItems = itemsArrayToObject(newItems); assert.equal(newItems["Not in Collection"].getCollections().length, 0); let parentCollection = newItems["In Parent Collection"].getCollections(); @@ -313,7 +313,7 @@ describe("Zotero.Translate", function() { "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()); assert.equal(containedAttachments.length, 3); @@ -447,7 +447,7 @@ describe("Zotero.Translate", function() { let newItems = yield saveItemsThroughTranslator("web", myItems); 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"]; assert.equal(link.getField("url"), "http://www.zotero.org/");