Drag and drop column reorder on items tree.

Some basic editing capabilities. (interface needs work, fixing).
This commit is contained in:
David Norton 2006-05-30 19:24:57 +00:00
parent 1910eb32f9
commit b7f78aa189
4 changed files with 291 additions and 12 deletions

View file

@ -0,0 +1,197 @@
MetadataPane = new function()
{
var _dynamicFields;
var _dynamicCreators;
var _itemBeingEdited;
var _creatorTypes = Scholar.CreatorTypes.getTypes();
var _editButton;
this.init = init;
this.viewItem = viewItem;
this.toggleEdit = toggleEdit;
this.saveItem = saveItem;
this.addCreator = addCreator;
this.removeCreator = removeCreator;
function init()
{
_metadataPane = document.getElementById('metadata-pane');
_dynamicFields = document.getElementById('editpane-dynamic-fields');
_dynamicCreators = document.getElementById('editpane-dynamic-creators');
_editButton = document.getElementById('metadata-pane-edit-button');
return true;
}
function viewItem(thisItem)
{
removeDynamicRows(_dynamicFields);
var fieldNames = getFullFieldList(thisItem);
for(var i = 0; i<fieldNames.length; i++)
{
if(!thisItem.isPrimaryField(fieldNames[i]) || thisItem.isEditableField(fieldNames[i]))
{
var label = document.createElement("label");
label.setAttribute("value",Scholar.getString("itemFields."+fieldNames[i])+":");
label.setAttribute("control","dynamic-field-"+i);
//create the textbox
var valueElement = document.createElement("textbox");
valueElement.setAttribute("value",thisItem.getField(fieldNames[i]));
valueElement.setAttribute("id","dynamic-field-"+i); //just so the label can be assigned to this valueElement
valueElement.setAttribute("fieldName",fieldNames[i]); //we will use this later
valueElement.setAttribute("disabled",true);
var row = document.createElement("row");
row.appendChild(label);
row.appendChild(valueElement);
_dynamicFields.appendChild(row);
}
}
removeDynamicRows(_dynamicCreators);
for(var i = 0, len=thisItem.numCreators(); i<len; i++)
addCreator(thisItem.getCreator(i)['firstName'],thisItem.getCreator(i)['lastName'],thisItem.getCreator(i)['creatorTypeID']);
_itemBeingEdited = thisItem;
}
function toggleEdit()
{
if(_editButton.checked)
saveItem();
_editButton.checked = !_editButton.checked;
var disabledElements = [];
for(var i = 0, row; row = _dynamicFields.childNodes[i]; i++)
{
disabledElements.push(row.lastChild);
}
for(var i = 0, row; row = _dynamicCreators.childNodes[i]; i++)
{
for(var j = 0, col; col = row.childNodes[j]; j++)
{
disabledElements.push(col);
}
}
disabledElements.push(document.getElementById('tb-creator-add'));
for(var i = 0, elem; elem = disabledElements[i]; i++)
{
if(_editButton.checked)
elem.removeAttribute("disabled");
else
elem.setAttribute("disabled",true);
}
}
function saveItem()
{
//get fields, call data access methods
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);
if(!_itemBeingEdited.getID()) //NEW ITEM
{
/* get ref to myTreeView?
myTreeView._showItem(_itemBeingEdited, 0, myTreeView.rowCount);
myTreeView._treebox.rowCountChanged(myTreeView.rowCount-1,1);
*/
}
_itemBeingEdited.save();
}
function getFullFieldList(item)
{
var fields = Scholar.ItemFields.getItemTypeFields(item.getField("itemTypeID"));
var fieldNames = new Array("title","dateAdded","dateModified","source","rights");
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 addCreator(firstname, lastname, typeID)
{
if(!lastname)
lastname = "";
if(!firstname)
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","x");
remove.setAttribute("oncommand","MetadataPane.removeCreator(this.parentNode);");
if(!_editButton.checked)
{
first.setAttribute("disabled",true);
last.setAttribute("disabled",true);
type.setAttribute("disabled",true);
remove.setAttribute("disabled",true);
}
var row = document.createElement("row");
row.appendChild(first);
row.appendChild(last);
row.appendChild(type);
row.appendChild(remove);
_dynamicCreators.appendChild(row);
}
function removeCreator(row)
{
_dynamicCreators.removeChild(row);
}
}
window.addEventListener("load", function(e) { MetadataPane.init(e); }, false);

View file

@ -0,0 +1,38 @@
<?xml version="1.0"?>
<overlay
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="metadataPane.js"/>
<vbox id="metadata-pane">
<grid>
<columns>
<column/>
<column flex="1"/>
</columns>
<rows id="editpane-dynamic-fields">
</rows>
</grid>
<grid>
<columns>
<column flex="1"/>
<column flex="1"/>
<column/>
<column/>
</columns>
<rows id="editpane-dynamic-creators">
</rows>
</grid>
<spacer flex="1"/>
<toolbar>
<toolbarbutton id="metadata-pane-edit-button" label="Edit" oncommand="MetadataPane.toggleEdit()"/>
<spacer flex="1" />
<toolbarbutton id="tb-creator-add" label="Add Creator" oncommand="MetadataPane.addCreator()" disabled="true"/>
</toolbar>
</vbox>
</overlay>

View file

@ -1,5 +1,6 @@
var foldersView;
var itemsView;
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
function init()
{
@ -50,19 +51,54 @@ function folderSelected()
function itemSelected()
{
if(itemsView.selection.count == 1)
var tabs = document.getElementById('item-tabs');
var editButton = document.getElementById('metadata-pane-edit-button');
if(editButton.checked)
{
var flags=promptService.BUTTON_TITLE_SAVE * promptService.BUTTON_POS_0 +
promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1 +
promptService.BUTTON_TITLE_DONT_SAVE * promptService.BUTTON_POS_2;
var response = promptService.confirmEx(window,"",
"Do you want to save the changes?", // to '"+_itemBeingEdited.getField("title")+"'
flags, null, null, null, null, {});
if(response == 1)
return;
else if(response == 0)
MetadataPane.toggleEdit();
else
editButton.checked = false;
}
if(itemsView && itemsView.selection.count == 1)
{
var item = itemsView._getItemAtRow(itemsView.selection.currentIndex);
document.getElementById('view-pane').setAttribute('src','http://www.google.com/search?q='+encodeURIComponent('"'+item.getField("title")+'"')+'&btnI');
tabs.hidden=false;
if(tabs.firstChild.selectedIndex == 0)
{
document.getElementById('view-pane').setAttribute('src','http://www.google.com/search?q='+encodeURIComponent('"'+item.getField("title")+'"')+'&btnI');
}
else if(tabs.firstChild.selectedIndex == 1)
{
MetadataPane.viewItem(item);
}
else
{
//do notes
}
}
else
{
tabs.hidden=true;
}
}
function deleteSelection()
{
if(itemsView && itemsView.selection.count > 0 && confirm("Are you sure you want to delete the selection????"))
{
if(itemsView && itemsView.selection.count > 0 && confirm("Are you sure you want to delete the selected items?"))
itemsView.deleteSelection();
}
}
function search()

View file

@ -13,6 +13,8 @@
windowtype="scholar:window"
onload="init();"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<?xul-overlay href="metadataPane.xul"?>
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
<script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>
@ -116,7 +118,7 @@
<vbox flex="4" persist="width">
<tree
id="items-tree"
enablecolumndrag="true"
enableColumnDrag="true"
onselect="itemSelected();"
persist="height" flex="1">
@ -157,12 +159,18 @@
<splitter collapse="after" resizebefore="closest" resizeafter="closest" persist="state">
<grippy/>
</splitter>
<vbox flex="3" persist="height">
<toolbar>
<toolbarbutton label="hello"/>
</toolbar>
<iframe id="view-pane" src="" type="content" flex="1"/>
</vbox>
<tabbox id="item-tabs" flex="3" persist="height" hidden="true">
<tabs onselect="itemSelected();">
<tab label="Item"/>
<tab label="Metadata"/>
<tab label="Notes"/>
</tabs>
<tabpanels flex="1">
<iframe id="view-pane" src="" type="content" flex="1"/>
<vbox id="metadata-pane"/>
<tabpanel/>
</tabpanels>
</tabbox>
</vbox>
</hbox>
<statusbar id="statusbar">