[interface] Preliminary drag-and-drop.

1) Items into collections.
  2) Collections into collections.
	Dan S, please check this out, I am getting some exceptions from the data access portion.
[interface] Temporarily, "metadata" pane on the right is not resizable.
This commit is contained in:
David Norton 2006-06-08 18:42:55 +00:00
parent 076ee0fad2
commit 1d14c69ad5
5 changed files with 97 additions and 45 deletions

View file

@ -1,10 +1,21 @@
Scholar.CollectionTreeView = function()
{
this._treebox = null;
this._unregisterID = Scholar.Notifier.registerColumnTree(this);
this.refresh();
}
Scholar.CollectionTreeView.prototype.refresh = function()
{
this._dataItems = new Array();
this.rowCount = 0;
this._showItem(new Scholar.ItemGroup('library',null),0,1);
this._unregisterID = Scholar.Notifier.registerColumnTree(this);
var newRows = Scholar.getCollections();
for(var i = 0; i < newRows.length; i++)
this._showItem(new Scholar.ItemGroup('collection',newRows[i]), 0, this._dataItems.length); //item ref, level, beforeRow
this._refreshHashMap();
}
/*
@ -80,12 +91,6 @@ Scholar.CollectionTreeView.prototype.setTree = function(treebox)
if(this._treebox)
return;
this._treebox = treebox;
var newRows = Scholar.getCollections();
for(var i = 0; i < newRows.length; i++)
this._showItem(new Scholar.ItemGroup('collection',newRows[i]), 0, this._dataItems.length); //item ref, level, beforeRow
this._refreshHashMap();
}
Scholar.CollectionTreeView.prototype.getCellText = function(row, column)
@ -243,18 +248,61 @@ Scholar.CollectionTreeView.prototype._refreshHashMap = function()
Scholar.CollectionTreeView.prototype.canDrop = function(row, orient)
{
if(orient == this.DROP_ON && this._getItemAtRow(row).isCollection())
if(orient == 0 && this._getItemAtRow(row).isCollection())
{
Scholar.debug("drag on row: " + row + " orient: " + orient);
return true;
}
else
return false;
}
Scholar.CollectionTreeView.prototype.drop = function(row, orient)
{
//you can't really do anything here, look to overlay.js - ScholarCollectionsDragObserver
var dataSet = nsTransferable.get(this.getSupportedFlavours(),nsDragAndDrop.getDragData, true);
var data = dataSet.first.first;
var dataType = data.flavour.contentType;
var ids = data.data.split(',');
if(dataType == 'scholar/collection')
{
var oldCount = this.rowCount;
var targetCollectionID;
if(this.canDrop(row,orient))
targetCollectionID = this._getItemAtRow(row).ref.getID();
var droppedCollection = Scholar.Collections.get(ids[0]);
droppedCollection.changeParent(targetCollectionID);
this.refresh();
this._treebox.rowCountChanged(0,this.rowCount-oldCount);
this._treebox.invalidate();
}
else if(dataType == 'scholar/item' && this.canDrop(row, orient))
{
var targetCollection = this._getItemAtRow(row).ref;
for(var i = 0; i<ids.length; i++)
targetCollection.addItem(ids[i]);
}
}
Scholar.CollectionTreeView.prototype.onDragStart = function(evt,transferData,action)
{
transferData.data=new TransferData();
transferData.data.addDataForFlavour("scholar/collection",this._getItemAtRow(this.selection.currentIndex).ref.getID());
}
Scholar.CollectionTreeView.prototype.getSupportedFlavours = function ()
{
var flavors = new FlavourSet();
flavors.appendFlavour("scholar/item");
flavors.appendFlavour("scholar/collection");
return flavors;
}
Scholar.CollectionTreeView.prototype.onDragOver = function (evt,dropdata,session) { }
Scholar.CollectionTreeView.prototype.onDrop = function (evt,dropdata,session) { }
//
// SCHOLAR ITEMGROUP
//

View file

@ -298,4 +298,21 @@ Scholar.ItemTreeView.prototype.rememberSelection = function()
Scholar.ItemTreeView.prototype.canDrop = function(index, orient)
{
return false;
}
}
Scholar.ItemTreeView.prototype.onDragStart = function (evt,transferData,action)
{
transferData.data=new TransferData();
this.saveSelection();
transferData.data.addDataForFlavour("scholar/item",this._savedSelection);
}
Scholar.ItemTreeView.prototype.getSupportedFlavours = function ()
{
var flavors = new FlavourSet();
flavors.appendFlavour("scholar/item");
return flavors;
}
Scholar.ItemTreeView.prototype.onDragOver = function (evt,dropdata,session) { }
Scholar.ItemTreeView.prototype.onDrop = function (evt,dropdata,session) { }

View file

@ -19,6 +19,8 @@ var ScholarPane = new function()
this.deleteCollectionSelection = deleteCollectionSelection;
this.renameSelectedCollection = renameSelectedCollection;
this.search = search;
this.getCollectionsView = getCollectionsView;
this.getItemsView = getItemsView;
/*
* Called when the window is open
@ -112,13 +114,13 @@ var ScholarPane = new function()
MetadataPane.viewItem(item);
document.getElementById('scholar-view-item').hidden=false;
document.getElementById('scholar-view-splitter').hidden = false;
document.getElementById('scholar-view-item').hidden = false;
document.getElementById('scholar-view-splitter').hidden = false;
}
else
{
document.getElementById('scholar-view-item').hidden=true;
document.getElementById('scholar-view-splitter').hidden = true;
document.getElementById('scholar-view-item').hidden = true;
document.getElementById('scholar-view-splitter').hidden = true;
}
@ -153,31 +155,15 @@ var ScholarPane = new function()
if(itemsView)
itemsView.searchText(document.getElementById('tb-search').value);
}
}
var ScholarItemsDragObserver =
{
onDragStart: function (evt,transferData,action)
{
transferData.data=new TransferData();
transferData.data.addDataForFlavour("text/unicode","random data");
}
};
var ScholarCollectionsDragObserver =
{
getSupportedFlavours : function ()
{
var flavours = new FlavourSet();
flavours.appendFlavour("text/unicode");
return flavours;
},
onDragOver: function (evt,dropdata,session){},
onDrop: function (evt,dropdata,session)
{
alert(dropdata.data);
function getCollectionsView()
{
return collectionsView;
}
function getItemsView()
{
return itemsView;
}
}

View file

@ -28,7 +28,8 @@
</toolbar>
<tree id="collections-tree" hidecolumnpicker="true"
onselect="ScholarPane.onCollectionSelected();" seltype="single"
ondragover="nsDragAndDrop.dragOver(event,ScholarCollectionsDragObserver)" ondragdrop="nsDragAndDrop.drop(event,ScholarCollectionsDragObserver)"
ondragover="nsDragAndDrop.dragOver(event,ScholarPane.getCollectionsView())" ondragdrop="nsDragAndDrop.drop(event,ScholarPane.getCollectionsView())"
ondraggesture="if (event.target.localName == 'treechildren') nsDragAndDrop.startDrag(event,ScholarPane.getCollectionsView());"
onkeypress="if(event.keyCode == event.DOM_VK_BACK_SPACE || event.keyCode == event.DOM_VK_DELETE){ ScholarPane.deleteCollectionSelection(); return false; }"
flex="1">
<treecols>
@ -57,7 +58,8 @@
id="items-tree"
enableColumnDrag="true" onkeypress="if(event.keyCode == event.DOM_VK_BACK_SPACE || event.keyCode == event.DOM_VK_DELETE){ ScholarPane.deleteItemSelection(); return false; }"
onselect="ScholarPane.itemSelected();"
ondraggesture="if (event.target.localName == 'treechildren') nsDragAndDrop.startDrag(event,ScholarItemsDragObserver);"
ondraggesture="if (event.target.localName == 'treechildren') nsDragAndDrop.startDrag(event,ScholarPane.getItemsView());"
ondragover="nsDragAndDrop.dragOver(event,ScholarPane.getItemsView())" ondragdrop="nsDragAndDrop.drop(event,ScholarPane.getItemsView())"
flex="1">
<treecols>
<treecol
@ -95,8 +97,8 @@
</tree>
</vbox>
<splitter id="scholar-view-splitter" resizebefore="closest" resizeafter="closest" hidden="true"/>
<tabbox id="scholar-view-item" hidden="true" flex="2" style="min-width: 300px;">
<separator orient="vertical" class="thin" id="scholar-view-splitter" hidden="true"/>
<tabbox id="scholar-view-item" hidden="true" flex="2" style="min-width: 300px; max-width: 300px;">
<tabs>
<tab label="Metadata"/>
<tab label="Notes"/>

View file

@ -14,7 +14,6 @@ tree #collections-tree
#scholar-tree-splitter
{
background: #f5f5f5;
}
tree #items-tree