Clear shortTitle when moving between book and bookSection when title/bookTitle is automatically transferred
This commit is contained in:
parent
532ad6b30c
commit
4ff0a51694
2 changed files with 34 additions and 5 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue