ItemTreeView remembers the selection on notify().

MetadataPane editing updated a lot -- creator support added.

Source column is hidden on default.
This commit is contained in:
David Norton 2006-06-07 16:19:56 +00:00
parent 393807b152
commit eba82e2ac6
4 changed files with 143 additions and 128 deletions

View file

@ -194,6 +194,9 @@ Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
ids = Scholar.flattenArguments(ids); ids = Scholar.flattenArguments(ids);
var madeChanges = false; var madeChanges = false;
this.selection.selectEventsSuppressed = true;
this.saveSelection();
if(action == 'remove') if(action == 'remove')
{ {
//Since a remove involves shifting of rows, we have to do it in order //Since a remove involves shifting of rows, we have to do it in order
@ -254,11 +257,18 @@ Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
this.selection.select(this._itemRowMap[item.getID()]); this.selection.select(this._itemRowMap[item.getID()]);
if(this.isSorted()) if(this.isSorted())
{
this.sort(); //this also refreshes the hash map this.sort(); //this also refreshes the hash map
else if(action != 'modify') //no need to update this if we just modified this._treebox.invalidate();
this._refreshHashMap();
} }
else if(action != 'modify') //no need to update this if we just modified
{
this._refreshHashMap();
}
this.rememberSelection();
}
this.selection.selectEventsSuppressed = false;
} }
Scholar.ItemTreeView.prototype.saveSelection = function() Scholar.ItemTreeView.prototype.saveSelection = function()

View file

@ -1,27 +1,36 @@
MetadataPane = new function() MetadataPane = new function()
{ {
var _dynamicFields; var _dynamicFields;
var _creatorTypeMenu;
var _beforeRow;
var _creatorCount;
var _itemBeingEdited; var _itemBeingEdited;
var _creatorTypes = Scholar.CreatorTypes.getTypes();
this.onLoad = onLoad; this.onLoad = onLoad;
this.viewItem = viewItem; this.viewItem = viewItem;
/* this.saveItem = saveItem; this.addCreatorRow = addCreatorRow;
this.addCreator = addCreator; this.modifyCreator = modifyCreator;
this.removeCreator = removeCreator; */ this.removeCreator = removeCreator;
this.showEditor = showEditor; this.showEditor = showEditor;
this.hideEditor = hideEditor; this.hideEditor = hideEditor;
function onLoad() function onLoad()
{ {
_metadataPane = document.getElementById('scholar-metadata');
_dynamicFields = document.getElementById('editpane-dynamic-fields'); _dynamicFields = document.getElementById('editpane-dynamic-fields');
_dynamicCreators = document.getElementById('editpane-dynamic-creators'); _creatorTypeMenu = document.getElementById('creatorTypeMenu');
_editButton = document.getElementById('metadata-pane-edit-button');
_cancelButton = document.getElementById('metadata-pane-cancel-button'); var creatorTypes = Scholar.CreatorTypes.getTypes();
_saveButton = document.getElementById('metadata-pane-save-button'); for(var i = 0; i < creatorTypes.length; i++)
_creatorsToolbar = document.getElementById('metadata-creators-toolbar'); {
var menuitem = document.createElement("menuitem");
menuitem.setAttribute("label",Scholar.getString('creatorTypes.'+creatorTypes[i]['name']));
menuitem.setAttribute("typeid",creatorTypes[i]['id']);
if(creatorTypes[i]['id'] == 0)
menuitem.setAttribute("selected",true);
_creatorTypeMenu.appendChild(menuitem);
}
return true; return true;
} }
@ -38,74 +47,38 @@ MetadataPane = new function()
function reloadFields() function reloadFields()
{ {
removeDynamicRows(_dynamicFields); while(_dynamicFields.hasChildNodes())
thisItem = _itemBeingEdited; _dynamicFields.removeChild(_dynamicFields.firstChild);
var fieldNames = getFullFieldList(thisItem); var fieldNames = new Array("title","dateAdded","dateModified");
var fields = Scholar.ItemFields.getItemTypeFields(_itemBeingEdited.getField("itemTypeID"));
for(var i = 0; i<fields.length; i++)
fieldNames.push(Scholar.ItemFields.getName(fields[i]));
for(var i = 0; i<fieldNames.length; i++) for(var i = 0; i<fieldNames.length; i++)
{ {
var editable = (!thisItem.isPrimaryField(fieldNames[i]) || thisItem.isEditableField(fieldNames[i])); var editable = (!_itemBeingEdited.isPrimaryField(fieldNames[i]) || _itemBeingEdited.isEditableField(fieldNames[i]));
var label = document.createElement("label"); var label = document.createElement("label");
label.setAttribute("value",Scholar.getString("itemFields."+fieldNames[i])+":"); label.setAttribute("value",Scholar.getString("itemFields."+fieldNames[i])+":");
addDynamicRow(label,createValueElement(thisItem.getField(fieldNames[i]), editable ? fieldNames[i] : null)); addDynamicRow(label,createValueElement(_itemBeingEdited.getField(fieldNames[i]), editable ? fieldNames[i] : null));
} }
if(thisItem.numCreators() > 0) _beforeRow = _dynamicFields.firstChild.nextSibling;
_creatorCount = 0;
if(_itemBeingEdited.numCreators() > 0)
{ {
for(var i = 0, len=thisItem.numCreators(); i<len; i++) for(var i = 0, len=_itemBeingEdited.numCreators(); i<len; i++)
{ {
var creator = thisItem.getCreator(i); var creator = _itemBeingEdited.getCreator(i);
addCreatorRow(creator['firstName'], creator['lastName'], creator['creatorTypeID']);
var label = document.createElement("label");
label.setAttribute("value",Scholar.getString('creatorTypes.'+Scholar.CreatorTypes.getTypeName(creator['creatorTypeID']))+":");
addDynamicRow(label, createValueElement(creator['firstName']+' '+creator['lastName'], null), _dynamicFields.firstChild.nextSibling);
} }
} }
} else
/*
function saveItem()
{ {
//get fields, call data access methods addCreatorRow('', '', 1);
var valueElements = _dynamicFields.getElementsByTagName("textbox"); //All elements of tagname 'textbox' should be the values of edits
for(var i=0; i<valueElements.length; i++)
_itemBeingEdited.setField(valueElements[i].getAttribute("fieldName"),valueElements[i].value);
var numCreatorsBefore = _itemBeingEdited.numCreators();
var creatorRows = _dynamicCreators.childNodes;
for(var i=0; i < creatorRows.length; i++)
{
var firstname = creatorRows[i].firstChild.value;
var lastname = creatorRows[i].firstChild.nextSibling.value;
var typeMenu = creatorRows[i].firstChild.nextSibling.nextSibling;
var typeID = typeMenu.firstChild.childNodes[typeMenu.selectedIndex].getAttribute('typeid');
_itemBeingEdited.setCreator(i, firstname, lastname, typeID);
} }
for(var i = creatorRows.length; i < numCreatorsBefore; i++)
_itemBeingEdited.setCreator(i, false);
_itemBeingEdited.save();
}
*/
function getFullFieldList(item)
{
var fieldNames = new Array("title","dateAdded","dateModified");
var fields = Scholar.ItemFields.getItemTypeFields(item.getField("itemTypeID"));
for(var i = 0; i<fields.length; i++)
fieldNames.push(Scholar.ItemFields.getName(fields[i]));
return fieldNames;
}
function removeDynamicRows(box)
{
while(box.hasChildNodes())
box.removeChild(box.firstChild);
} }
function addDynamicRow(label, value, beforeElement) function addDynamicRow(label, value, beforeElement)
@ -114,11 +87,45 @@ MetadataPane = new function()
row.appendChild(label); row.appendChild(label);
row.appendChild(value); row.appendChild(value);
if(beforeElement) if(beforeElement)
_dynamicFields.insertBefore(row, beforeElement); _dynamicFields.insertBefore(row, _beforeRow);
else else
_dynamicFields.appendChild(row); _dynamicFields.appendChild(row);
} }
function addCreatorRow(firstName, lastName, typeID)
{
if(!firstName)
firstName = "(first)";
if(!lastName)
lastName = "(last)";
var label = document.createElement("label");
label.setAttribute("value",Scholar.getString('creatorTypes.'+Scholar.CreatorTypes.getTypeName(typeID))+":");
label.setAttribute("popup","creatorTypeMenu");
label.setAttribute("fieldname",'creator-'+_creatorCount+'-typeID');
var row = document.createElement("hbox");
var firstlast = document.createElement("hbox");
firstlast.setAttribute("flex","1");
firstlast.appendChild(createValueElement(lastName+",", 'creator-'+_creatorCount+'-lastName'));
firstlast.appendChild(createValueElement(firstName, 'creator-'+_creatorCount+'-firstName'));
row.appendChild(firstlast);
var removeButton = document.createElement('toolbarbutton');
removeButton.setAttribute("label","-");
removeButton.setAttribute("oncommand","MetadataPane.removeCreator("+_creatorCount+")");
row.appendChild(removeButton);
var addButton = document.createElement('toolbarbutton');
addButton.setAttribute("label","+");
addButton.setAttribute("oncommand","MetadataPane.addCreatorRow('','',1);");
row.appendChild(addButton);
_creatorCount++;
addDynamicRow(label, row, true);
}
function createValueElement(valueText, fieldName) function createValueElement(valueText, fieldName)
{ {
var valueElement = document.createElement("label"); var valueElement = document.createElement("label");
@ -130,70 +137,56 @@ MetadataPane = new function()
} }
return valueElement; return valueElement;
} }
/*
function addCreator(firstname, lastname, typeID) function removeCreator(index)
{ {
if(!lastname) _itemBeingEdited.removeCreator(index);
lastname = ""; _itemBeingEdited.save();
if(!firstname) reloadFields();
firstname = "";
if(!typeID)
typeID = 0;
var first = document.createElement("textbox");
first.setAttribute("value",firstname);
var last = document.createElement("textbox");
last.setAttribute("value",lastname);
var type = document.createElement("menulist");
type.setAttribute("label","Type");
var typeMenu = document.createElement("menupopup");
for(var j = 0; j < _creatorTypes.length; j++)
{
var menuitem = document.createElement("menuitem");
menuitem.setAttribute("label",Scholar.getString('creatorTypes.'+_creatorTypes[j]['name']));
menuitem.setAttribute("typeid",_creatorTypes[j]['id']);
if(_creatorTypes[j]['id'] == typeID)
menuitem.setAttribute("selected",true);
typeMenu.appendChild(menuitem);
}
type.appendChild(typeMenu);
var remove = document.createElement("toolbarbutton");
remove.setAttribute("label","-");
remove.setAttribute("class","addremove");
remove.setAttribute("oncommand","MetadataPane.removeCreator(this.parentNode);");
var add = document.createElement("toolbarbutton");
add.setAttribute("label","+");
add.setAttribute("class","addremove");
add.setAttribute("oncommand","MetadataPane.addCreator();");
var row = document.createElement("row");
row.appendChild(first);
row.appendChild(last);
row.appendChild(type);
row.appendChild(remove);
row.appendChild(add);
_dynamicCreators.appendChild(row);
} }
function removeCreator(row) function modifyCreator(index, field, value)
{ {
_dynamicCreators.removeChild(row); var creator = _itemBeingEdited.getCreator(index);
}*/ var firstName = creator['firstName'];
var lastName = creator['lastName'];
var typeID = creator['typeID'];
if(field == 'firstName')
firstName = value;
else if(field == 'lastName')
lastName = value;
else if(field == 'typeID')
typeID = value;
_itemBeingEdited.setCreator(index, firstName, lastName, typeID);
_itemBeingEdited.save();
}
function showEditor(elem) function showEditor(elem)
{ {
var fieldName = elem.getAttribute('fieldname');
var value = '';
var creatorFields = fieldName.split('-');
if(creatorFields[0] == 'creator')
{
var c = _itemBeingEdited.getCreator(creatorFields[1]);
if(c)
value = c[creatorFields[2]];
}
else
{
value = _itemBeingEdited.getField(fieldName);
}
var t = document.createElement("textbox"); var t = document.createElement("textbox");
t.setAttribute('value',_itemBeingEdited.getField(elem.getAttribute('fieldname'))); t.setAttribute('value',value);
t.setAttribute('fieldname',elem.getAttribute('fieldname')); t.setAttribute('fieldname',fieldName);
t.setAttribute('flex','1');
var box = elem.parentNode; var box = elem.parentNode;
box.removeChild(elem); box.replaceChild(t,elem);
box.appendChild(t);
t.select(); t.select();
t.setAttribute('onblur',"MetadataPane.hideEditor(this);"); t.setAttribute('onblur',"MetadataPane.hideEditor(this);");
t.setAttribute('onkeypress','if(event.keyCode == event.DOM_VK_RETURN) document.commandDispatcher.focusedElement.blur()'); //for some reason I can't just say this.blur(); t.setAttribute('onkeypress','if(event.keyCode == event.DOM_VK_RETURN) document.commandDispatcher.focusedElement.blur()'); //for some reason I can't just say this.blur();
@ -204,16 +197,25 @@ MetadataPane = new function()
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;
Scholar.debug(value);
var elem;
var creatorFields = fieldName.split('-');
if(creatorFields[0] == 'creator')
{
modifyCreator(creatorFields[1],creatorFields[2],value);
elem = createValueElement(value, fieldName);
}
else
{
_itemBeingEdited.setField(fieldName,value); _itemBeingEdited.setField(fieldName,value);
_itemBeingEdited.save(); _itemBeingEdited.save();
var elem = createValueElement(value,fieldName); elem = createValueElement(_itemBeingEdited.getField(fieldName),fieldName);
}
var box = textbox.parentNode; var box = textbox.parentNode;
box.removeChild(textbox); box.replaceChild(elem,textbox);
box.appendChild(elem);
} }
} }

View file

@ -6,6 +6,9 @@
<script src="metadataPane.js"/> <script src="metadataPane.js"/>
<vbox id="scholar-metadata"> <vbox id="scholar-metadata">
<popupset>
<popup id="creatorTypeMenu" position="after_start" oncommand="MetadataPane.modifyCreator(document.popupNode.getAttribute('fieldname').split('-')[1],'typeID',event.explicitOriginalTarget.getAttribute('typeid'));"/>
</popupset>
<grid> <grid>
<columns> <columns>
<column/> <column/>

View file

@ -67,11 +67,11 @@
<splitter class="tree-splitter"/> <splitter class="tree-splitter"/>
<treecol <treecol
id="firstCreator" id="firstCreator"
label="&items.creator_column;" label="&items.creator_column;" sortActive="true" sortDirection="descending"
flex="1" persist="width ordinal hidden sortActive sortDirection"/> flex="1" persist="width ordinal hidden sortActive sortDirection"/>
<splitter class="tree-splitter"/> <splitter class="tree-splitter"/>
<treecol <treecol
id="source" id="source" hidden="true"
label="&items.source_column;" label="&items.source_column;"
flex="1" persist="width ordinal hidden sortActive sortDirection"/> flex="1" persist="width ordinal hidden sortActive sortDirection"/>
<splitter class="tree-splitter"/> <splitter class="tree-splitter"/>