Unsaved creators are no longer saved (e.g. on creator type change) if they don't have a firstName or a lastName
(Also fixes bug from r379 where changing creator type on a blank unsaved creator would actually insert "(first)" and "(last)") Localized '(first)' and '(last)' Refs #179, adding a new creator then clicking an existing creator makes the creator field disappear
This commit is contained in:
parent
b35ba91c15
commit
3a18dcb70f
3 changed files with 56 additions and 12 deletions
|
@ -97,6 +97,7 @@ ScholarItemPane = new function()
|
||||||
|
|
||||||
function loadPane(index)
|
function loadPane(index)
|
||||||
{
|
{
|
||||||
|
//Scholar.debug('Loading item pane ' + index);
|
||||||
if(_loaded[index])
|
if(_loaded[index])
|
||||||
return;
|
return;
|
||||||
_loaded[index] = true;
|
_loaded[index] = true;
|
||||||
|
@ -292,9 +293,9 @@ ScholarItemPane = new function()
|
||||||
function addCreatorRow(firstName, lastName, typeID, unsaved, defaultRow)
|
function addCreatorRow(firstName, lastName, typeID, unsaved, defaultRow)
|
||||||
{
|
{
|
||||||
if(!firstName)
|
if(!firstName)
|
||||||
firstName = "(first)";
|
firstName = "(" + Scholar.getString('pane.item.defaultFirstName') + ")";
|
||||||
if(!lastName)
|
if(!lastName)
|
||||||
lastName = "(last)";
|
lastName = "(" + Scholar.getString('pane.item.defaultLastName') + ")";
|
||||||
var label = document.createElement("label");
|
var label = document.createElement("label");
|
||||||
label.setAttribute("value",Scholar.getString('creatorTypes.'+Scholar.CreatorTypes.getName(typeID))+":");
|
label.setAttribute("value",Scholar.getString('creatorTypes.'+Scholar.CreatorTypes.getName(typeID))+":");
|
||||||
label.setAttribute("popup","creatorTypeMenu");
|
label.setAttribute("popup","creatorTypeMenu");
|
||||||
|
@ -380,6 +381,7 @@ ScholarItemPane = new function()
|
||||||
|
|
||||||
function showEditor(elem)
|
function showEditor(elem)
|
||||||
{
|
{
|
||||||
|
//Scholar.debug('Showing editor');
|
||||||
var fieldName = elem.getAttribute('fieldname');
|
var fieldName = elem.getAttribute('fieldname');
|
||||||
var value = '';
|
var value = '';
|
||||||
var creatorFields = fieldName.split('-');
|
var creatorFields = fieldName.split('-');
|
||||||
|
@ -410,6 +412,7 @@ ScholarItemPane = new function()
|
||||||
|
|
||||||
function hideEditor(t, saveChanges)
|
function hideEditor(t, saveChanges)
|
||||||
{
|
{
|
||||||
|
//Scholar.debug('Hiding editor');
|
||||||
var textbox = t.parentNode.parentNode;
|
var textbox = t.parentNode.parentNode;
|
||||||
var fieldName = textbox.getAttribute('fieldname');
|
var fieldName = textbox.getAttribute('fieldname');
|
||||||
var value = t.value;
|
var value = t.value;
|
||||||
|
@ -418,13 +421,29 @@ ScholarItemPane = new function()
|
||||||
var creatorFields = fieldName.split('-');
|
var creatorFields = fieldName.split('-');
|
||||||
if(creatorFields[0] == 'creator')
|
if(creatorFields[0] == 'creator')
|
||||||
{
|
{
|
||||||
if(saveChanges)
|
if (saveChanges){
|
||||||
modifyCreator(creatorFields[1],creatorFields[2],value);
|
var otherFields =
|
||||||
|
this.getCreatorFields(textbox.parentNode.parentNode.parentNode);
|
||||||
|
modifyCreator(creatorFields[1], creatorFields[2], value, otherFields);
|
||||||
|
}
|
||||||
|
|
||||||
var val = _itemBeingEdited.getCreator(creatorFields[1])[creatorFields[2]];
|
var val = _itemBeingEdited.getCreator(creatorFields[1])[creatorFields[2]];
|
||||||
|
|
||||||
|
if (!val){
|
||||||
|
// Reset to '(first)' or '(last)'
|
||||||
|
if (creatorFields[2]=='lastName'){
|
||||||
|
val = "(" + Scholar.getString('pane.item.defaultLastName') + ")";
|
||||||
|
}
|
||||||
|
else if (creatorFields[2]=='firstName'){
|
||||||
|
val = "(" + Scholar.getString('pane.item.defaultFirstName') + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add trailing comma
|
||||||
if (creatorFields[2]=='lastName'){
|
if (creatorFields[2]=='lastName'){
|
||||||
val += ',';
|
val += ',';
|
||||||
}
|
}
|
||||||
|
|
||||||
elem = createValueElement(val, fieldName);
|
elem = createValueElement(val, fieldName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -437,7 +456,6 @@ ScholarItemPane = new function()
|
||||||
|
|
||||||
var box = textbox.parentNode;
|
var box = textbox.parentNode;
|
||||||
box.replaceChild(elem,textbox);
|
box.replaceChild(elem,textbox);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function modifyField(field, value)
|
function modifyField(field, value)
|
||||||
|
@ -447,6 +465,7 @@ ScholarItemPane = new function()
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCreatorFields(row){
|
function getCreatorFields(row){
|
||||||
|
var type = row.getElementsByTagName('label')[0].getAttribute('value');
|
||||||
var label1 = row.getElementsByTagName('hbox')[0].firstChild.firstChild;
|
var label1 = row.getElementsByTagName('hbox')[0].firstChild.firstChild;
|
||||||
var label2 = label1.nextSibling;
|
var label2 = label1.nextSibling;
|
||||||
|
|
||||||
|
@ -457,6 +476,7 @@ ScholarItemPane = new function()
|
||||||
.substr(0, label1.firstChild.nodeValue.length-1): label1.value,
|
.substr(0, label1.firstChild.nodeValue.length-1): label1.value,
|
||||||
firstName: label2.firstChild ? label2.firstChild.nodeValue
|
firstName: label2.firstChild ? label2.firstChild.nodeValue
|
||||||
: label2.value,
|
: label2.value,
|
||||||
|
typeID: Scholar.CreatorTypes.getID(type.substr(0, type.length-1).toLowerCase()),
|
||||||
isInstitution: null // placeholder
|
isInstitution: null // placeholder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,21 +486,40 @@ ScholarItemPane = new function()
|
||||||
if (otherFields){
|
if (otherFields){
|
||||||
var firstName = otherFields.firstName;
|
var firstName = otherFields.firstName;
|
||||||
var lastName = otherFields.lastName;
|
var lastName = otherFields.lastName;
|
||||||
|
var typeID = otherFields.typeID;
|
||||||
// var isInstitution = otherFields.isInstitution;
|
// var isInstitution = otherFields.isInstitution;
|
||||||
|
|
||||||
|
// Ignore '(first)' and '(last)'
|
||||||
|
if (firstName == "(" + Scholar.getString('pane.item.defaultFirstName') + ")"){
|
||||||
|
firstName = '';
|
||||||
|
}
|
||||||
|
if (lastName == "(" + Scholar.getString('pane.item.defaultLastName') + ")"){
|
||||||
|
lastName = '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var creator = _itemBeingEdited.getCreator(index);
|
var creator = _itemBeingEdited.getCreator(index);
|
||||||
var firstName = creator['firstName'];
|
var firstName = creator['firstName'];
|
||||||
var lastName = creator['lastName'];
|
var lastName = creator['lastName'];
|
||||||
var typeID = creator['creatorTypeID'];
|
var typeID = creator['creatorTypeID'];
|
||||||
|
// var isInstitution = creator['isInstitution'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(field == 'firstName')
|
if (!_itemBeingEdited.hasCreatorAt(index) && !firstName && !lastName){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (field){
|
||||||
|
case 'firstName':
|
||||||
firstName = value;
|
firstName = value;
|
||||||
else if(field == 'lastName')
|
break;
|
||||||
|
case 'lastName':
|
||||||
lastName = value;
|
lastName = value;
|
||||||
else if(field == 'typeID')
|
break;
|
||||||
|
case 'typeID':
|
||||||
typeID = value;
|
typeID = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
_itemBeingEdited.setCreator(index, firstName, lastName, typeID);
|
_itemBeingEdited.setCreator(index, firstName, lastName, typeID);
|
||||||
_itemBeingEdited.save();
|
_itemBeingEdited.save();
|
||||||
|
|
|
@ -29,8 +29,11 @@
|
||||||
<popupset>
|
<popupset>
|
||||||
<popup id="creatorTypeMenu" position="after_start"
|
<popup id="creatorTypeMenu" position="after_start"
|
||||||
oncommand="var otherFields = ScholarItemPane.getCreatorFields(document.popupNode.parentNode);
|
oncommand="var otherFields = ScholarItemPane.getCreatorFields(document.popupNode.parentNode);
|
||||||
|
var typeID = event.explicitOriginalTarget.getAttribute('typeid');
|
||||||
|
document.popupNode.setAttribute('value',
|
||||||
|
Scholar.getString('creatorTypes.' + Scholar.CreatorTypes.getName(typeID)) + ':');
|
||||||
ScholarItemPane.modifyCreator(document.popupNode.getAttribute('fieldname').split('-')[1],
|
ScholarItemPane.modifyCreator(document.popupNode.getAttribute('fieldname').split('-')[1],
|
||||||
'typeID', event.explicitOriginalTarget.getAttribute('typeid'), otherFields)"/>
|
'typeID', typeID, otherFields)"/>
|
||||||
</popupset>
|
</popupset>
|
||||||
<hbox align="center">
|
<hbox align="center">
|
||||||
<menulist id="editpane-type-menu" oncommand="ScholarItemPane.changeTypeTo(this.value)" flex="1">
|
<menulist id="editpane-type-menu" oncommand="ScholarItemPane.changeTypeTo(this.value)" flex="1">
|
||||||
|
|
|
@ -19,6 +19,8 @@ pane.item.selected.zero = No items selected
|
||||||
pane.item.selected.multiple = %1 items selected
|
pane.item.selected.multiple = %1 items selected
|
||||||
|
|
||||||
pane.item.changeType = Are you sure you want to change the item type? Certain fields may be lost.
|
pane.item.changeType = Are you sure you want to change the item type? Certain fields may be lost.
|
||||||
|
pane.item.defaultFirstName = first
|
||||||
|
pane.item.defaultLastName = last
|
||||||
pane.item.notes.untitled = Untitled Note
|
pane.item.notes.untitled = Untitled Note
|
||||||
pane.item.notes.delete.confirm = Are you sure you want to delete this note?
|
pane.item.notes.delete.confirm = Are you sure you want to delete this note?
|
||||||
pane.item.notes.count.singular = %1 note
|
pane.item.notes.count.singular = %1 note
|
||||||
|
|
Loading…
Reference in a new issue