Fixed hierarchical viewing of notes. (Standalone notes not very well supported yet). Please post bugs to Trac (component: interface)

This commit is contained in:
David Norton 2006-06-27 20:37:02 +00:00
parent 22296470c3
commit 711a277173
5 changed files with 71 additions and 85 deletions

View File

@ -43,7 +43,8 @@ ScholarItemPane = new function()
var itemTypes = Scholar.ItemTypes.getTypes(); var itemTypes = Scholar.ItemTypes.getTypes();
for(var i = 0; i<itemTypes.length; i++) for(var i = 0; i<itemTypes.length; i++)
_itemTypeMenu.appendItem(Scholar.getString("itemTypes."+itemTypes[i]['name']),itemTypes[i]['id']); if(itemTypes[i]['id'] != 1)
_itemTypeMenu.appendItem(Scholar.getString("itemTypes."+itemTypes[i]['name']),itemTypes[i]['id']);
return true; return true;
} }
@ -108,7 +109,7 @@ ScholarItemPane = new function()
while(_notesList.hasChildNodes()) while(_notesList.hasChildNodes())
_notesList.removeChild(_notesList.firstChild); _notesList.removeChild(_notesList.firstChild);
var notes = _itemBeingEdited.getNotes(); var notes = Scholar.Items.get(_itemBeingEdited.getNotes());
if(notes.length) if(notes.length)
{ {
for(var i = 0; i < notes.length; i++) for(var i = 0; i < notes.length; i++)
@ -117,11 +118,11 @@ ScholarItemPane = new function()
icon.setAttribute('src','chrome://scholar/skin/treeitem-note.png'); icon.setAttribute('src','chrome://scholar/skin/treeitem-note.png');
var label = document.createElement('label'); var label = document.createElement('label');
label.setAttribute('value',_noteToTitle(_itemBeingEdited.getNote(notes[i]))); label.setAttribute('value',_noteToTitle(notes[i].getNote()));
label.setAttribute('crop','end'); label.setAttribute('crop','end');
box = document.createElement('box'); 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('onclick',"window.open('chrome://scholar/content/note.xul?item="+_itemBeingEdited.getID()+"&note="+notes[i].getID()+"','','chrome,resizable,centerscreen');");
box.setAttribute('class','clicky'); box.setAttribute('class','clicky');
box.appendChild(icon); box.appendChild(icon);
box.appendChild(label); box.appendChild(label);
@ -129,7 +130,7 @@ ScholarItemPane = new function()
var removeButton = document.createElement('label'); var removeButton = document.createElement('label');
removeButton.setAttribute("value","-"); removeButton.setAttribute("value","-");
removeButton.setAttribute("class","clicky"); removeButton.setAttribute("class","clicky");
removeButton.setAttribute("onclick","ScholarItemPane.removeNote("+notes[i]+")"); removeButton.setAttribute("onclick","ScholarItemPane.removeNote("+notes[i].getID()+")");
var row = document.createElement('row'); var row = document.createElement('row');
row.appendChild(box); row.appendChild(box);
@ -313,12 +314,10 @@ ScholarItemPane = new function()
function removeNote(id) function removeNote(id)
{ {
if(_itemBeingEdited.getNote(id) != "") var note = Scholar.Items.get(id);
if(!confirm(Scholar.getString('pane.item.notes.delete.confirm'))) if(note)
return; if(confirm(Scholar.getString('pane.item.notes.delete.confirm')))
note.erase();
if(id)
_itemBeingEdited.removeNote(id);
} }
function addNote() function addNote()

View File

@ -14,8 +14,7 @@ Scholar.ItemTreeView = function(itemGroup)
this._itemGroup = itemGroup; this._itemGroup = itemGroup;
this._treebox = null; this._treebox = null;
this._savedSelectionItems = null; this._savedSelection = null;
this._savedSelectionNotes = null;
this.refresh(); this.refresh();
this._unregisterID = Scholar.Notifier.registerItemTree(this); this._unregisterID = Scholar.Notifier.registerItemTree(this);
@ -52,7 +51,7 @@ Scholar.ItemTreeView.prototype.refresh = function()
var newRows = this._itemGroup.getChildItems(); var newRows = this._itemGroup.getChildItems();
for(var i = 0; i < newRows.length; i++) for(var i = 0; i < newRows.length; i++)
if(newRows[i]) if(newRows[i])
this._showItem(new Scholar.ItemTreeView.TreeRow('item',newRows[i],null,0,false), i+1); //item ref, before row this._showItem(new Scholar.ItemTreeView.TreeRow('item',newRows[i],0,false), i+1); //item ref, before row
this._refreshHashMap(); this._refreshHashMap();
} }
@ -114,9 +113,9 @@ Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
{ {
var item = Scholar.Items.get(ids); var item = Scholar.Items.get(ids);
if((this._itemGroup.isLibrary() || item.inCollection(this._itemGroup.ref.getID())) && this._itemRowMap[ids] == null) if((this._itemGroup.isLibrary() || item.inCollection(this._itemGroup.ref.getID())) && this._itemRowMap[ids] == null && !item.isNote())
{ {
this._showItem(new Scholar.ItemTreeView.TreeRow('item',item,null,0,false),this.rowCount); this._showItem(new Scholar.ItemTreeView.TreeRow('item',item,0,false),this.rowCount);
this._treebox.rowCountChanged(this.rowCount-1,1); this._treebox.rowCountChanged(this.rowCount-1,1);
madeChanges = true; madeChanges = true;
@ -195,11 +194,7 @@ Scholar.ItemTreeView.prototype.getImageSrc = function(row, col)
{ {
if(col.id == 'title') if(col.id == 'title')
{ {
var itemType; var itemType = Scholar.ItemTypes.getName(this._getItemAtRow(row).getType());
if(this._getItemAtRow(row).isNote())
itemType = 'note';
else
itemType = Scholar.ItemTypes.getName(this._getItemAtRow(row).getType());
return "chrome://scholar/skin/treeitem-"+itemType+".png"; return "chrome://scholar/skin/treeitem-"+itemType+".png";
} }
@ -262,12 +257,12 @@ Scholar.ItemTreeView.prototype.toggleOpenState = function(row)
else else
{ {
var item = this._getItemAtRow(row).ref; var item = this._getItemAtRow(row).ref;
var newRows = item.getNotes(); //Get children var newRows = Scholar.Items.get(item.getNotes()); //Get children
for(var i = 0; i < newRows.length; i++) for(var i = 0; i < newRows.length; i++)
{ {
count++; count++;
this._showItem(new Scholar.ItemTreeView.TreeRow('note',item,newRows[i],thisLevel+1,false), row+i+1); //item ref, before row this._showItem(new Scholar.ItemTreeView.TreeRow('note',newRows[i],thisLevel+1,false), row+i+1); //item ref, before row
} }
} }
@ -432,17 +427,10 @@ Scholar.ItemTreeView.prototype.deleteSelection = function()
this._treebox.beginUpdateBatch(); this._treebox.beginUpdateBatch();
for (var i=0; i<items.length; i++) for (var i=0; i<items.length; i++)
{ {
if(items[i].isNote()) if(this._itemGroup.isLibrary() || items[i].isNote()) //erase item from DB
{ items[i].ref.erase();
items[i].ref.removeNote(items[i].noteID); else if(this._itemGroup.isCollection())
} this._itemGroup.ref.removeItem(items[i].ref.getID());
else
{
if(this._itemGroup.isLibrary()) //erase item from DB
items[i].ref.erase();
else if(this._itemGroup.isCollection())
this._itemGroup.ref.removeItem(items[i].ref.getID());
}
} }
this._treebox.endUpdateBatch(); this._treebox.endUpdateBatch();
} }
@ -502,14 +490,10 @@ Scholar.ItemTreeView.prototype._getItemAtRow = function(row)
Scholar.ItemTreeView.prototype._refreshHashMap = function() Scholar.ItemTreeView.prototype._refreshHashMap = function()
{ {
this._itemRowMap = new Array(); this._itemRowMap = new Array();
this._noteRowMap = new Array();
for(var i=0; i < this.rowCount; i++) for(var i=0; i < this.rowCount; i++)
{ {
var row = this._getItemAtRow(i); var row = this._getItemAtRow(i);
if(row.isNote()) this._itemRowMap[row.ref.getID()] = i;
this._noteRowMap[row.noteID] = i;
else
this._itemRowMap[row.ref.getID()] = i;
} }
} }
@ -518,8 +502,7 @@ Scholar.ItemTreeView.prototype._refreshHashMap = function()
*/ */
Scholar.ItemTreeView.prototype.saveSelection = function() Scholar.ItemTreeView.prototype.saveSelection = function()
{ {
this._savedSelectionItems = new Array(); this._savedSelection = new Array();
this._savedSelectionNotes = new Array();
var start = new Object(); var start = new Object();
var end = new Object(); var end = new Object();
@ -528,10 +511,7 @@ Scholar.ItemTreeView.prototype.saveSelection = function()
this.selection.getRangeAt(i,start,end); this.selection.getRangeAt(i,start,end);
for (var j=start.value; j<=end.value; j++) for (var j=start.value; j<=end.value; j++)
{ {
if(this._getItemAtRow(j).isNote()) this._savedSelection.push(this._getItemAtRow(j).ref.getID());
this._savedSelectionNotes.push(this._getItemAtRow(j).noteID);
else
this._savedSelectionItems.push(this._getItemAtRow(j).ref.getID());
} }
} }
} }
@ -542,16 +522,10 @@ Scholar.ItemTreeView.prototype.saveSelection = function()
Scholar.ItemTreeView.prototype.rememberSelection = function() Scholar.ItemTreeView.prototype.rememberSelection = function()
{ {
this.selection.clearSelection(); this.selection.clearSelection();
for(var i=0; i < this._savedSelectionItems.length; i++) for(var i=0; i < this._savedSelection.length; i++)
{ {
if(this._itemRowMap[this._savedSelectionItems[i]] != null) if(this._itemRowMap[this._savedSelection[i]] != null)
this.selection.toggleSelect(this._itemRowMap[this._savedSelectionItems[i]]); this.selection.toggleSelect(this._itemRowMap[this._savedSelection[i]]);
}
for(var i=0; i < this._savedSelectionNotes.length; i++)
{
if(this._noteRowMap[this._savedSelectionNotes[i]] != null)
this.selection.toggleSelect(this._noteRowMap[this._savedSelectionNotes[i]]);
} }
} }
@ -569,7 +543,7 @@ Scholar.ItemTreeView.prototype.onDragStart = function (evt,transferData,action)
{ {
transferData.data=new TransferData(); transferData.data=new TransferData();
this.saveSelection(); this.saveSelection();
transferData.data.addDataForFlavour("scholar/item",this._savedSelectionItems); transferData.data.addDataForFlavour("scholar/item",this._savedSelection);
} }
/* /*
@ -622,28 +596,29 @@ Scholar.ItemTreeView.prototype.getRowProperties = function(row, prop) { }
Scholar.ItemTreeView.prototype.getColumnProperties = function(col, prop) { } Scholar.ItemTreeView.prototype.getColumnProperties = function(col, prop) { }
Scholar.ItemTreeView.prototype.getCellProperties = function(row, col, prop) { } Scholar.ItemTreeView.prototype.getCellProperties = function(row, col, prop) { }
Scholar.ItemTreeView.TreeRow = function(type, ref, noteID, level, isOpen) Scholar.ItemTreeView.TreeRow = function(type, ref, level, isOpen)
{ {
this.type = type; //either 'item' or 'note' this.type = type; //either 'item' or 'note'
this.ref = ref; //the item associated with this this.ref = ref; //the item/note associated with this
this.noteID = noteID //the note ID (if applicable)
this.level = level; this.level = level;
this.isOpen = isOpen; this.isOpen = isOpen;
} }
Scholar.ItemTreeView.TreeRow.prototype.isNote = function() Scholar.ItemTreeView.TreeRow.prototype.isNote = function()
{ {
return this.type == 'note'; return this.ref.isNote();
} }
Scholar.ItemTreeView.TreeRow.prototype.getField = function(field) Scholar.ItemTreeView.TreeRow.prototype.getField = function(field)
{ {
if(this.isNote()) if(this.isNote() && field == 'title')
{ {
if(field == 'title') var t = this.ref.getNote();
{ var n = t.indexOf("\n");
return this.ref.getNote(this.noteID); if(n > -1)
} t = t.substring(0,n);
return t;
} }
else else
{ {
@ -654,10 +629,7 @@ Scholar.ItemTreeView.TreeRow.prototype.getField = function(field)
Scholar.ItemTreeView.TreeRow.prototype.getType = function() Scholar.ItemTreeView.TreeRow.prototype.getType = function()
{ {
if(this.isNote()) return this.ref.getType();
return 'note';
else
return this.ref.getType();
} }
Scholar.ItemTreeView.TreeRow.prototype.numNotes = function() Scholar.ItemTreeView.TreeRow.prototype.numNotes = function()

View File

@ -1,5 +1,4 @@
var item; var item;
var noteID;
var note; var note;
var _notesField; var _notesField;
@ -17,11 +16,14 @@ function onLoad()
params[b[i].substr(0,mid)] = b[i].substr(mid+1); params[b[i].substr(0,mid)] = b[i].substr(mid+1);
} }
item = Scholar.Items.get(params['item']); item = Scholar.Items.get(params['item']);
noteID = params['note']; var noteID = params['note'];
document.getElementById('info-label').appendChild(document.createTextNode(item.getField('title') + " by " + item.getField('firstCreator'))); document.getElementById('info-label').appendChild(document.createTextNode(item.getField('title') + " by " + item.getField('firstCreator')));
if(noteID) if(noteID)
_notesField.setAttribute('value',item.getNote(noteID)); {
note = Scholar.Items.get(noteID);
_notesField.setAttribute('value',note.getNote());
}
} }
function onUnload() function onUnload()
@ -31,10 +33,15 @@ function onUnload()
function save() function save()
{ {
if(noteID) if(note)
item.updateNote(noteID,_notesField.value); {
note.updateNote(_notesField.value);
}
else else
noteID = item.addNote(_notesField.value); {
var noteID = Scholar.Notes.add(_notesField.value,item.getID());
note = Scholar.Items.get(noteID);
}
} }
addEventListener("load", function(e) { onLoad(e); }, false); addEventListener("load", function(e) { onLoad(e); }, false);

View File

@ -125,17 +125,22 @@ var ScholarPane = new function()
{ {
var item = itemsView._getItemAtRow(itemsView.selection.currentIndex); var item = itemsView._getItemAtRow(itemsView.selection.currentIndex);
if(!item.isNote()) if(item.isNote())
ScholarItemPane.viewItem(item.ref); {
document.getElementById('scholar-view-item').hidden = false; document.getElementById('item-pane').selectedIndex = 2;
document.getElementById('scholar-view-selected-label').hidden = true; }
else
{
ScholarItemPane.viewItem(item.ref);
document.getElementById('item-pane').selectedIndex = 1;
}
} }
else else
{ {
document.getElementById('scholar-view-item').hidden = true; document.getElementById('item-pane').selectedIndex = 0;
var label = document.getElementById('scholar-view-selected-label'); var label = document.getElementById('scholar-view-selected-label');
label.hidden = false;
if(itemsView && itemsView.selection.count) if(itemsView && itemsView.selection.count)
label.value = Scholar.getString('pane.item.selected.multiple').replace('%1', itemsView.selection.count); label.value = Scholar.getString('pane.item.selected.multiple').replace('%1', itemsView.selection.count);

View File

@ -140,10 +140,13 @@
</tree> </tree>
</vbox> </vbox>
<splitter id="scholar-view-splitter" collapse="after" persist="state"><grippy/></splitter> <splitter id="scholar-view-splitter" collapse="after" persist="state"><grippy/></splitter>
<box id="item-pane" pack="center" align="center"> <deck id="item-pane" selectedIndex="0">
<label id="scholar-view-selected-label"/> <box pack="center" align="center"><label id="scholar-view-selected-label"/></box>
<tabbox id="scholar-view-item" hidden="true" flex="1"/> <tabbox id="scholar-view-item" flex="1"/>
</box> <vbox id="scholar-view-note" flex="1" pack="center" align="center">
<label>Inline editing: coming soon</label>
</vbox>
</deck>
</hbox> </hbox>
</vbox> </vbox>
<splitter id="scholar-splitter" resizebefore="closest" resizeafter="closest" position="2" persist="collapsed"/> <splitter id="scholar-splitter" resizebefore="closest" resizeafter="closest" position="2" persist="collapsed"/>