[interface] Preliminary note editing support.

[other] MetadataPane renamed ScholarItemPane.
This commit is contained in:
David Norton 2006-06-09 15:52:40 +00:00
parent fbcd247b09
commit a7b35c0286
5 changed files with 86 additions and 70 deletions

View file

@ -30,7 +30,6 @@ Scholar.ItemTreeView.prototype.refresh = function()
this._refreshHashMap(); this._refreshHashMap();
} }
//CALLED BY DATA LAYER ON CHANGE:
Scholar.ItemTreeView.prototype.notify = function(action, type, ids) Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
{ {
var madeChanges = false; var madeChanges = false;
@ -246,10 +245,11 @@ Scholar.ItemTreeView.prototype._getItemAtRow = function(row)
return this._dataItems[row]; return this._dataItems[row];
} }
/*
* Create hash map of item ids to row indexes
*/
Scholar.ItemTreeView.prototype._refreshHashMap = function() Scholar.ItemTreeView.prototype._refreshHashMap = function()
{ {
// Create hash map of item ids to row indexes
this._itemRowMap = new Array(); this._itemRowMap = new Array();
for(var i=0; i < this.rowCount; i++) for(var i=0; i < this.rowCount; i++)
this._itemRowMap[this._getItemAtRow(i).getID()] = i; this._itemRowMap[this._getItemAtRow(i).getID()] = i;
@ -303,7 +303,7 @@ Scholar.ItemTreeView.prototype.getSupportedFlavours = function ()
Scholar.ItemTreeView.prototype.onDragOver = function (evt,dropdata,session) { } Scholar.ItemTreeView.prototype.onDragOver = function (evt,dropdata,session) { }
Scholar.ItemTreeView.prototype.onDrop = function (evt,dropdata,session) { } Scholar.ItemTreeView.prototype.onDrop = function (evt,dropdata,session) { }
//More functions we have to include for TreeView /* MORE TREEVIEW FUNCTIONS THAT HAVE TO BE HERE */
Scholar.ItemTreeView.prototype.isSeparator = function(row) { return false; } Scholar.ItemTreeView.prototype.isSeparator = function(row) { return false; }
Scholar.ItemTreeView.prototype.isContainer = function(row) { return false; } Scholar.ItemTreeView.prototype.isContainer = function(row) { return false; }

View file

@ -1,8 +1,9 @@
MetadataPane = new function() ScholarItemPane = new function()
{ {
var _dynamicFields; var _dynamicFields;
var _creatorTypeMenu; var _creatorTypeMenu;
var _beforeRow; var _beforeRow;
var _notesPane;
var _creatorCount; var _creatorCount;
@ -11,15 +12,17 @@ MetadataPane = new function()
this.onLoad = onLoad; this.onLoad = onLoad;
this.viewItem = viewItem; this.viewItem = viewItem;
this.addCreatorRow = addCreatorRow; this.addCreatorRow = addCreatorRow;
this.modifyCreator = modifyCreator;
this.removeCreator = removeCreator; this.removeCreator = removeCreator;
this.showEditor = showEditor; this.showEditor = showEditor;
this.hideEditor = hideEditor; this.hideEditor = hideEditor;
this.modifyField = modifyField;
this.modifyCreator = modifyCreator;
function onLoad() function onLoad()
{ {
_dynamicFields = document.getElementById('editpane-dynamic-fields'); _dynamicFields = document.getElementById('editpane-dynamic-fields');
_creatorTypeMenu = document.getElementById('creatorTypeMenu'); _creatorTypeMenu = document.getElementById('creatorTypeMenu');
_notesPane = document.getElementById('scholar-notes');
var creatorTypes = Scholar.CreatorTypes.getTypes(); var creatorTypes = Scholar.CreatorTypes.getTypes();
for(var i = 0; i < creatorTypes.length; i++) for(var i = 0; i < creatorTypes.length; i++)
@ -56,13 +59,22 @@ MetadataPane = new function()
fieldNames.push(Scholar.ItemFields.getName(fields[i])); fieldNames.push(Scholar.ItemFields.getName(fields[i]));
for(var i = 0; i<fieldNames.length; i++) for(var i = 0; i<fieldNames.length; i++)
{
if(fieldNames[i] != 'notes')
{ {
var editable = (!_itemBeingEdited.isPrimaryField(fieldNames[i]) || _itemBeingEdited.isEditableField(fieldNames[i])); var editable = (!_itemBeingEdited.isPrimaryField(fieldNames[i]) || _itemBeingEdited.isEditableField(fieldNames[i]));
var valueElement = createValueElement(_itemBeingEdited.getField(fieldNames[i]), editable ? fieldNames[i] : null);
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(_itemBeingEdited.getField(fieldNames[i]), editable ? fieldNames[i] : null)); addDynamicRow(label,valueElement);
}
else
{
_notesPane.value = _itemBeingEdited.getField(fieldNames[i]);
}
} }
_beforeRow = _dynamicFields.firstChild.nextSibling; _beforeRow = _dynamicFields.firstChild.nextSibling;
@ -114,13 +126,13 @@ MetadataPane = new function()
var removeButton = document.createElement('toolbarbutton'); var removeButton = document.createElement('toolbarbutton');
removeButton.setAttribute("label","-"); removeButton.setAttribute("label","-");
removeButton.setAttribute("class","addremove"); removeButton.setAttribute("class","addremove");
removeButton.setAttribute("oncommand","MetadataPane.removeCreator("+_creatorCount+")"); removeButton.setAttribute("oncommand","ScholarItemPane.removeCreator("+_creatorCount+")");
row.appendChild(removeButton); row.appendChild(removeButton);
var addButton = document.createElement('toolbarbutton'); var addButton = document.createElement('toolbarbutton');
addButton.setAttribute("label","+"); addButton.setAttribute("label","+");
addButton.setAttribute("class","addremove"); addButton.setAttribute("class","addremove");
addButton.setAttribute("oncommand","MetadataPane.addCreatorRow('','',1);"); addButton.setAttribute("oncommand","ScholarItemPane.addCreatorRow('','',1);");
row.appendChild(addButton); row.appendChild(addButton);
_creatorCount++; _creatorCount++;
@ -135,7 +147,7 @@ MetadataPane = new function()
if(fieldName) if(fieldName)
{ {
valueElement.setAttribute('fieldname',fieldName); valueElement.setAttribute('fieldname',fieldName);
valueElement.setAttribute('onclick', 'MetadataPane.showEditor(this);'); valueElement.setAttribute('onclick', 'ScholarItemPane.showEditor(this);');
} }
return valueElement; return valueElement;
} }
@ -147,24 +159,6 @@ MetadataPane = new function()
reloadFields(); reloadFields();
} }
function modifyCreator(index, field, value)
{
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 fieldName = elem.getAttribute('fieldname');
@ -190,8 +184,8 @@ MetadataPane = new function()
box.replaceChild(t,elem); box.replaceChild(t,elem);
t.select(); t.select();
t.setAttribute('onblur',"MetadataPane.hideEditor(this, true);"); t.setAttribute('onblur',"ScholarItemPane.hideEditor(this, true);");
t.setAttribute('onkeypress','if(event.keyCode == event.DOM_VK_RETURN) document.commandDispatcher.focusedElement.blur(); else if(event.keyCode == event.DOM_VK_ESCAPE) MetadataPane.hideEditor(document.commandDispatcher.focusedElement, false);'); //for some reason I can't just say this.blur(); t.setAttribute('onkeypress','if(event.keyCode == event.DOM_VK_RETURN) document.commandDispatcher.focusedElement.blur(); else if(event.keyCode == event.DOM_VK_ESCAPE) ScholarItemPane.hideEditor(document.commandDispatcher.focusedElement, false);'); //for some reason I can't just say this.blur();
} }
function hideEditor(t, saveChanges) function hideEditor(t, saveChanges)
@ -212,10 +206,7 @@ MetadataPane = new function()
else else
{ {
if(saveChanges) if(saveChanges)
{ modifyField(fieldName,value);
_itemBeingEdited.setField(fieldName,value);
_itemBeingEdited.save();
}
elem = createValueElement(_itemBeingEdited.getField(fieldName),fieldName); elem = createValueElement(_itemBeingEdited.getField(fieldName),fieldName);
} }
@ -224,6 +215,30 @@ MetadataPane = new function()
box.replaceChild(elem,textbox); box.replaceChild(elem,textbox);
} }
function modifyField(field, value)
{
_itemBeingEdited.setField(field,value);
_itemBeingEdited.save();
}
function modifyCreator(index, field, value)
{
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();
}
} }
addEventListener("load", function(e) { MetadataPane.onLoad(e); }, false); addEventListener("load", function(e) { ScholarItemPane.onLoad(e); }, false);

View file

@ -5,9 +5,15 @@
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="metadataPane.js"/> <script src="metadataPane.js"/>
<tabbox id="scholar-view-item">
<tabs>
<tab label="Info"/>
<tab label="Notes"/>
</tabs>
<tabpanels flex="1">
<vbox id="scholar-metadata"> <vbox id="scholar-metadata">
<popupset> <popupset>
<popup id="creatorTypeMenu" position="after_start" oncommand="MetadataPane.modifyCreator(document.popupNode.getAttribute('fieldname').split('-')[1],'typeID',event.explicitOriginalTarget.getAttribute('typeid'));"/> <popup id="creatorTypeMenu" position="after_start" oncommand="ScholarItemPane.modifyCreator(document.popupNode.getAttribute('fieldname').split('-')[1],'typeID',event.explicitOriginalTarget.getAttribute('typeid'));"/>
</popupset> </popupset>
<grid> <grid>
<columns> <columns>
@ -19,4 +25,11 @@
</rows> </rows>
</grid> </grid>
</vbox> </vbox>
<vbox>
<textbox id="scholar-notes" multiline="true" flex="1"
fieldname="notes" onblur="ScholarItemPane.modifyField('notes',this.value);"/>
<button label="Save" oncommand="ScholarItemPane.modifyField('notes',document.getElementById('scholar-notes').value);"/>
</vbox>
</tabpanels>
</tabbox>
</overlay> </overlay>

View file

@ -72,7 +72,7 @@ var ScholarPane = new function()
*/ */
function newItem(typeID) function newItem(typeID)
{ {
MetadataPane.viewItem(new Scholar.Item(typeID)); ScholarItemPane.viewItem(new Scholar.Item(typeID));
document.getElementById('scholar-view-item').hidden = false; document.getElementById('scholar-view-item').hidden = false;
document.getElementById('scholar-view-splitter').hidden = false; document.getElementById('scholar-view-splitter').hidden = false;
} }
@ -112,7 +112,7 @@ var ScholarPane = new function()
{ {
var item = itemsView._getItemAtRow(itemsView.selection.currentIndex); var item = itemsView._getItemAtRow(itemsView.selection.currentIndex);
MetadataPane.viewItem(item); ScholarItemPane.viewItem(item);
document.getElementById('scholar-view-item').hidden = false; document.getElementById('scholar-view-item').hidden = false;
document.getElementById('scholar-view-splitter').hidden = false; document.getElementById('scholar-view-splitter').hidden = false;

View file

@ -98,19 +98,7 @@
</vbox> </vbox>
<separator orient="vertical" class="thin" id="scholar-view-splitter" hidden="true"/> <separator orient="vertical" class="thin" id="scholar-view-splitter" hidden="true"/>
<tabbox id="scholar-view-item" hidden="true" flex="2" style="min-width: 300px; max-width: 300px;"> <tabbox id="scholar-view-item" hidden="true" flex="2" style="min-width: 300px; max-width: 300px;"/>
<tabs>
<tab label="Metadata"/>
<tab label="Notes"/>
</tabs>
<tabpanels flex="1">
<vbox id="scholar-metadata">
</vbox>
<vbox id="scholar-notes">
<textbox multiline="true" flex="1" disabled="true"/>
</vbox>
</tabpanels>
</tabbox>
</hbox> </hbox>
<splitter id="scholar-splitter" resizebefore="closest" resizeafter="closest" position="2" persist="collapsed"/> <splitter id="scholar-splitter" resizebefore="closest" resizeafter="closest" position="2" persist="collapsed"/>
</vbox> </vbox>