Disable creator add button on previous row when adding a new row (since bad things can happen if we don't) and undo on reverse

This commit is contained in:
Dan Stillman 2006-08-22 19:52:15 +00:00
parent 57f4e43507
commit 03d8097527

View file

@ -39,6 +39,7 @@ ScholarItemPane = new function()
this.changeTypeTo = changeTypeTo; this.changeTypeTo = changeTypeTo;
this.onOpenURLClick = onOpenURLClick; this.onOpenURLClick = onOpenURLClick;
this.addCreatorRow = addCreatorRow; this.addCreatorRow = addCreatorRow;
this.disableButton = disableButton;
this.removeCreator = removeCreator; this.removeCreator = removeCreator;
this.showEditor = showEditor; this.showEditor = showEditor;
this.hideEditor = hideEditor; this.hideEditor = hideEditor;
@ -153,12 +154,14 @@ ScholarItemPane = new function()
} }
else else
{ {
// Add default row
addCreatorRow('', '', 1, true, true); addCreatorRow('', '', 1, true, true);
} }
} }
// Notes pane
else if(index == 1) else if(index == 1)
{ {
//NOTES:
while(_notesList.hasChildNodes()) while(_notesList.hasChildNodes())
_notesList.removeChild(_notesList.firstChild); _notesList.removeChild(_notesList.firstChild);
@ -196,9 +199,10 @@ ScholarItemPane = new function()
_updateNoteCount(); _updateNoteCount();
} }
// Attachments pane
else if(index == 2) else if(index == 2)
{ {
//ATTACHMENTS
while(_attachmentsList.hasChildNodes()) while(_attachmentsList.hasChildNodes())
_attachmentsList.removeChild(_attachmentsList.firstChild); _attachmentsList.removeChild(_attachmentsList.firstChild);
@ -254,14 +258,16 @@ ScholarItemPane = new function()
_updateAttachmentCount(); _updateAttachmentCount();
} }
// Tags pane
else if(index == 3) else if(index == 3)
{ {
//TAGS:
_tagsBox.item = _itemBeingEdited; _tagsBox.item = _itemBeingEdited;
} }
// Related pane
else if(index == 4) else if(index == 4)
{ {
//RELATED
_relatedBox.item = _itemBeingEdited; _relatedBox.item = _itemBeingEdited;
} }
} }
@ -294,6 +300,12 @@ ScholarItemPane = new function()
function addCreatorRow(firstName, lastName, typeID, unsaved, defaultRow) function addCreatorRow(firstName, lastName, typeID, unsaved, defaultRow)
{ {
// Disable the "+" button on previous rows
var elems = _dynamicFields.getElementsByAttribute('value', '+');
if (elems.length){
ScholarItemPane.disableButton(elems[elems.length-1]);
}
if(!firstName) if(!firstName)
firstName = "(" + Scholar.getString('pane.item.defaultFirstName') + ")"; firstName = "(" + Scholar.getString('pane.item.defaultFirstName') + ")";
if(!lastName) if(!lastName)
@ -304,7 +316,7 @@ ScholarItemPane = new function()
label.setAttribute("fieldname",'creator-'+_creatorCount+'-typeID'); label.setAttribute("fieldname",'creator-'+_creatorCount+'-typeID');
label.className = 'clicky'; label.className = 'clicky';
// getCreatorFields() needs to be adjusted if the DOM changes // getCreatorFields() needs to be adjusted if this DOM structure changes
var row = document.createElement("hbox"); var row = document.createElement("hbox");
var firstlast = document.createElement("hbox"); var firstlast = document.createElement("hbox");
@ -315,9 +327,9 @@ ScholarItemPane = new function()
var removeButton = document.createElement('label'); var removeButton = document.createElement('label');
removeButton.setAttribute("value","-"); removeButton.setAttribute("value","-");
// If default first row, don't let user remove it
if (defaultRow){ if (defaultRow){
removeButton.setAttribute("disabled",true); disableButton(removeButton);
removeButton.setAttribute("class","unclicky");
} }
else { else {
removeButton.setAttribute("class","clicky"); removeButton.setAttribute("class","clicky");
@ -327,15 +339,14 @@ ScholarItemPane = new function()
var addButton = document.createElement('label'); var addButton = document.createElement('label');
addButton.setAttribute("value","+"); addButton.setAttribute("value","+");
// If row isn't saved, don't let user add more
if (unsaved) if (unsaved)
{ {
addButton.setAttribute("disabled",true); disableButton(addButton);
addButton.setAttribute("class","unclicky");
} }
else else
{ {
addButton.setAttribute("class","clicky"); _enablePlusButton(addButton);
addButton.setAttribute("onclick","ScholarItemPane.addCreatorRow('','',1,true);");
} }
row.appendChild(addButton); row.appendChild(addButton);
@ -344,6 +355,20 @@ ScholarItemPane = new function()
addDynamicRow(label, row, true); addDynamicRow(label, row, true);
} }
function disableButton(button)
{
button.setAttribute('disabled', true);
button.setAttribute('class', 'unclicky');
button.setAttribute('onclick', false);
}
function _enablePlusButton(button)
{
button.setAttribute('disabled', false);
button.setAttribute("class","clicky");
button.setAttribute("onclick","ScholarItemPane.disableButton(this); ScholarItemPane.addCreatorRow('','',1,true);");
}
function createValueElement(valueText, fieldName) function createValueElement(valueText, fieldName)
{ {
var valueElement = document.createElement("label"); var valueElement = document.createElement("label");
@ -373,6 +398,11 @@ ScholarItemPane = new function()
// If unsaved row, just remove element // If unsaved row, just remove element
if (!_itemBeingEdited.hasCreatorAt(index)){ if (!_itemBeingEdited.hasCreatorAt(index)){
labelToDelete.parentNode.removeChild(labelToDelete); labelToDelete.parentNode.removeChild(labelToDelete);
// Enable the "+" button on the previous row
var elems = _dynamicFields.getElementsByAttribute('value', '+');
_enablePlusButton(elems[elems.length-1]);
_creatorCount--; _creatorCount--;
return; return;
} }
@ -471,7 +501,6 @@ ScholarItemPane = new function()
var label1 = row.getElementsByTagName('hbox')[0].firstChild.firstChild; var label1 = row.getElementsByTagName('hbox')[0].firstChild.firstChild;
var label2 = label1.nextSibling; var label2 = label1.nextSibling;
// doesn't currently return creator type, since we don't need it anywhere
return { return {
lastName: label1.firstChild ? label1.firstChild.nodeValue lastName: label1.firstChild ? label1.firstChild.nodeValue
// Strip trailing comma // Strip trailing comma