Fixes #179, adding a new creator then clicking an existing creator makes the creator field disappear
Fixed a number of creator-editing-related issues (mostly interface-side, with a little help from the data layer): - New row no longer disappears when clicking "+" and then clicking the existing or new creator (removed onselect="ScholarItemPane.loadPane(this.selectedIndex)" on the <deck> (from r371, with changelog "Individual tabs don't load their content unless selected"), which doesn't seem to be necessary as far as I can tell) - New row no longer disappears when changing creator before editing names (setting the creator type now triggers an Item.save() with an otherwise blank creator (now allowed by the data layer), which isn't entirely ideal but is probably OK for now) - Clicking the minus button on an unsaved row (i.e. one just created with the plus button) no longer throws an error (new method Item.hasCreatorAt(pos), and ScholarItemPane.removeCreator() just deletes the label directly, since it doesn't get a notify() event to reload the pane) - The plus button is disabled on unsaved rows, since allowing the user to create multiple unsaved rows and then edit one in the middle is problematic (and the other alternatives have their own problems); the minus button is also disabled on the default row that shows when there are no creators - Creator type is no longer reset when editing a name field - Name field is no longer erased when clicking directly on creator type popup and changing creator type without blurring textbox - Comma is appended to last name when switching from <textbox> to <label> without saving changes (before it was just appended to labels when the pane was loaded)
This commit is contained in:
parent
bb07710b34
commit
c92faace52
|
@ -43,6 +43,7 @@ ScholarItemPane = new function()
|
||||||
this.showEditor = showEditor;
|
this.showEditor = showEditor;
|
||||||
this.hideEditor = hideEditor;
|
this.hideEditor = hideEditor;
|
||||||
this.modifyField = modifyField;
|
this.modifyField = modifyField;
|
||||||
|
this.getCreatorFields = getCreatorFields;
|
||||||
this.modifyCreator = modifyCreator;
|
this.modifyCreator = modifyCreator;
|
||||||
this.removeNote = removeNote;
|
this.removeNote = removeNote;
|
||||||
this.addNote = addNote;
|
this.addNote = addNote;
|
||||||
|
@ -100,6 +101,7 @@ ScholarItemPane = new function()
|
||||||
return;
|
return;
|
||||||
_loaded[index] = true;
|
_loaded[index] = true;
|
||||||
|
|
||||||
|
// Info pane
|
||||||
if(index == 0)
|
if(index == 0)
|
||||||
{
|
{
|
||||||
while(_dynamicFields.hasChildNodes())
|
while(_dynamicFields.hasChildNodes())
|
||||||
|
@ -148,7 +150,7 @@ ScholarItemPane = new function()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
addCreatorRow('', '', 1);
|
addCreatorRow('', '', 1, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(index == 1)
|
else if(index == 1)
|
||||||
|
@ -287,7 +289,7 @@ ScholarItemPane = new function()
|
||||||
_dynamicFields.appendChild(row);
|
_dynamicFields.appendChild(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addCreatorRow(firstName, lastName, typeID)
|
function addCreatorRow(firstName, lastName, typeID, unsaved, defaultRow)
|
||||||
{
|
{
|
||||||
if(!firstName)
|
if(!firstName)
|
||||||
firstName = "(first)";
|
firstName = "(first)";
|
||||||
|
@ -299,6 +301,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
|
||||||
var row = document.createElement("hbox");
|
var row = document.createElement("hbox");
|
||||||
|
|
||||||
var firstlast = document.createElement("hbox");
|
var firstlast = document.createElement("hbox");
|
||||||
|
@ -309,14 +312,28 @@ ScholarItemPane = new function()
|
||||||
|
|
||||||
var removeButton = document.createElement('label');
|
var removeButton = document.createElement('label');
|
||||||
removeButton.setAttribute("value","-");
|
removeButton.setAttribute("value","-");
|
||||||
removeButton.setAttribute("class","clicky");
|
if (defaultRow){
|
||||||
removeButton.setAttribute("onclick","ScholarItemPane.removeCreator("+_creatorCount+")");
|
removeButton.setAttribute("disabled",true);
|
||||||
|
removeButton.setAttribute("class","unclicky");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
removeButton.setAttribute("class","clicky");
|
||||||
|
removeButton.setAttribute("onclick","ScholarItemPane.removeCreator("+_creatorCount+", this.parentNode.parentNode)");
|
||||||
|
}
|
||||||
row.appendChild(removeButton);
|
row.appendChild(removeButton);
|
||||||
|
|
||||||
var addButton = document.createElement('label');
|
var addButton = document.createElement('label');
|
||||||
addButton.setAttribute("value","+");
|
addButton.setAttribute("value","+");
|
||||||
addButton.setAttribute("class","clicky");
|
if (unsaved)
|
||||||
addButton.setAttribute("onclick","ScholarItemPane.addCreatorRow('','',1);");
|
{
|
||||||
|
addButton.setAttribute("disabled",true);
|
||||||
|
addButton.setAttribute("class","unclicky");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
addButton.setAttribute("class","clicky");
|
||||||
|
addButton.setAttribute("onclick","ScholarItemPane.addCreatorRow('','',1,true);");
|
||||||
|
}
|
||||||
row.appendChild(addButton);
|
row.appendChild(addButton);
|
||||||
|
|
||||||
_creatorCount++;
|
_creatorCount++;
|
||||||
|
@ -348,8 +365,14 @@ ScholarItemPane = new function()
|
||||||
return valueElement;
|
return valueElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeCreator(index)
|
function removeCreator(index, labelToDelete)
|
||||||
{
|
{
|
||||||
|
// If unsaved row, just remove element
|
||||||
|
if (!_itemBeingEdited.hasCreatorAt(index)){
|
||||||
|
labelToDelete.parentNode.removeChild(labelToDelete);
|
||||||
|
_creatorCount--;
|
||||||
|
return;
|
||||||
|
}
|
||||||
_itemBeingEdited.removeCreator(index);
|
_itemBeingEdited.removeCreator(index);
|
||||||
_itemBeingEdited.save();
|
_itemBeingEdited.save();
|
||||||
loadPane(0);
|
loadPane(0);
|
||||||
|
@ -398,7 +421,11 @@ ScholarItemPane = new function()
|
||||||
if(saveChanges)
|
if(saveChanges)
|
||||||
modifyCreator(creatorFields[1],creatorFields[2],value);
|
modifyCreator(creatorFields[1],creatorFields[2],value);
|
||||||
|
|
||||||
elem = createValueElement(_itemBeingEdited.getCreator(creatorFields[1])[creatorFields[2]], fieldName);
|
var val = _itemBeingEdited.getCreator(creatorFields[1])[creatorFields[2]];
|
||||||
|
if (creatorFields[2]=='lastName'){
|
||||||
|
val += ',';
|
||||||
|
}
|
||||||
|
elem = createValueElement(val, fieldName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -419,12 +446,34 @@ ScholarItemPane = new function()
|
||||||
_itemBeingEdited.save();
|
_itemBeingEdited.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
function modifyCreator(index, field, value)
|
function getCreatorFields(row){
|
||||||
|
var label1 = row.getElementsByTagName('hbox')[0].firstChild.firstChild;
|
||||||
|
var label2 = label1.nextSibling;
|
||||||
|
|
||||||
|
// doesn't currently return creator type, since we don't need it anywhere
|
||||||
|
return {
|
||||||
|
lastName: label1.firstChild ? label1.firstChild.nodeValue
|
||||||
|
// Strip trailing comma
|
||||||
|
.substr(0, label1.firstChild.nodeValue.length-1): label1.value,
|
||||||
|
firstName: label2.firstChild ? label2.firstChild.nodeValue
|
||||||
|
: label2.value,
|
||||||
|
isInstitution: null // placeholder
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function modifyCreator(index, field, value, otherFields)
|
||||||
{
|
{
|
||||||
var creator = _itemBeingEdited.getCreator(index);
|
if (otherFields){
|
||||||
var firstName = creator['firstName'];
|
var firstName = otherFields.firstName;
|
||||||
var lastName = creator['lastName'];
|
var lastName = otherFields.lastName;
|
||||||
var typeID = creator['typeID'];
|
// var isInstitution = otherFields.isInstitution;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var creator = _itemBeingEdited.getCreator(index);
|
||||||
|
var firstName = creator['firstName'];
|
||||||
|
var lastName = creator['lastName'];
|
||||||
|
var typeID = creator['creatorTypeID'];
|
||||||
|
}
|
||||||
|
|
||||||
if(field == 'firstName')
|
if(field == 'firstName')
|
||||||
firstName = value;
|
firstName = value;
|
||||||
|
|
|
@ -24,10 +24,13 @@
|
||||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||||
|
|
||||||
<script src="itemPane.js"/>
|
<script src="itemPane.js"/>
|
||||||
<deck id="scholar-view-item" flex="1" onselect="ScholarItemPane.loadPane(this.selectedIndex);">
|
<deck id="scholar-view-item" flex="1">
|
||||||
<vbox id="scholar-info" flex="1">
|
<vbox id="scholar-info" flex="1">
|
||||||
<popupset>
|
<popupset>
|
||||||
<popup id="creatorTypeMenu" position="after_start" oncommand="ScholarItemPane.modifyCreator(document.popupNode.getAttribute('fieldname').split('-')[1],'typeID',event.explicitOriginalTarget.getAttribute('typeid'));"/>
|
<popup id="creatorTypeMenu" position="after_start"
|
||||||
|
oncommand="var otherFields = ScholarItemPane.getCreatorFields(document.popupNode.parentNode);
|
||||||
|
ScholarItemPane.modifyCreator(document.popupNode.getAttribute('fieldname').split('-')[1],
|
||||||
|
'typeID', event.explicitOriginalTarget.getAttribute('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">
|
||||||
|
|
|
@ -189,6 +189,15 @@ Scholar.Item.prototype.numCreators = function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Scholar.Item.prototype.hasCreatorAt = function(pos){
|
||||||
|
if (this.getID() && !this._creatorsLoaded){
|
||||||
|
this._loadCreators();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._creators.has(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns an array of the creator data at the given position, or false if none
|
* Returns an array of the creator data at the given position, or false if none
|
||||||
*
|
*
|
||||||
|
@ -468,7 +477,8 @@ Scholar.Item.prototype.save = function(){
|
||||||
Scholar.DB.query(sql2);
|
Scholar.DB.query(sql2);
|
||||||
|
|
||||||
// If empty, move on
|
// If empty, move on
|
||||||
if (!creator['firstName'] && !creator['lastName']){
|
if (typeof creator['firstName'] == 'undefined'
|
||||||
|
&& typeof creator['lastName'] == 'undefined'){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2701,6 +2711,13 @@ Scholar.Creators = new function(){
|
||||||
* Returns the creatorID matching given name and type
|
* Returns the creatorID matching given name and type
|
||||||
*/
|
*/
|
||||||
function getID(firstName, lastName, isInstitution){
|
function getID(firstName, lastName, isInstitution){
|
||||||
|
if (!firstName){
|
||||||
|
firstName = '';
|
||||||
|
}
|
||||||
|
if (!lastName){
|
||||||
|
lastName = '';
|
||||||
|
}
|
||||||
|
|
||||||
if (isInstitution){
|
if (isInstitution){
|
||||||
firstName = '';
|
firstName = '';
|
||||||
isInstitution = 1;
|
isInstitution = 1;
|
||||||
|
|
|
@ -73,19 +73,13 @@ searchcondition
|
||||||
-moz-binding: url('chrome://scholar/content/bindings/scholarsearch.xml#search-condition');
|
-moz-binding: url('chrome://scholar/content/bindings/scholarsearch.xml#search-condition');
|
||||||
}
|
}
|
||||||
|
|
||||||
.clicky
|
.clicky, .unclicky
|
||||||
{
|
{
|
||||||
-moz-border-radius: 6px;
|
-moz-border-radius: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.clicky[value="-"]
|
.clicky[value="-"], .clicky[value="+"],
|
||||||
{
|
.unclicky[value="-"], .unclicky[value="+"]
|
||||||
margin: 0px;
|
|
||||||
padding-left: 4px;
|
|
||||||
padding-right: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.clicky[value="+"]
|
|
||||||
{
|
{
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
padding-left: 4px;
|
padding-left: 4px;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user