New editing pane. Lots of smaller bugs.
ScholarLocalizedStrings moved out of sidebar.js and into Scholar.LocalizedStrings Rudimentary creator adding/editing. lots of things to work on, because it doesn't work.
This commit is contained in:
parent
deea149235
commit
3ad618f6df
8 changed files with 238 additions and 91 deletions
155
chrome/chromeFiles/content/scholar/editpane.js
Normal file
155
chrome/chromeFiles/content/scholar/editpane.js
Normal file
|
@ -0,0 +1,155 @@
|
|||
Scholar.EditPane = new function()
|
||||
{
|
||||
var _editpane;
|
||||
var _dynamicFields;
|
||||
var _dynamicCreators;
|
||||
var _itemBeingEdited;
|
||||
var _creatorTypes = Scholar.CreatorTypes.getTypes();
|
||||
|
||||
this.init = init;
|
||||
this.editItem = editItem;
|
||||
this.close = close;
|
||||
this.addCreator = addCreator;
|
||||
|
||||
function init()
|
||||
{
|
||||
_editpane = document.getElementById('editpane');
|
||||
_dynamicFields = document.getElementById('editpane-dynamic-fields');
|
||||
_dynamicCreators = document.getElementById('editpane-dynamic-creators');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function editItem(thisItem)
|
||||
{
|
||||
|
||||
_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)
|
||||
{
|
||||
//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 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);
|
||||
}
|
||||
|
||||
if(!_itemBeingEdited.getID()) //NEW ITEM
|
||||
{
|
||||
/* get ref to myTreeView?
|
||||
myTreeView._showItem(_itemBeingEdited, 0, myTreeView.rowCount);
|
||||
myTreeView._treebox.rowCountChanged(myTreeView.rowCount-1,1);
|
||||
*/
|
||||
}
|
||||
|
||||
_itemBeingEdited.save();
|
||||
|
||||
|
||||
}
|
||||
_itemBeingEdited = null;
|
||||
|
||||
_editpane.hidden = true;
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
var row = document.createElement("row");
|
||||
row.appendChild(first);
|
||||
row.appendChild(last);
|
||||
row.appendChild(type);
|
||||
row.appendChild(remove);
|
||||
_dynamicCreators.appendChild(row);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("load", function(e) { Scholar.EditPane.init(e); }, false);
|
41
chrome/chromeFiles/content/scholar/editpane.xul
Normal file
41
chrome/chromeFiles/content/scholar/editpane.xul
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?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">
|
||||
<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>
|
|
@ -14,7 +14,7 @@ var Scholar = new function(){
|
|||
var _initialized = false
|
||||
|
||||
this.testString = 'Sidebar is not registered';
|
||||
|
||||
this.LocalizedStrings;
|
||||
this.init = init;
|
||||
this.debug = debug;
|
||||
this.varDump = varDump;
|
||||
|
@ -26,6 +26,8 @@ var Scholar = new function(){
|
|||
* Initialize the extension
|
||||
*/
|
||||
function init(){
|
||||
this.LocalizedStrings = document.getElementById('scholar-strings');
|
||||
|
||||
if (!_initialized){
|
||||
Scholar.DB.updateSchema();
|
||||
_initialized = true;
|
||||
|
|
|
@ -4,34 +4,39 @@
|
|||
|
||||
<overlay id="scholar"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<?xul-overlay href="editpane.xul" ?>
|
||||
|
||||
<script src="scholar.js"/>
|
||||
<script src="db.js"/>
|
||||
<script src="data_access.js"/>
|
||||
|
||||
<stringbundleset id="stringbundleset">
|
||||
<stringbundle id="scholar-strings" src="chrome://scholar/locale/scholar.properties"/>
|
||||
</stringbundleset>
|
||||
|
||||
<statusbar id="status-bar">
|
||||
<statusbarpanel onclick="alert(Scholar.testString)" id="my-panel" label="&statusbarpanel.helloworld;"/>
|
||||
</statusbar>
|
||||
|
||||
<menupopup id="viewSidebarMenu">
|
||||
<menuitem key="key_openScholarSidebar" observes="viewScholarSidebar" />
|
||||
</menupopup>
|
||||
<menupopup id="viewSidebarMenu">
|
||||
<menuitem key="key_openScholarSidebar" observes="viewScholarSidebar" />
|
||||
</menupopup>
|
||||
|
||||
<keyset id="mainKeyset">
|
||||
<key id="key_openScholarSidebar" command="viewScholarSidebar"
|
||||
key="S"
|
||||
modifiers="shift accel" />
|
||||
</keyset>
|
||||
<keyset id="mainKeyset">
|
||||
<key id="key_openScholarSidebar" command="viewScholarSidebar"
|
||||
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>
|
||||
|
||||
<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>
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
var ScholarLocalizedStrings;
|
||||
var myTreeView;
|
||||
var dynamicBox;
|
||||
var itemBeingEdited; //the item currently being edited
|
||||
|
@ -192,7 +191,7 @@ function viewSelectedItem()
|
|||
if(thisItem.getField(fieldNames[i]) != "")
|
||||
{
|
||||
var label = document.createElement("label");
|
||||
label.setAttribute("value",ScholarLocalizedStrings.getString("itemFields."+fieldNames[i])+":");
|
||||
label.setAttribute("value",Scholar.LocalizedStrings.getString("itemFields."+fieldNames[i])+":");
|
||||
|
||||
var valueElement = document.createElement("description");
|
||||
valueElement.appendChild(document.createTextNode(thisItem.getField(fieldNames[i])));
|
||||
|
@ -229,44 +228,13 @@ function viewSelectedItem()
|
|||
|
||||
function newItem(typeID)
|
||||
{
|
||||
editItem(Scholar.Items.getNewItemByType(typeID));
|
||||
Scholar.EditPane.editItem(Scholar.Items.getNewItemByType(typeID));
|
||||
}
|
||||
|
||||
function editSelectedItem()
|
||||
{
|
||||
editItem(myTreeView._getItemAtRow(myTreeView.selection.currentIndex));
|
||||
}
|
||||
|
||||
function editItem(thisItem)
|
||||
{
|
||||
document.getElementById('list-pane').hidden = true;
|
||||
document.getElementById('edit-pane').hidden = false;
|
||||
|
||||
removeDynamicRows(dynamicBox);
|
||||
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",ScholarLocalizedStrings.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);
|
||||
dynamicBox.appendChild(row);
|
||||
}
|
||||
}
|
||||
|
||||
itemBeingEdited = thisItem;
|
||||
Scholar.EditPane.editItem(myTreeView._getItemAtRow(myTreeView.selection.currentIndex));
|
||||
// editItem(myTreeView._getItemAtRow(myTreeView.selection.currentIndex));
|
||||
}
|
||||
|
||||
function removeDynamicRows(box)
|
||||
|
@ -284,35 +252,10 @@ function getFullFieldList(item)
|
|||
return fieldNames;
|
||||
}
|
||||
|
||||
function returnToTree(save)
|
||||
{
|
||||
if(save)
|
||||
{
|
||||
//get fields, call data access methods
|
||||
var valueElements = dynamicBox.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);
|
||||
|
||||
if(!itemBeingEdited.getID())
|
||||
{
|
||||
myTreeView._showItem(itemBeingEdited, 0, myTreeView.rowCount);
|
||||
myTreeView._treebox.rowCountChanged(myTreeView.rowCount-1,1);
|
||||
}
|
||||
|
||||
itemBeingEdited.save();
|
||||
}
|
||||
itemBeingEdited = null;
|
||||
|
||||
document.getElementById('list-pane').hidden = false;
|
||||
document.getElementById('edit-pane').hidden = true;
|
||||
|
||||
viewSelectedItem();
|
||||
}
|
||||
|
||||
function init()
|
||||
{
|
||||
myTreeView = new Scholar.TreeView();
|
||||
ScholarLocalizedStrings = document.getElementById('scholar-strings');
|
||||
|
||||
dynamicBox = document.getElementById('dynamic-fields');
|
||||
|
||||
var addMenu = document.getElementById('tb-add').firstChild;
|
||||
|
@ -320,7 +263,7 @@ function init()
|
|||
for(var i = 0; i<itemTypes.length; i++)
|
||||
{
|
||||
var menuitem = document.createElement("menuitem");
|
||||
menuitem.setAttribute("label",ScholarLocalizedStrings.getString("itemTypes."+itemTypes[i]['name']));
|
||||
menuitem.setAttribute("label",Scholar.LocalizedStrings.getString("itemTypes."+itemTypes[i]['name']));
|
||||
menuitem.setAttribute("oncommand","newItem("+itemTypes[i]['id']+")");
|
||||
addMenu.appendChild(menuitem);
|
||||
}
|
||||
|
|
|
@ -52,7 +52,6 @@
|
|||
<toolbarbutton id="tb-edit" label="Edit…" oncommand="editSelectedItem();" hidden="true"/>
|
||||
</sidebarheader>
|
||||
</vbox>
|
||||
|
||||
|
||||
<vbox id="view-pane">
|
||||
<grid>
|
||||
|
@ -65,9 +64,4 @@
|
|||
</rows>
|
||||
</grid>
|
||||
</vbox>
|
||||
|
||||
<hbox id="edit-pane" hidden="true">
|
||||
<button label="Cancel" oncommand="returnToTree(false)"/>
|
||||
<button label="Save" oncommand="returnToTree(true)"/>
|
||||
</hbox>
|
||||
</page>
|
|
@ -16,6 +16,9 @@ itemFields.ISBN = ISBN
|
|||
itemFields.publication = Publication
|
||||
itemFields.ISSN = ISSN
|
||||
|
||||
|
||||
itemTypes.book = Book
|
||||
itemTypes.journalArticle = Journal Article
|
||||
itemTypes.journalArticle = Journal Article
|
||||
|
||||
creatorTypes.author = Author
|
||||
creatorTypes.contributor = Contributor
|
||||
creatorTypes.editor = Editor
|
|
@ -1,3 +1,7 @@
|
|||
#scholar-sidebar-object-pane-dynamic-fields label {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#editpane {
|
||||
background-color: rgb(239, 248, 206);
|
||||
}
|
Loading…
Reference in a new issue