2006-06-02 15:27:52 +00:00
|
|
|
/*
|
|
|
|
* This object contains the various functions for the interface
|
|
|
|
*/
|
2006-05-30 22:06:33 +00:00
|
|
|
var ScholarPane = new function()
|
|
|
|
{
|
2006-06-05 18:01:53 +00:00
|
|
|
var collectionsView;
|
2006-05-30 22:06:33 +00:00
|
|
|
var itemsView;
|
|
|
|
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
|
|
|
|
|
2006-06-02 15:27:52 +00:00
|
|
|
//Privileged methods
|
|
|
|
this.onLoad = onLoad;
|
|
|
|
this.onUnload = onUnload;
|
|
|
|
this.toggleDisplay = toggleDisplay;
|
2006-07-05 16:19:26 +00:00
|
|
|
this.fullScreen = fullScreen;
|
2006-05-30 22:06:33 +00:00
|
|
|
this.newItem = newItem;
|
2006-06-01 03:50:34 +00:00
|
|
|
this.newCollection = newCollection;
|
2006-06-05 18:01:53 +00:00
|
|
|
this.onCollectionSelected = onCollectionSelected;
|
2006-05-30 22:06:33 +00:00
|
|
|
this.itemSelected = itemSelected;
|
2006-06-19 15:00:13 +00:00
|
|
|
this.deleteSelectedItem = deleteSelectedItem;
|
|
|
|
this.deleteSelectedCollection = deleteSelectedCollection;
|
2006-06-05 13:08:16 +00:00
|
|
|
this.renameSelectedCollection = renameSelectedCollection;
|
2006-05-30 22:06:33 +00:00
|
|
|
this.search = search;
|
2006-06-08 18:42:55 +00:00
|
|
|
this.getCollectionsView = getCollectionsView;
|
|
|
|
this.getItemsView = getItemsView;
|
2006-07-24 22:12:25 +00:00
|
|
|
this.getSelectedCollection = getSelectedCollection;
|
|
|
|
this.getSelectedItem = getSelectedItem;
|
2006-06-19 15:00:13 +00:00
|
|
|
this.buildCollectionContextMenu = buildCollectionContextMenu;
|
|
|
|
this.buildItemContextMenu = buildItemContextMenu;
|
2006-06-27 22:47:17 +00:00
|
|
|
this.openNoteWindow = openNoteWindow;
|
2006-05-30 22:06:33 +00:00
|
|
|
|
2006-06-02 15:27:52 +00:00
|
|
|
/*
|
|
|
|
* Called when the window is open
|
|
|
|
*/
|
|
|
|
function onLoad()
|
2006-05-30 22:06:33 +00:00
|
|
|
{
|
2006-07-19 16:14:27 +00:00
|
|
|
if(Scholar.Prefs.get("scholarPaneOnTop"))
|
2006-06-28 15:15:38 +00:00
|
|
|
{
|
2006-07-19 16:14:27 +00:00
|
|
|
var oldPane = document.getElementById('scholar-pane');
|
|
|
|
var oldSplitter = document.getElementById('scholar-splitter');
|
|
|
|
var appContent = document.getElementById('appcontent');
|
|
|
|
|
|
|
|
var newPane = document.createElement('hbox');
|
|
|
|
newPane.setAttribute('id','scholar-pane');
|
|
|
|
newPane.setAttribute('collapsed',true);
|
|
|
|
newPane.setAttribute('flex','1');
|
|
|
|
while(oldPane.hasChildNodes())
|
|
|
|
newPane.appendChild(oldPane.firstChild);
|
|
|
|
appContent.removeChild(oldPane);
|
|
|
|
appContent.insertBefore(newPane, document.getElementById('content'));
|
|
|
|
|
|
|
|
var newSplitter = document.createElement('splitter');
|
|
|
|
newSplitter.setAttribute('id','scholar-splitter');
|
|
|
|
newSplitter.setAttribute('collapsed',true);
|
|
|
|
newSplitter.setAttribute('resizebefore','closest');
|
|
|
|
newSplitter.setAttribute('resizeafter','closest');
|
|
|
|
appContent.removeChild(oldSplitter);
|
|
|
|
appContent.insertBefore(newSplitter, document.getElementById('content'));
|
2006-06-28 15:15:38 +00:00
|
|
|
}
|
|
|
|
|
2006-07-26 14:03:54 +00:00
|
|
|
//Initialize collections view
|
|
|
|
collectionsView = new Scholar.CollectionTreeView();
|
|
|
|
document.getElementById('collections-tree').view = collectionsView;
|
|
|
|
|
2006-06-20 13:59:59 +00:00
|
|
|
//Create the add menu with each item type
|
|
|
|
var addMenu = document.getElementById('tb-add').firstChild;
|
|
|
|
var itemTypes = Scholar.ItemTypes.getTypes();
|
|
|
|
for(var i = 0; i<itemTypes.length; i++)
|
|
|
|
{
|
|
|
|
var menuitem = document.createElement("menuitem");
|
|
|
|
menuitem.setAttribute("label", Scholar.getString("itemTypes."+itemTypes[i]['name']));
|
|
|
|
menuitem.setAttribute("oncommand","ScholarPane.newItem("+itemTypes[i]['id']+")");
|
|
|
|
addMenu.appendChild(menuitem);
|
|
|
|
}
|
2006-05-30 22:06:33 +00:00
|
|
|
}
|
|
|
|
|
2006-06-02 15:27:52 +00:00
|
|
|
/*
|
|
|
|
* Called when the window closes
|
|
|
|
*/
|
|
|
|
function onUnload()
|
|
|
|
{
|
2006-06-05 18:01:53 +00:00
|
|
|
collectionsView.unregister();
|
2006-06-02 15:27:52 +00:00
|
|
|
if(itemsView)
|
|
|
|
itemsView.unregister();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hides/displays the Scholar interface
|
|
|
|
*/
|
|
|
|
function toggleDisplay()
|
2006-05-31 22:01:31 +00:00
|
|
|
{
|
2006-07-19 16:14:27 +00:00
|
|
|
var visible = document.getElementById('scholar-pane').getAttribute('collapsed') == 'true';
|
2006-05-31 22:01:31 +00:00
|
|
|
|
2006-07-19 16:14:27 +00:00
|
|
|
document.getElementById('scholar-pane').setAttribute('collapsed',!visible);
|
|
|
|
document.getElementById('scholar-splitter').setAttribute('collapsed',!visible);
|
2006-07-05 16:19:26 +00:00
|
|
|
|
|
|
|
if(!visible)
|
|
|
|
document.getElementById('content').setAttribute('collapsed', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function fullScreen()
|
|
|
|
{
|
|
|
|
var visible = document.getElementById('content').getAttribute('collapsed') == 'true';
|
|
|
|
document.getElementById('content').setAttribute('collapsed', !visible);
|
2006-07-19 16:14:27 +00:00
|
|
|
document.getElementById('scholar-splitter').setAttribute('collapsed', !visible);
|
2006-05-31 22:01:31 +00:00
|
|
|
}
|
2006-06-02 15:27:52 +00:00
|
|
|
|
|
|
|
/*
|
2006-06-17 00:57:50 +00:00
|
|
|
* Create a new item
|
2006-06-02 15:27:52 +00:00
|
|
|
*/
|
2006-05-30 22:06:33 +00:00
|
|
|
function newItem(typeID)
|
|
|
|
{
|
2006-06-19 15:00:13 +00:00
|
|
|
if(document.getElementById('tb-search').value != "")
|
|
|
|
{
|
|
|
|
document.getElementById('tb-search').value = "";
|
|
|
|
document.getElementById('tb-search').doCommand();
|
|
|
|
}
|
|
|
|
|
2006-06-17 00:57:50 +00:00
|
|
|
var item = new Scholar.Item(typeID);
|
|
|
|
item.save();
|
|
|
|
if(itemsView && itemsView._itemGroup.isCollection())
|
|
|
|
itemsView._itemGroup.ref.addItem(item.getID());
|
2006-06-19 15:00:13 +00:00
|
|
|
|
2006-06-25 04:57:52 +00:00
|
|
|
//set to Info tab
|
|
|
|
document.getElementById('scholar-view-item').selectedIndex = 0;
|
2006-05-30 22:06:33 +00:00
|
|
|
}
|
|
|
|
|
2006-06-01 03:50:34 +00:00
|
|
|
function newCollection()
|
2006-05-30 22:06:33 +00:00
|
|
|
{
|
2006-06-05 17:47:36 +00:00
|
|
|
Scholar.Collections.add(Scholar.getString('pane.collections.untitled'));
|
2006-05-30 22:06:33 +00:00
|
|
|
}
|
|
|
|
|
2006-06-05 18:01:53 +00:00
|
|
|
function onCollectionSelected()
|
2006-05-30 22:06:33 +00:00
|
|
|
{
|
2006-06-02 12:59:58 +00:00
|
|
|
if(itemsView)
|
|
|
|
itemsView.unregister();
|
2006-06-06 22:43:58 +00:00
|
|
|
|
|
|
|
document.getElementById('tb-search').value = "";
|
2006-06-21 22:23:42 +00:00
|
|
|
document.getElementById('scholar-search-options').hidden = true;
|
2006-07-24 22:12:25 +00:00
|
|
|
|
2006-06-05 18:01:53 +00:00
|
|
|
if(collectionsView.selection.count == 1 && collectionsView.selection.currentIndex != -1)
|
2006-05-30 22:06:33 +00:00
|
|
|
{
|
2006-06-05 18:01:53 +00:00
|
|
|
var collection = collectionsView._getItemAtRow(collectionsView.selection.currentIndex);
|
2006-06-06 22:43:58 +00:00
|
|
|
collection.setSearch('');
|
2006-06-05 13:08:16 +00:00
|
|
|
|
|
|
|
itemsView = new Scholar.ItemTreeView(collection);
|
2006-05-30 22:06:33 +00:00
|
|
|
document.getElementById('items-tree').view = itemsView;
|
2006-06-20 17:08:30 +00:00
|
|
|
document.getElementById('tb-collection-rename').disabled = collection.isLibrary();
|
2006-06-13 20:45:30 +00:00
|
|
|
itemsView.selection.clearSelection();
|
2006-05-30 22:06:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-01 18:50:16 +00:00
|
|
|
document.getElementById('items-tree').view = itemsView = null;
|
2006-06-20 17:08:30 +00:00
|
|
|
document.getElementById('tb-collection-rename').disabled = true;
|
2006-05-30 22:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function itemSelected()
|
|
|
|
{
|
2006-06-02 15:27:52 +00:00
|
|
|
if(itemsView && itemsView.selection.count == 1 && itemsView.selection.currentIndex != -1)
|
2006-05-30 22:06:33 +00:00
|
|
|
{
|
|
|
|
var item = itemsView._getItemAtRow(itemsView.selection.currentIndex);
|
|
|
|
|
2006-06-27 20:37:02 +00:00
|
|
|
if(item.isNote())
|
|
|
|
{
|
2006-06-28 18:30:29 +00:00
|
|
|
var noteEditor = document.getElementById('scholar-note-editor');
|
|
|
|
noteEditor.item = null;
|
|
|
|
noteEditor.note = item.ref;
|
2006-06-27 22:47:17 +00:00
|
|
|
document.getElementById('scholar-view-note').lastChild.setAttribute('noteID',item.ref.getID());
|
2006-06-27 20:37:02 +00:00
|
|
|
document.getElementById('item-pane').selectedIndex = 2;
|
2006-07-26 14:03:54 +00:00
|
|
|
document.getElementById('scholar-view-tabs').setAttribute('hidden',true);
|
2006-06-27 20:37:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-26 17:51:18 +00:00
|
|
|
ScholarItemPane.viewItem(item.ref);
|
2006-06-27 20:37:02 +00:00
|
|
|
document.getElementById('item-pane').selectedIndex = 1;
|
2006-07-26 14:03:54 +00:00
|
|
|
document.getElementById('scholar-view-tabs').setAttribute('hidden',false);
|
2006-06-27 20:37:02 +00:00
|
|
|
}
|
2006-05-30 22:06:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-27 20:37:02 +00:00
|
|
|
document.getElementById('item-pane').selectedIndex = 0;
|
2006-07-26 14:03:54 +00:00
|
|
|
document.getElementById('scholar-view-tabs').setAttribute('hidden',true);
|
2006-06-20 13:59:59 +00:00
|
|
|
|
2006-06-27 20:37:02 +00:00
|
|
|
var label = document.getElementById('scholar-view-selected-label');
|
|
|
|
|
2006-06-20 13:59:59 +00:00
|
|
|
if(itemsView && itemsView.selection.count)
|
2006-06-21 23:22:37 +00:00
|
|
|
label.value = Scholar.getString('pane.item.selected.multiple').replace('%1', itemsView.selection.count);
|
2006-06-20 13:59:59 +00:00
|
|
|
else
|
2006-06-21 23:22:37 +00:00
|
|
|
label.value = Scholar.getString('pane.item.selected.zero');
|
2006-05-30 22:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-06-19 15:00:13 +00:00
|
|
|
function deleteSelectedItem()
|
2006-05-30 22:06:33 +00:00
|
|
|
{
|
2006-06-05 17:47:36 +00:00
|
|
|
if(itemsView && itemsView.selection.count > 0 && confirm(Scholar.getString('pane.items.delete')))
|
2006-05-30 22:06:33 +00:00
|
|
|
itemsView.deleteSelection();
|
|
|
|
}
|
|
|
|
|
2006-06-19 15:00:13 +00:00
|
|
|
function deleteSelectedCollection()
|
2006-06-02 14:11:23 +00:00
|
|
|
{
|
2006-06-05 18:01:53 +00:00
|
|
|
if(collectionsView.selection.count > 0 && confirm(Scholar.getString('pane.collections.delete')))
|
|
|
|
collectionsView.deleteSelection();
|
2006-06-02 14:11:23 +00:00
|
|
|
}
|
|
|
|
|
2006-06-05 13:08:16 +00:00
|
|
|
function renameSelectedCollection()
|
|
|
|
{
|
2006-06-05 18:01:53 +00:00
|
|
|
if(collectionsView.selection.count > 0)
|
2006-06-05 13:08:16 +00:00
|
|
|
{
|
2006-07-24 22:12:25 +00:00
|
|
|
var collection = collectionsView._getItemAtRow(collectionsView.selection.currentIndex);
|
2006-06-05 13:08:16 +00:00
|
|
|
|
2006-06-05 17:47:36 +00:00
|
|
|
var newName = prompt(Scholar.getString('pane.collections.rename'),collection.getName());
|
2006-06-05 13:08:16 +00:00
|
|
|
if(newName)
|
|
|
|
collection.ref.rename(newName);
|
|
|
|
}
|
|
|
|
}
|
2006-06-06 19:53:27 +00:00
|
|
|
|
2006-05-30 22:06:33 +00:00
|
|
|
function search()
|
|
|
|
{
|
2006-06-01 16:40:43 +00:00
|
|
|
if(itemsView)
|
2006-06-21 22:23:42 +00:00
|
|
|
{
|
|
|
|
searchVal = document.getElementById('tb-search').value;
|
|
|
|
itemsView.searchText(searchVal);
|
|
|
|
|
|
|
|
//do something about granularity
|
|
|
|
//document.getElementById('scholar-search-options').getElementsByAttribute('checked','true')[0].label
|
|
|
|
|
|
|
|
document.getElementById('scholar-search-options').hidden = searchVal == "";
|
|
|
|
}
|
|
|
|
|
2006-06-01 16:40:43 +00:00
|
|
|
}
|
2006-06-08 18:42:55 +00:00
|
|
|
|
|
|
|
function getCollectionsView()
|
|
|
|
{
|
|
|
|
return collectionsView;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getItemsView()
|
|
|
|
{
|
|
|
|
return itemsView;
|
2006-06-02 12:59:58 +00:00
|
|
|
}
|
2006-06-19 15:00:13 +00:00
|
|
|
|
2006-07-24 22:12:25 +00:00
|
|
|
function getSelectedCollection()
|
|
|
|
{
|
|
|
|
if(collectionsView.selection.count > 0 && collectionsView.selection.currentIndex != -1)
|
|
|
|
{
|
|
|
|
collection = collectionsView._getItemAtRow(collectionsView.selection.currentIndex);
|
|
|
|
if(collection && collection.isCollection())
|
|
|
|
return collection.ref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSelectedItem()
|
|
|
|
{
|
|
|
|
if(itemsView && itemsView.selection.count == 1 && itemsView.selection.currentIndex != -1)
|
|
|
|
{
|
|
|
|
var item = itemsView._getItemAtRow(itemsView.selection.currentIndex);
|
|
|
|
if(item)
|
|
|
|
return item.ref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-19 15:00:13 +00:00
|
|
|
function buildCollectionContextMenu()
|
|
|
|
{
|
|
|
|
var menu = document.getElementById('scholar-collectionmenu');
|
|
|
|
|
|
|
|
if(collectionsView.selection.count == 1 && !collectionsView._getItemAtRow(collectionsView.selection.currentIndex).isLibrary())
|
|
|
|
{
|
|
|
|
menu.childNodes[2].removeAttribute('disabled');
|
|
|
|
menu.childNodes[3].removeAttribute('disabled');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
menu.childNodes[2].setAttribute('disabled', true);
|
|
|
|
menu.childNodes[3].setAttribute('disabled', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildItemContextMenu()
|
|
|
|
{
|
|
|
|
var menu = document.getElementById('scholar-itemmenu');
|
|
|
|
|
|
|
|
if(itemsView && itemsView.selection.count > 0)
|
|
|
|
menu.childNodes[2].removeAttribute('disabled');
|
|
|
|
else
|
|
|
|
menu.childNodes[2].setAttribute('disabled', true);
|
|
|
|
|
|
|
|
if(itemsView && itemsView.selection.count > 1)
|
2006-06-21 23:22:37 +00:00
|
|
|
menu.childNodes[2].setAttribute('label', Scholar.getString('pane.items.menu.remove.multiple'));
|
2006-06-19 15:00:13 +00:00
|
|
|
else
|
2006-06-21 23:22:37 +00:00
|
|
|
menu.childNodes[2].setAttribute('label', Scholar.getString('pane.items.menu.remove'));
|
2006-06-19 15:00:13 +00:00
|
|
|
}
|
2006-06-27 22:47:17 +00:00
|
|
|
|
|
|
|
function openNoteWindow(id)
|
|
|
|
{
|
|
|
|
window.open('chrome://scholar/content/note.xul?id='+id,'','chrome,resizable,centerscreen');
|
|
|
|
}
|
2006-06-02 12:59:58 +00:00
|
|
|
}
|
|
|
|
|
2006-06-02 15:27:52 +00:00
|
|
|
window.addEventListener("load", function(e) { ScholarPane.onLoad(e); }, false);
|
|
|
|
window.addEventListener("unload", function(e) { ScholarPane.onUnload(e); }, false);
|