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.hideEditor = hideEditor;
this.modifyField = modifyField; this.modifyField = modifyField;
this.modifyCreator = modifyCreator; this.modifyCreator = modifyCreator;
this.modifySelectedNote = modifySelectedNote; this.removeNote = removeNote;
this.removeSelectedNote = removeSelectedNote;
this.addNote = addNote; this.addNote = addNote;
this.onNoteSelected = onNoteSelected;
function onLoad() function onLoad()
{ {
@ -115,12 +113,26 @@ ScholarItemPane = new function()
{ {
for(var i = 0; i < notes.length; i++) 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'); var button = document.createElement('label');
button.setAttribute('value',_noteToTitle(_itemBeingEdited.getNote(notes[i]))); 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') box = document.createElement('box');
row.appendChild(button); 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); _notesList.appendChild(row);
} }
@ -298,52 +310,14 @@ ScholarItemPane = new function()
_itemBeingEdited.save(); _itemBeingEdited.save();
} }
function modifySelectedNote() function removeNote(id)
{ {
if(_notesMenu.selectedIndex == -1) if(_itemBeingEdited.getNote(id) != "")
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(!confirm(Scholar.getString('pane.item.notes.delete.confirm'))) if(!confirm(Scholar.getString('pane.item.notes.delete.confirm')))
return; return;
var id = _selectedNoteID();
if(id) if(id)
{
_itemBeingEdited.removeNote(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() function addNote()
@ -351,18 +325,6 @@ ScholarItemPane = new function()
window.open("chrome://scholar/content/note.xul?item="+_itemBeingEdited.getID(),'','chrome,resizable,centerscreen'); 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) function _noteToTitle(text)
{ {
var MAX_LENGTH = 100; 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) + ":"; _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); addEventListener("load", function(e) { ScholarItemPane.onLoad(e); }, false);

View File

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