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

View File

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

View File

@ -1,5 +1,4 @@
var item;
var noteID;
var note;
var _notesField;
@ -17,11 +16,14 @@ function onLoad()
params[b[i].substr(0,mid)] = b[i].substr(mid+1);
}
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')));
if(noteID)
_notesField.setAttribute('value',item.getNote(noteID));
{
note = Scholar.Items.get(noteID);
_notesField.setAttribute('value',note.getNote());
}
}
function onUnload()
@ -31,10 +33,15 @@ function onUnload()
function save()
{
if(noteID)
item.updateNote(noteID,_notesField.value);
if(note)
{
note.updateNote(_notesField.value);
}
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);

View File

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

View File

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