www

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

commit 532ad6b30c984802132aa67ed39817ff8d3fea12
parent f28cb224802f72ede5fc2afe24e062fc53827eaa
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 22 Dec 2009 07:49:33 +0000

Move title to bookTitle when changing item type from book to bookSection, and move bookTitle to title when going from bookSection to book if there's not also a title

http://forums.zotero.org/discussion/78/books-and-book-sections-avoiding-input-of-duplicate-info/#Item_21


Diffstat:
Mchrome/content/zotero/bindings/itembox.xml | 16+++++++++++++++-
Mchrome/content/zotero/xpcom/data/item.js | 24++++++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/chrome/content/zotero/bindings/itembox.xml b/chrome/content/zotero/bindings/itembox.xml @@ -953,6 +953,20 @@ // Generate list of localized field names for display in pop-up if (fieldsToDelete) { + // Ignore warning for bookTitle when going from bookSection to book + // if there's not also a title, since the book title is transferred + // to title automatically in Zotero.Item.setType() + var bookTypeID = Zotero.ItemTypes.getID('book'); + var bookSectionTypeID = Zotero.ItemTypes.getID('bookSection'); + if (this.item.itemTypeID == bookSectionTypeID && itemTypeID == bookTypeID) { + var titleFieldID = Zotero.ItemFields.getID('title'); + var bookTitleFieldID = Zotero.ItemFields.getID('bookTitle'); + if (this.item.getField(bookTitleFieldID) && !this.item.getField(titleFieldID)) { + var index = fieldsToDelete.indexOf(bookTitleFieldID); + fieldsToDelete.splice(index, 1); + } + } + var fieldNames = ""; for (var i=0; i<fieldsToDelete.length; i++) { fieldNames += "\n - " + @@ -963,7 +977,7 @@ .getService(Components.interfaces.nsIPromptService); } - if (!fieldsToDelete || + if (!fieldsToDelete || fieldsToDelete.length == 0 || promptService.confirm(null, Zotero.getString('pane.item.changeType.title'), Zotero.getString('pane.item.changeType.text') + "\n" + fieldNames)) { diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js @@ -417,8 +417,22 @@ Zotero.Item.prototype.setType = function(itemTypeID, loadIn) { var copiedFields = []; + // Special cases handled below + var bookTypeID = Zotero.ItemTypes.getID('book'); + var bookSectionTypeID = Zotero.ItemTypes.getID('bookSection'); + var obsoleteFields = this.getFieldsNotInType(itemTypeID); if (obsoleteFields) { + // Move bookTitle to title when going from bookSection to book + // if there's not also a title + if (this._itemTypeID == bookSectionTypeID && itemTypeID == bookTypeID) { + var titleFieldID = Zotero.ItemFields.getID('title'); + var bookTitleFieldID = Zotero.ItemFields.getID('bookTitle'); + if (this._itemData[bookTitleFieldID] && !this._itemData[titleFieldID]) { + copiedFields.push([titleFieldID, this._itemData[bookTitleFieldID]]); + } + } + for each(var oldFieldID in obsoleteFields) { // Try to get a base type for this field var baseFieldID = @@ -446,6 +460,16 @@ Zotero.Item.prototype.setType = function(itemTypeID, loadIn) { } } + // Move title to bookTitle when going from book to bookSection + if (this._itemTypeID == bookTypeID && itemTypeID == bookSectionTypeID) { + var titleFieldID = Zotero.ItemFields.getID('title'); + var bookTitleFieldID = Zotero.ItemFields.getID('bookTitle'); + if (this._itemData[titleFieldID]) { + copiedFields.push([bookTitleFieldID, this._itemData[titleFieldID]]); + this.setField(titleFieldID, false); + } + } + for (var fieldID in this._itemData) { if (this._itemData[fieldID] && (!obsoleteFields || obsoleteFields.indexOf(fieldID) == -1)) {