From b94cf81ba38abd974b57e55480b5440a0eecfe06 Mon Sep 17 00:00:00 2001 From: David Norton Date: Mon, 26 Jun 2006 13:54:05 +0000 Subject: [PATCH] Trying this again: Fixes #22, #26, #79, #71 Added remove note button, removed some old code. --- .../chromeFiles/content/scholar/itemPane.js | 85 +++++-------------- .../chromeFiles/content/scholar/itemPane.xul | 1 + 2 files changed, 22 insertions(+), 64 deletions(-) diff --git a/chrome/chromeFiles/content/scholar/itemPane.js b/chrome/chromeFiles/content/scholar/itemPane.js index e3fc29656..7c6dd4ff5 100644 --- a/chrome/chromeFiles/content/scholar/itemPane.js +++ b/chrome/chromeFiles/content/scholar/itemPane.js @@ -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()+"¬e="+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()+"¬e="+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); diff --git a/chrome/chromeFiles/content/scholar/itemPane.xul b/chrome/chromeFiles/content/scholar/itemPane.xul index aff8d278f..ac5c35411 100644 --- a/chrome/chromeFiles/content/scholar/itemPane.xul +++ b/chrome/chromeFiles/content/scholar/itemPane.xul @@ -36,6 +36,7 @@ +