Trying this again:

Fixes #22, #26, #79, #71

Added remove note button, removed some old code.
This commit is contained in:
David Norton 2006-06-26 13:54:05 +00:00
parent fb9e803ab5
commit b94cf81ba3
2 changed files with 22 additions and 64 deletions

View file

@ -19,10 +19,8 @@ ScholarItemPane = new function()
this.hideEditor = hideEditor;
this.modifyField = modifyField;
this.modifyCreator = modifyCreator;
this.modifySelectedNote = modifySelectedNote;
this.removeSelectedNote = removeSelectedNote;
this.removeNote = removeNote;
this.addNote = addNote;
this.onNoteSelected = onNoteSelected;
function onLoad()
{
@ -115,12 +113,26 @@ ScholarItemPane = new function()
{
for(var i = 0; i < notes.length; i++)
{
var row = document.createElement('row');
var icon = document.createElement('image');
icon.setAttribute('src','chrome://scholar/skin/treeitem-note.png');
var button = document.createElement('label');
button.setAttribute('value',_noteToTitle(_itemBeingEdited.getNote(notes[i])));
button.setAttribute('onclick',"window.open('chrome://scholar/content/note.xul?item="+_itemBeingEdited.getID()+"&note="+notes[i]+"','','chrome,resizable,centerscreen');");
button.setAttribute('class','clicky')
row.appendChild(button);
box = document.createElement('box');
box.setAttribute('onclick',"window.open('chrome://scholar/content/note.xul?item="+_itemBeingEdited.getID()+"&note="+notes[i]+"','','chrome,resizable,centerscreen');");
box.setAttribute('class','clicky');
box.appendChild(icon);
box.appendChild(button);
var removeButton = document.createElement('label');
removeButton.setAttribute("value","-");
removeButton.setAttribute("class","clicky");
removeButton.setAttribute("onclick","ScholarItemPane.removeNote("+notes[i]+")");
var row = document.createElement('row');
row.appendChild(box);
row.appendChild(removeButton);
_notesList.appendChild(row);
}
@ -298,52 +310,14 @@ ScholarItemPane = new function()
_itemBeingEdited.save();
}
function modifySelectedNote()
function removeNote(id)
{
if(_notesMenu.selectedIndex == -1)
return;
var id = _selectedNoteID();
if(id)
{
_itemBeingEdited.updateNote(id,_notesField.value);
}
else if(_notesField.value)//new note
{
id = _itemBeingEdited.addNote(_notesField.value);
_notesMenu.selectedItem.setAttribute('value',id);
}
var label = _noteToTitle(_notesField.value);
_notesMenu.selectedItem.label = label; //sets the individual item label
_notesMenu.setAttribute('label', label); //sets the 'overall' label of the menu... not usually updated unless the item is reselected
}
function removeSelectedNote()
{
if(_notesField.value != "")
if(_itemBeingEdited.getNote(id) != "")
if(!confirm(Scholar.getString('pane.item.notes.delete.confirm')))
return;
var id = _selectedNoteID();
if(id)
{
_itemBeingEdited.removeNote(id);
}
var oldIndex = _notesMenu.selectedIndex;
_notesMenu.removeItemAt(oldIndex);
_notesMenu.selectedIndex = Math.max(oldIndex-1,0);
if(_notesMenu.firstChild.childNodes.length == 0)
{
addNote();
}
else
{
onNoteSelected();
_updateNoteCount();
}
}
function addNote()
@ -351,18 +325,6 @@ ScholarItemPane = new function()
window.open("chrome://scholar/content/note.xul?item="+_itemBeingEdited.getID(),'','chrome,resizable,centerscreen');
}
function onNoteSelected()
{
var id = _selectedNoteID();
Scholar.debug(id);
if(id)
_notesField.value = _itemBeingEdited.getNote(id);
else
_notesField.value = "";
}
function _noteToTitle(text)
{
var MAX_LENGTH = 100;
@ -390,11 +352,6 @@ ScholarItemPane = new function()
_notesLabel.value = Scholar.getString('pane.item.notes.count.'+(c != 1 ? "plural" : "singular")).replace('%1',c) + ":";
}
function _selectedNoteID()
{
return _notesMenu.selectedItem.getAttribute('value'); //for some reason, selectedItem.value is null sometimes.
}
}
addEventListener("load", function(e) { ScholarItemPane.onLoad(e); }, false);

View file

@ -36,6 +36,7 @@
<grid flex="1">
<columns>
<column flex="1"/>
<column/>
</columns>
<rows id="editpane-dynamic-notes" flex="1"/>
</grid>