Clear shortTitle when moving between book and bookSection when title/bookTitle is automatically transferred
This commit is contained in:
parent
532ad6b30c
commit
4ff0a51694
|
@ -951,19 +951,40 @@
|
||||||
|
|
||||||
var fieldsToDelete = this.item.getFieldsNotInType(itemTypeID, true);
|
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
|
// Generate list of localized field names for display in pop-up
|
||||||
if (fieldsToDelete) {
|
if (fieldsToDelete) {
|
||||||
// Ignore warning for bookTitle when going from bookSection to book
|
// Ignore warning for bookTitle when going from bookSection to book
|
||||||
// if there's not also a title, since the book title is transferred
|
// if there's not also a title, since the book title is transferred
|
||||||
// to title automatically in Zotero.Item.setType()
|
// 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) {
|
if (this.item.itemTypeID == bookSectionTypeID && itemTypeID == bookTypeID) {
|
||||||
var titleFieldID = Zotero.ItemFields.getID('title');
|
var titleFieldID = Zotero.ItemFields.getID('title');
|
||||||
var bookTitleFieldID = Zotero.ItemFields.getID('bookTitle');
|
var bookTitleFieldID = Zotero.ItemFields.getID('bookTitle');
|
||||||
|
var shortTitleFieldID = Zotero.ItemFields.getID('shortTitle');
|
||||||
if (this.item.getField(bookTitleFieldID) && !this.item.getField(titleFieldID)) {
|
if (this.item.getField(bookTitleFieldID) && !this.item.getField(titleFieldID)) {
|
||||||
var index = fieldsToDelete.indexOf(bookTitleFieldID);
|
var index = fieldsToDelete.indexOf(bookTitleFieldID);
|
||||||
fieldsToDelete.splice(index, 1);
|
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);
|
var obsoleteFields = this.getFieldsNotInType(itemTypeID);
|
||||||
if (obsoleteFields) {
|
if (obsoleteFields) {
|
||||||
// Move bookTitle to title when going from bookSection to book
|
// Move bookTitle to title and clear short title when going from
|
||||||
// if there's not also a title
|
// bookSection to book if there's not also a title
|
||||||
if (this._itemTypeID == bookSectionTypeID && itemTypeID == bookTypeID) {
|
if (this._itemTypeID == bookSectionTypeID && itemTypeID == bookTypeID) {
|
||||||
var titleFieldID = Zotero.ItemFields.getID('title');
|
var titleFieldID = Zotero.ItemFields.getID('title');
|
||||||
var bookTitleFieldID = Zotero.ItemFields.getID('bookTitle');
|
var bookTitleFieldID = Zotero.ItemFields.getID('bookTitle');
|
||||||
|
var shortTitleFieldID = Zotero.ItemFields.getID('shortTitle');
|
||||||
if (this._itemData[bookTitleFieldID] && !this._itemData[titleFieldID]) {
|
if (this._itemData[bookTitleFieldID] && !this._itemData[titleFieldID]) {
|
||||||
copiedFields.push([titleFieldID, this._itemData[bookTitleFieldID]]);
|
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) {
|
if (this._itemTypeID == bookTypeID && itemTypeID == bookSectionTypeID) {
|
||||||
var titleFieldID = Zotero.ItemFields.getID('title');
|
var titleFieldID = Zotero.ItemFields.getID('title');
|
||||||
var bookTitleFieldID = Zotero.ItemFields.getID('bookTitle');
|
var bookTitleFieldID = Zotero.ItemFields.getID('bookTitle');
|
||||||
|
var shortTitleFieldID = Zotero.ItemFields.getID('shortTitle');
|
||||||
if (this._itemData[titleFieldID]) {
|
if (this._itemData[titleFieldID]) {
|
||||||
copiedFields.push([bookTitleFieldID, this._itemData[titleFieldID]]);
|
copiedFields.push([bookTitleFieldID, this._itemData[titleFieldID]]);
|
||||||
this.setField(titleFieldID, false);
|
this.setField(titleFieldID, false);
|
||||||
}
|
}
|
||||||
|
if (this._itemData[shortTitleFieldID]) {
|
||||||
|
this.setField(shortTitleFieldID, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var fieldID in this._itemData) {
|
for (var fieldID in this._itemData) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user