mirror of
https://github.com/zotero/zotero.git
synced 2026-10-08 03:08:19 +00:00
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
This commit is contained in:
parent
f28cb22480
commit
532ad6b30c
2 changed files with 39 additions and 1 deletions
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue