[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() Scholar.CollectionTreeView = function()
{ {
this._treebox = null; this._treebox = null;
this._unregisterID = Scholar.Notifier.registerColumnTree(this);
this.refresh();
}
Scholar.CollectionTreeView.prototype.refresh = function()
{
this._dataItems = new Array(); this._dataItems = new Array();
this.rowCount = 0; this.rowCount = 0;
this._showItem(new Scholar.ItemGroup('library',null),0,1); 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) if(this._treebox)
return; return;
this._treebox = treebox; 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) Scholar.CollectionTreeView.prototype.getCellText = function(row, column)
@ -243,17 +248,60 @@ Scholar.CollectionTreeView.prototype._refreshHashMap = function()
Scholar.CollectionTreeView.prototype.canDrop = function(row, orient) 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; return true;
}
else else
return false; return false;
} }
Scholar.CollectionTreeView.prototype.drop = function(row, orient) 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 // SCHOLAR ITEMGROUP

View file

@ -299,3 +299,20 @@ Scholar.ItemTreeView.prototype.canDrop = function(index, orient)
{ {
return false; 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.deleteCollectionSelection = deleteCollectionSelection;
this.renameSelectedCollection = renameSelectedCollection; this.renameSelectedCollection = renameSelectedCollection;
this.search = search; this.search = search;
this.getCollectionsView = getCollectionsView;
this.getItemsView = getItemsView;
/* /*
* Called when the window is open * Called when the window is open
@ -153,31 +155,15 @@ var ScholarPane = new function()
if(itemsView) if(itemsView)
itemsView.searchText(document.getElementById('tb-search').value); itemsView.searchText(document.getElementById('tb-search').value);
} }
function getCollectionsView()
{
return collectionsView;
} }
var ScholarItemsDragObserver = function getItemsView()
{ {
onDragStart: function (evt,transferData,action) return itemsView;
{
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);
} }
} }

View file

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

View file

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