commit 4ff0a5169495d76a4f4a7b06947ba52e602ccfc6
parent 532ad6b30c984802132aa67ed39817ff8d3fea12
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 22 Dec 2009 08:21:18 +0000
Clear shortTitle when moving between book and bookSection when title/bookTitle is automatically transferred
Diffstat:
2 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/chrome/content/zotero/bindings/itembox.xml b/chrome/content/zotero/bindings/itembox.xml
@@ -951,19 +951,40 @@
var fieldsToDelete = this.item.getFieldsNotInType(itemTypeID, true);
+ // Special cases handled below
+ var bookTypeID = Zotero.ItemTypes.getID('book');
+ var bookSectionTypeID = Zotero.ItemTypes.getID('bookSection');
+
+ // Add warning for shortTitle when moving from book to bookSection
+ // when title will be transferred
+ if (this.item.itemTypeID == bookTypeID && itemTypeID == bookSectionTypeID) {
+ var titleFieldID = Zotero.ItemFields.getID('title');
+ var bookTitleFieldID = Zotero.ItemFields.getID('bookTitle');
+ var shortTitleFieldID = Zotero.ItemFields.getID('shortTitle');
+ if (this.item.getField(titleFieldID) && this.item.getField(shortTitleFieldID)) {
+ if (!fieldsToDelete) {
+ fieldsToDelete = [];
+ }
+ fieldsToDelete.push(shortTitleFieldID);
+ }
+ }
+
// 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');
+ var shortTitleFieldID = Zotero.ItemFields.getID('shortTitle');
if (this.item.getField(bookTitleFieldID) && !this.item.getField(titleFieldID)) {
var index = fieldsToDelete.indexOf(bookTitleFieldID);
fieldsToDelete.splice(index, 1);
+ // But warn for short title, which will be removed
+ if (this.item.getField(shortTitleFieldID)) {
+ fieldsToDelete.push(shortTitleFieldID);
+ }
}
}
diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js
@@ -423,13 +423,17 @@ Zotero.Item.prototype.setType = function(itemTypeID, loadIn) {
var obsoleteFields = this.getFieldsNotInType(itemTypeID);
if (obsoleteFields) {
- // Move bookTitle to title when going from bookSection to book
- // if there's not also a title
+ // Move bookTitle to title and clear short 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');
+ var shortTitleFieldID = Zotero.ItemFields.getID('shortTitle');
if (this._itemData[bookTitleFieldID] && !this._itemData[titleFieldID]) {
copiedFields.push([titleFieldID, this._itemData[bookTitleFieldID]]);
+ if (this._itemData[shortTitleFieldID]) {
+ this.setField(shortTitleFieldID, false);
+ }
}
}
@@ -460,14 +464,18 @@ Zotero.Item.prototype.setType = function(itemTypeID, loadIn) {
}
}
- // Move title to bookTitle when going from book to bookSection
+ // Move title to bookTitle and clear shortTitle when going from book to bookSection
if (this._itemTypeID == bookTypeID && itemTypeID == bookSectionTypeID) {
var titleFieldID = Zotero.ItemFields.getID('title');
var bookTitleFieldID = Zotero.ItemFields.getID('bookTitle');
+ var shortTitleFieldID = Zotero.ItemFields.getID('shortTitle');
if (this._itemData[titleFieldID]) {
copiedFields.push([bookTitleFieldID, this._itemData[titleFieldID]]);
this.setField(titleFieldID, false);
}
+ if (this._itemData[shortTitleFieldID]) {
+ this.setField(shortTitleFieldID, false);
+ }
}
for (var fieldID in this._itemData) {