Upgraded Scholar window to work more correctly (thanks Mozilla Bookmarks Manager!)
Removed sidebar, editpane for now.
This commit is contained in:
parent
a78715cf5c
commit
4a7412560e
8 changed files with 110 additions and 637 deletions
|
@ -1,181 +0,0 @@
|
|||
Scholar.EditPane = new function()
|
||||
{
|
||||
var _editpane;
|
||||
var _dynamicFields;
|
||||
var _dynamicCreators;
|
||||
var _itemBeingEdited;
|
||||
var _creatorTypes = Scholar.CreatorTypes.getTypes();
|
||||
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
|
||||
|
||||
this.init = init;
|
||||
this.editItem = editItem;
|
||||
this.close = close;
|
||||
this.addCreator = addCreator;
|
||||
this.removeCreator = removeCreator;
|
||||
|
||||
function init()
|
||||
{
|
||||
_editpane = document.getElementById('editpane');
|
||||
_dynamicFields = document.getElementById('editpane-dynamic-fields');
|
||||
_dynamicCreators = document.getElementById('editpane-dynamic-creators');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function editItem(thisItem)
|
||||
{
|
||||
if(!_editpane.hidden)
|
||||
{
|
||||
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)
|
||||
saveItem();
|
||||
|
||||
}
|
||||
_editpane.hidden = false;
|
||||
|
||||
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.LocalizedStrings.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
|
||||
|
||||
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 close(save)
|
||||
{
|
||||
if(save)
|
||||
saveItem();
|
||||
|
||||
_itemBeingEdited = null;
|
||||
|
||||
_editpane.hidden = 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.LocalizedStrings.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","Scholar.EditPane.removeCreator(this.parentNode);");
|
||||
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) { Scholar.EditPane.init(e); }, false);
|
|
@ -1,41 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://scholar/skin/scholar.css" type="text/css"?>
|
||||
<!DOCTYPE window SYSTEM "chrome://scholar/locale/scholar.dtd">
|
||||
|
||||
<overlay id="editpane-overlay"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<script src="editpane.js"/>
|
||||
<vbox id="appcontent">
|
||||
<vbox id="editpane" hidden="true" position="1">
|
||||
<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>
|
||||
<sidebarheader>
|
||||
<spacer flex="1" />
|
||||
<toolbarbutton id="tb-creator-add" label="Add Creator" oncommand="Scholar.EditPane.addCreator()"/>
|
||||
</sidebarheader>
|
||||
<hbox>
|
||||
<button label="Cancel" oncommand="Scholar.EditPane.close(false)"/>
|
||||
<button label="Save" oncommand="Scholar.EditPane.close(true)"/>
|
||||
</hbox>
|
||||
</vbox>
|
||||
</vbox>
|
||||
</overlay>
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
<overlay id="scholar"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<?xul-overlay href="editpane.xul" ?>
|
||||
|
||||
<script src="overlay.js"/>
|
||||
<script src="db.js"/>
|
||||
|
@ -19,13 +17,9 @@
|
|||
<statusbarpanel onclick="alert(Scholar.testString)" id="my-panel" label="&statusbarpanel.helloworld;"/>
|
||||
</statusbar>
|
||||
|
||||
<menupopup id="viewSidebarMenu">
|
||||
<menuitem observes="viewScholarSidebar" />
|
||||
</menupopup>
|
||||
|
||||
<menupopup id="menu_ToolsPopup">
|
||||
<menuitem id="tools-scholar"
|
||||
oncommand="open('chrome://scholar/content/scholar.xul','scholar-window','chrome, resizable');" label="Scholar"
|
||||
oncommand="toOpenWindowByType('scholar:window','chrome://scholar/content/scholar.xul');" label="Scholar"
|
||||
key="key_openScholar"/>
|
||||
</menupopup>
|
||||
|
||||
|
@ -34,15 +28,4 @@
|
|||
key="S"
|
||||
modifiers="shift accel" />
|
||||
</keyset>
|
||||
|
||||
<broadcasterset id="mainBroadcasterSet">
|
||||
<broadcaster id="viewScholarSidebar"
|
||||
label="Scholar"
|
||||
autoCheck="false"
|
||||
type="checkbox"
|
||||
group="sidebar"
|
||||
sidebarurl="chrome://scholar/content/sidebar.xul"
|
||||
sidebartitle="Scholar"
|
||||
oncommand="toggleSidebar('viewScholarSidebar');" />
|
||||
</broadcasterset>
|
||||
</overlay>
|
|
@ -57,7 +57,6 @@ function deleteSelection()
|
|||
{
|
||||
if(itemsView && itemsView.selection.count > 0 && confirm("Are you sure you want to delete the selection????"))
|
||||
{
|
||||
//either determine focus or just delete from items...
|
||||
alert("delete not quite implemented yet");
|
||||
itemsView.deleteSelection();
|
||||
}
|
||||
}
|
|
@ -1,16 +1,24 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
<?xul-overlay href="chrome://global/content/editMenuOverlay.xul"?>
|
||||
<?xul-overlay href="chrome://browser/content/baseMenuOverlay.xul"?>
|
||||
<!DOCTYPE window SYSTEM "chrome://scholar/locale/scholar.dtd">
|
||||
|
||||
<window
|
||||
id="scholar-window"
|
||||
title="Scholar"
|
||||
orient="vertical"
|
||||
width="1000"
|
||||
height="700"
|
||||
width="1000" height="700" screenX="20" screenY="20"
|
||||
persist="width height screenX screenY sizemode"
|
||||
windowtype="scholar:window"
|
||||
onload="Scholar.init(); init();"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
|
||||
<script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>
|
||||
<script type="application/x-javascript" src="chrome://global/content/nsTransferable.js"/>
|
||||
<script type="application/x-javascript" src="chrome://browser/content/utilityOverlay.js"/>
|
||||
|
||||
<!-- Include these until we get a global XPCOM object: -->
|
||||
<script src="overlay.js"/>
|
||||
<script src="db.js"/>
|
||||
|
@ -19,76 +27,125 @@
|
|||
<script src="scholar.js"/>
|
||||
<script src="treeView.js"/>
|
||||
|
||||
<stringbundleset id="stringbundleset"/>
|
||||
<commandset id="baseMenuCommandSet" />
|
||||
<keyset id="baseMenuKeyset" />
|
||||
<keyset id="editMenuKeys"/>
|
||||
|
||||
<stringbundle id="scholar-strings" src="chrome://scholar/locale/scholar.properties"/>
|
||||
|
||||
<command id="cmd_close" oncommand="closeWindow(true);"/>
|
||||
<command id="cmd_scholar_newItem" oncommand="newItem(1);"/>
|
||||
<command id="cmd_scholar_newFolder" oncommand="newFolder();"/>
|
||||
|
||||
<keyset>
|
||||
<key id="delete-cmd" keycode="VK_DELETE" oncommand="deleteSelection()"/>
|
||||
<key id="backspace-cmd" keycode="VK_BACK" oncommand="deleteSelection()"/>
|
||||
<key id="key_close" key="&closeCmd.commandkey;" modifiers="accel" command="cmd_close"/>
|
||||
</keyset>
|
||||
|
||||
<toolbox>
|
||||
<menubar id="main-menubar">
|
||||
<menu label="&fileMenu.label;" accesskey="&fileMenu.accesskey;">
|
||||
<menupopup>
|
||||
<menuitem label="&menuitem.newItem.label;"
|
||||
accesskey="&menuitem.newItem.accesskey;"
|
||||
command="cmd_scholar_newItem"/>
|
||||
<menuitem label="&menuitem.newFolder.label;"
|
||||
accesskey="&menuitem.newFolder.accesskey;"
|
||||
command="cmd_scholar_newFolder"/>
|
||||
<menuitem label="&closeCmd.label;" command="cmd_close"
|
||||
key="key_close" accesskey="&closeCmd.accesskey;"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
|
||||
<menu id="menu_edit">
|
||||
<menupopup>
|
||||
<menuitem id="menu_undo"/>
|
||||
<menuitem id="menu_redo"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="menu_cut"/>
|
||||
<menuitem id="menu_copy"/>
|
||||
<menuitem id="menu_paste"/>
|
||||
<menuitem id="menu_delete"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="menu_selectAll"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
<menu id="windowMenu"/>
|
||||
<menupopup id="menu_ToolsPopup"/>
|
||||
#endif
|
||||
<menu id="helpMenu"/>
|
||||
</menubar>
|
||||
|
||||
<toolbar>
|
||||
<toolbarbutton label="&menuitem.newFolder.label;" command="cmd_scholar_newFolder"/>
|
||||
<toolbarbutton id="tb-add" label="&menuitem.newItem.label;" type="menu">
|
||||
<menupopup>
|
||||
</menupopup>
|
||||
</toolbarbutton>
|
||||
</toolbar>
|
||||
<toolbar>
|
||||
<label value="Search:" control="tb-search"/>
|
||||
<textbox id="tb-search" type="timed" timeout="500" flex="1"/>
|
||||
</toolbar>
|
||||
</toolbox>
|
||||
|
||||
<hbox flex="1">
|
||||
<vbox id="folders-pane" flex="1">
|
||||
<toolbar>
|
||||
<toolbarbutton label="New Folder..." oncommand="newFolder();"/>
|
||||
<spacer flex="1"/>
|
||||
</toolbar>
|
||||
<separator/>
|
||||
<tree
|
||||
id="folders-tree"
|
||||
treeviewtype="folders"
|
||||
onselect="folderSelected();"
|
||||
persist="width"
|
||||
flex="1">
|
||||
<treecols>
|
||||
<treecol
|
||||
id="name_column"
|
||||
label="Name"
|
||||
label="&folders.name_column;"
|
||||
flex="1"
|
||||
primary="true"/>
|
||||
</treecols>
|
||||
<treechildren/>
|
||||
</tree>
|
||||
</vbox>
|
||||
<splitter collapse="before" resizebefore="closest" resizeafter="closest">
|
||||
<splitter collapse="before" resizebefore="closest" resizeafter="closest" persist="state">
|
||||
<grippy/>
|
||||
</splitter>
|
||||
<vbox flex="4">
|
||||
<toolbar>
|
||||
<toolbarbutton id="tb-add" label="New Item..." type="menu">
|
||||
<menupopup>
|
||||
</menupopup>
|
||||
</toolbarbutton>
|
||||
<spacer flex="1"/>
|
||||
<label control="tb-search" value="Search:"/><textbox id="tb-search" value=""/>
|
||||
</toolbar>
|
||||
<separator/>
|
||||
<vbox flex="4" persist="width">
|
||||
<tree
|
||||
id="items-tree"
|
||||
enablecolumndrag="true"
|
||||
treeviewtype="items"
|
||||
onselect="itemSelected();"
|
||||
persist="height"
|
||||
flex="1">
|
||||
|
||||
<treecols>
|
||||
<treecol
|
||||
id="title_column"
|
||||
label="&sidebar.items.title_column;"
|
||||
label="&items.title_column;"
|
||||
flex="2"/>
|
||||
<splitter class="tree-splitter"/>
|
||||
<treecol
|
||||
id="creator_column"
|
||||
label="&sidebar.items.creator_column;"
|
||||
label="&items.creator_column;"
|
||||
flex="1"/>
|
||||
<splitter class="tree-splitter"/>
|
||||
<treecol
|
||||
id="source_column"
|
||||
label="&sidebar.items.source_column;"
|
||||
label="&items.source_column;"
|
||||
flex="1"/>
|
||||
</treecols>
|
||||
|
||||
<treechildren/>
|
||||
</tree>
|
||||
<splitter collapse="after" resizebefore="closest" resizeafter="closest">
|
||||
<splitter collapse="after" resizebefore="closest" resizeafter="closest" persist="state">
|
||||
<grippy/>
|
||||
</splitter>
|
||||
<tabbox flex="3">
|
||||
<tabbox flex="3" persist="height">
|
||||
<tabs>
|
||||
<tab label="Item" selected="true"/>
|
||||
<tab label="Metadeta"/>
|
||||
|
@ -104,4 +161,7 @@
|
|||
</tabbox>
|
||||
</vbox>
|
||||
</hbox>
|
||||
<statusbar id="statusbar">
|
||||
<statuspanel id="statusbar-text" flex="1"/>
|
||||
</statusbar>
|
||||
</window>
|
|
@ -1,298 +0,0 @@
|
|||
var myTreeView;
|
||||
var dynamicBox;
|
||||
var itemBeingEdited; //the item currently being edited
|
||||
|
||||
Scholar.TreeView = function()
|
||||
{
|
||||
this._treebox = null;
|
||||
this._dataItems = new Array();
|
||||
this.rowCount = 0;
|
||||
}
|
||||
|
||||
Scholar.TreeView.prototype.setTree = function(treebox)
|
||||
{
|
||||
if(this._treebox)
|
||||
return;
|
||||
this._treebox = treebox;
|
||||
|
||||
var newRows = Scholar.Items.getTreeRows();
|
||||
for(var i = 0; i < newRows.length; i++)
|
||||
this._showItem(newRows[i], 0, i+1); //item ref, isContainerOpen, level
|
||||
|
||||
this._refreshHashMap();
|
||||
}
|
||||
|
||||
Scholar.TreeView.prototype.getCellText = function(row, column)
|
||||
{
|
||||
var obj = this._getItemAtRow(row);
|
||||
|
||||
if(obj.isFolder())
|
||||
{
|
||||
if(column.id == "title_column")
|
||||
return obj.getName();
|
||||
else
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
if(column.id == "title_column")
|
||||
return obj.getField("title");
|
||||
else if(column.id == "creator_column")
|
||||
return obj.getField("firstCreator");
|
||||
else
|
||||
return obj.getField("source");
|
||||
}
|
||||
}
|
||||
|
||||
Scholar.TreeView.prototype.isContainer = function(row) { return this._getItemAtRow(row).isFolder(); }
|
||||
Scholar.TreeView.prototype.isContainerOpen = function(row) { return this._dataItems[row][1]; }
|
||||
Scholar.TreeView.prototype.isContainerEmpty = function(row) { return (this.isContainer(row) && this._getItemAtRow(row).isEmpty()); }
|
||||
Scholar.TreeView.prototype.getLevel = function(row) { return this._dataItems[row][2]; }
|
||||
|
||||
Scholar.TreeView.prototype.getParentIndex = function(row)
|
||||
{
|
||||
var thisLevel = this.getLevel(row);
|
||||
if(thisLevel == 0) return -1;
|
||||
for(var i = row - 1; i >= 0; i--)
|
||||
if(this.getLevel(i) < thisLevel)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Scholar.TreeView.prototype.hasNextSibling = function(row, afterIndex)
|
||||
{
|
||||
var thisLevel = this.getLevel(row);
|
||||
for(var i = afterIndex + 1; i < this.rowCount; i++)
|
||||
{
|
||||
var nextLevel = this.getLevel(i);
|
||||
if(nextLevel == thisLevel) return true;
|
||||
else if(nextLevel < thisLevel) return false;
|
||||
}
|
||||
}
|
||||
|
||||
Scholar.TreeView.prototype.toggleOpenState = function(row)
|
||||
{
|
||||
var count = 0; //used to tell the tree how many rows were added/removed
|
||||
var thisLevel = this.getLevel(row);
|
||||
|
||||
this._treebox.beginUpdateBatch();
|
||||
if(this.isContainerOpen(row))
|
||||
{
|
||||
while((row + 1 < this._dataItems.length) && (this.getLevel(row + 1) > thisLevel))
|
||||
{
|
||||
this._hideItem(row+1);
|
||||
count--; //count is negative when closing a container because we are removing rows
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var newRows = Scholar.Items.getTreeRows(this._getItemAtRow(row).getID()); //Get children
|
||||
|
||||
for(var i = 0; i < newRows.length; i++)
|
||||
{
|
||||
count++;
|
||||
this._showItem(newRows[i], thisLevel+1, row+i+1); //insert new row
|
||||
}
|
||||
}
|
||||
this._dataItems[row][1] = !this._dataItems[row][1]; //toggle container open value
|
||||
|
||||
this._treebox.rowCountChanged(row+1, count); //tell treebox to repaint these
|
||||
this._treebox.invalidateRow(row);
|
||||
this._treebox.endUpdateBatch();
|
||||
this._refreshHashMap();
|
||||
}
|
||||
|
||||
Scholar.TreeView.prototype.selectionChanged = function()
|
||||
{
|
||||
if(this.selection.count == 1 && this.selection.currentIndex != -1 && !this.isContainer(this.selection.currentIndex))
|
||||
{
|
||||
viewSelectedItem();
|
||||
document.getElementById('tb-edit').hidden = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
removeDynamicRows(dynamicBox);
|
||||
document.getElementById('tb-edit').hidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Scholar.TreeView.prototype._showItem = function(item, level, beforeRow) { this._dataItems.splice(beforeRow, 0, [item, false, level]); this.rowCount++; }
|
||||
|
||||
Scholar.TreeView.prototype._hideItem = function(row) { this._dataItems.splice(row,1); this.rowCount--; }
|
||||
|
||||
Scholar.TreeView.prototype._getItemAtRow = function(row) { return this._dataItems[row][0]; }
|
||||
Scholar.TreeView.prototype.isSorted = function() { return false; }
|
||||
Scholar.TreeView.prototype.isSeparator = function(row) { return false; }
|
||||
Scholar.TreeView.prototype.isEditable = function(row, idx) { return false; }
|
||||
Scholar.TreeView.prototype.getRowProperties = function(row, prop) { }
|
||||
Scholar.TreeView.prototype.getColumnProperties = function(col, prop) { }
|
||||
Scholar.TreeView.prototype.getCellProperties = function(row, col, prop) { }
|
||||
Scholar.TreeView.prototype.getImageSrc = function(row, col) { }
|
||||
Scholar.TreeView.prototype.performAction = function(action) { }
|
||||
Scholar.TreeView.prototype.performActionOnCell = function(action, row, col) { }
|
||||
Scholar.TreeView.prototype.getProgressMode = function(row, col) { }
|
||||
|
||||
Scholar.TreeView.prototype.deleteSelection = function()
|
||||
{
|
||||
if(this.selection.count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(!confirm("Are you sure you want to delete the selected item"+(this.selection.count > 1 ? "s" : "")+"?"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//collapse open folders
|
||||
for(var i=0; i<this.rowCount; i++)
|
||||
{
|
||||
if(this.selection.isSelected(i) && this.isContainer(i) && this.isContainerOpen(i))
|
||||
this.toggleOpenState(i);
|
||||
}
|
||||
|
||||
//create an array of selected items/folders
|
||||
var rows = new Array();
|
||||
var start = new Object();
|
||||
var end = new Object();
|
||||
for (var i=0, len=this.selection.getRangeCount(); i<len; i++)
|
||||
{
|
||||
this.selection.getRangeAt(i,start,end);
|
||||
for (var j=start.value; j<=end.value; j++)
|
||||
rows.push(j);
|
||||
}
|
||||
|
||||
//iterate and erase...
|
||||
this._treebox.beginUpdateBatch();
|
||||
for (var i=0; i<rows.length; i++)
|
||||
{
|
||||
this._getItemAtRow(rows[i]-i).erase(); //erases item/folder from DB
|
||||
|
||||
//remove row from tree
|
||||
this._hideItem(rows[i]-i);
|
||||
this._treebox.rowCountChanged(rows[i]-i, -1);
|
||||
}
|
||||
this._treebox.endUpdateBatch();
|
||||
|
||||
this._refreshHashMap();
|
||||
}
|
||||
|
||||
Scholar.TreeView.prototype._refreshHashMap = function()
|
||||
{
|
||||
// Create hash map of folder and object ids to row indexes
|
||||
// Author: Dan Stillman
|
||||
|
||||
this._itemRowMap = new Array();
|
||||
this._folderRowMap = new Array();
|
||||
for(var i=0; i < this.rowCount; i++){
|
||||
if (this.isContainer(i)){
|
||||
this._folderRowMap[this._getItemAtRow(i).getID()] = i;
|
||||
}
|
||||
else {
|
||||
this._itemRowMap[this._getItemAtRow(i).getID()] = i;
|
||||
}
|
||||
}
|
||||
//Scholar.debug(Scholar.varDump(this.folderRowMap));
|
||||
//Scholar.debug(Scholar.varDump(this.objectRowMap));
|
||||
|
||||
}
|
||||
/*
|
||||
DRAG AND DROP (IMPLEMENT LATER)
|
||||
Scholar.DragObserver.canDrop = function(row, orient) { return !orient; }
|
||||
Scholar.DragObserver.drop = function(row, orient) { }
|
||||
*/
|
||||
|
||||
function viewSelectedItem()
|
||||
{
|
||||
removeDynamicRows(dynamicBox);
|
||||
|
||||
var thisItem = myTreeView._getItemAtRow(myTreeView.selection.currentIndex);
|
||||
|
||||
var fieldNames = getFullFieldList(thisItem);
|
||||
|
||||
for(var i = 0; i<fieldNames.length; i++)
|
||||
{
|
||||
if(thisItem.getField(fieldNames[i]) != "")
|
||||
{
|
||||
var label = document.createElement("label");
|
||||
label.setAttribute("value",Scholar.LocalizedStrings.getString("itemFields."+fieldNames[i])+":");
|
||||
|
||||
var valueElement = document.createElement("description");
|
||||
valueElement.appendChild(document.createTextNode(thisItem.getField(fieldNames[i])));
|
||||
|
||||
var row = document.createElement("row");
|
||||
row.appendChild(label);
|
||||
row.appendChild(valueElement);
|
||||
row.setAttribute("id","dynamic-"+fieldNames[i]);
|
||||
|
||||
dynamicBox.appendChild(row);
|
||||
}
|
||||
}
|
||||
|
||||
var beforeField = dynamicBox.firstChild.nextSibling;
|
||||
|
||||
for (var i=0,len=thisItem.numCreators(); i<len; i++)
|
||||
{
|
||||
var creator = thisItem.getCreator(i);
|
||||
|
||||
var label = document.createElement("label");
|
||||
label.setAttribute("value","Creator:");
|
||||
|
||||
var valueElement = document.createElement("description");
|
||||
valueElement.appendChild(document.createTextNode(creator.lastName+", "+creator.firstName));
|
||||
|
||||
var row = document.createElement("row");
|
||||
row.appendChild(label);
|
||||
row.appendChild(valueElement);
|
||||
|
||||
dynamicBox.insertBefore(row, beforeField);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function newItem(typeID)
|
||||
{
|
||||
Scholar.EditPane.editItem(Scholar.Items.getNewItemByType(typeID));
|
||||
}
|
||||
|
||||
function editSelectedItem()
|
||||
{
|
||||
Scholar.EditPane.editItem(myTreeView._getItemAtRow(myTreeView.selection.currentIndex));
|
||||
// editItem(myTreeView._getItemAtRow(myTreeView.selection.currentIndex));
|
||||
}
|
||||
|
||||
function removeDynamicRows(box)
|
||||
{
|
||||
while(box.hasChildNodes())
|
||||
box.removeChild(box.firstChild);
|
||||
}
|
||||
|
||||
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 init()
|
||||
{
|
||||
myTreeView = new Scholar.TreeView();
|
||||
|
||||
dynamicBox = document.getElementById('dynamic-fields');
|
||||
|
||||
var addMenu = document.getElementById('tb-add').firstChild;
|
||||
var itemTypes = Scholar.ItemTypes.getTypes();
|
||||
for(var i = 0; i<itemTypes.length; i++)
|
||||
{
|
||||
var menuitem = document.createElement("menuitem");
|
||||
menuitem.setAttribute("label",Scholar.LocalizedStrings.getString("itemTypes."+itemTypes[i]['name']));
|
||||
menuitem.setAttribute("oncommand","newItem("+itemTypes[i]['id']+")");
|
||||
addMenu.appendChild(menuitem);
|
||||
}
|
||||
|
||||
document.getElementById('list-tree').view=myTreeView;
|
||||
}
|
||||
|
||||
Scholar.testString = 'Sidebar is registered.';
|
|
@ -1,67 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin/" type"text/css"?>
|
||||
<?xml-stylesheet href="chrome://browser/skin/browser.css" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://scholar/skin/scholar.css" type="text/css"?>
|
||||
<!DOCTYPE window SYSTEM "chrome://scholar/locale/scholar.dtd">
|
||||
|
||||
<page id="scholar-sidebar" title="Scholar"
|
||||
onload="init()"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" >
|
||||
|
||||
<script src="include.js"/>
|
||||
<script src="sidebar.js"/>
|
||||
<keyset>
|
||||
<key id="delete-cmd" keycode="VK_DELETE" oncommand="myTreeView.deleteSelection()"/>
|
||||
<key id="backspace-cmd" keycode="VK_BACK" oncommand="myTreeView.deleteSelection()"/>
|
||||
</keyset>
|
||||
<stringbundle id="scholar-strings" src="chrome://scholar/locale/scholar.properties"/>
|
||||
<vbox id="list-pane" flex="1">
|
||||
<tree
|
||||
id="list-tree"
|
||||
onselect="this.view.selectionChanged()"
|
||||
enableColumnDrag="true"
|
||||
seltype="multiple" flex="1">
|
||||
|
||||
<treecols>
|
||||
<treecol
|
||||
id="title_column"
|
||||
label="&sidebar.items.title_column;"
|
||||
flex="2"
|
||||
primary="true"/>
|
||||
<splitter class="tree-splitter"/>
|
||||
<treecol
|
||||
id="creator_column"
|
||||
label="&sidebar.items.creator_column;"
|
||||
flex="1"
|
||||
hidden="true"/>
|
||||
<splitter class="tree-splitter"/>
|
||||
<treecol
|
||||
id="source_column"
|
||||
label="&sidebar.items.source_column;"
|
||||
flex="1"
|
||||
hidden="true"/>
|
||||
</treecols>
|
||||
<treechildren/>
|
||||
</tree>
|
||||
<sidebarheader>
|
||||
<toolbarbutton id="tb-add" type="menu" label="New…">
|
||||
<menupopup>
|
||||
</menupopup>
|
||||
</toolbarbutton>
|
||||
<spacer flex="1" />
|
||||
<toolbarbutton id="tb-edit" label="Edit…" oncommand="editSelectedItem();" hidden="true"/>
|
||||
</sidebarheader>
|
||||
</vbox>
|
||||
|
||||
<vbox id="view-pane">
|
||||
<grid>
|
||||
<columns>
|
||||
<column/>
|
||||
<column flex="1"/>
|
||||
</columns>
|
||||
|
||||
<rows id="dynamic-fields">
|
||||
</rows>
|
||||
</grid>
|
||||
</vbox>
|
||||
</page>
|
|
@ -1,8 +1,26 @@
|
|||
<!ENTITY statusbarpanel.helloworld "Hello, World">
|
||||
|
||||
<!ENTITY sidebar.items.title_column "Title">
|
||||
<!ENTITY sidebar.items.creator_column "Creator">
|
||||
<!ENTITY sidebar.items.source_column "Source">
|
||||
<!ENTITY sidebar.creators.firstname_column "First name">
|
||||
<!ENTITY sidebar.creators.lastname_column "Last name">
|
||||
<!ENTITY sidebar.creators.type_column "Type">
|
||||
<!ENTITY items.title_column "Title">
|
||||
<!ENTITY items.creator_column "Creator">
|
||||
<!ENTITY items.source_column "Source">
|
||||
|
||||
<!ENTITY folders.name_column "Name">
|
||||
|
||||
<!ENTITY creators.firstname "First name">
|
||||
<!ENTITY creators.lastname "Last name">
|
||||
<!ENTITY creators.type "Type">
|
||||
|
||||
<!ENTITY fileMenu.label "File">
|
||||
<!ENTITY fileMenu.accesskey "F">
|
||||
<!ENTITY viewMenu.label "View">
|
||||
<!ENTITY viewMenu.accesskey "V">
|
||||
|
||||
<!ENTITY menuitem.newItem.label "New Item...">
|
||||
<!ENTITY menuitem.newItem.accesskey "n">
|
||||
<!ENTITY menuitem.newFolder.label "New Folder...">
|
||||
<!ENTITY menuitem.newFolder.accesskey "o">
|
||||
|
||||
|
||||
<!ENTITY closeCmd.label "Close">
|
||||
<!ENTITY closeCmd.accesskey "C">
|
||||
<!ENTITY closeCmd.commandkey "W">
|
Loading…
Reference in a new issue