From 2f01fe57a8d37767827d6db42850aef86a767c53 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 15 Nov 2010 10:39:52 +0300 Subject: add dijit/dojo stuff; initial ui mockup --- lib/dijit/tree/ForestStoreModel.js | 83 +++++++++++++ lib/dijit/tree/TreeStoreModel.js | 145 ++++++++++++++++++++++ lib/dijit/tree/_dndContainer.js | 49 ++++++++ lib/dijit/tree/_dndSelector.js | 125 +++++++++++++++++++ lib/dijit/tree/dndSource.js | 240 +++++++++++++++++++++++++++++++++++++ lib/dijit/tree/model.js | 20 ++++ 6 files changed, 662 insertions(+) create mode 100644 lib/dijit/tree/ForestStoreModel.js create mode 100644 lib/dijit/tree/TreeStoreModel.js create mode 100644 lib/dijit/tree/_dndContainer.js create mode 100644 lib/dijit/tree/_dndSelector.js create mode 100644 lib/dijit/tree/dndSource.js create mode 100644 lib/dijit/tree/model.js (limited to 'lib/dijit/tree') diff --git a/lib/dijit/tree/ForestStoreModel.js b/lib/dijit/tree/ForestStoreModel.js new file mode 100644 index 000000000..aa51b0023 --- /dev/null +++ b/lib/dijit/tree/ForestStoreModel.js @@ -0,0 +1,83 @@ +/* + Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Available via Academic Free License >= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + + +if(!dojo._hasResource["dijit.tree.ForestStoreModel"]){ +dojo._hasResource["dijit.tree.ForestStoreModel"]=true; +dojo.provide("dijit.tree.ForestStoreModel"); +dojo.require("dijit.tree.TreeStoreModel"); +dojo.declare("dijit.tree.ForestStoreModel",dijit.tree.TreeStoreModel,{rootId:"$root$",rootLabel:"ROOT",query:null,constructor:function(_1){ +this.root={store:this,root:true,id:_1.rootId,label:_1.rootLabel,children:_1.rootChildren}; +},mayHaveChildren:function(_2){ +return _2===this.root||this.inherited(arguments); +},getChildren:function(_3,_4,_5){ +if(_3===this.root){ +if(this.root.children){ +_4(this.root.children); +}else{ +this.store.fetch({query:this.query,onComplete:dojo.hitch(this,function(_6){ +this.root.children=_6; +_4(_6); +}),onError:_5}); +} +}else{ +this.inherited(arguments); +} +},isItem:function(_7){ +return (_7===this.root)?true:this.inherited(arguments); +},fetchItemByIdentity:function(_8){ +if(_8.identity==this.root.id){ +var _9=_8.scope?_8.scope:dojo.global; +if(_8.onItem){ +_8.onItem.call(_9,this.root); +} +}else{ +this.inherited(arguments); +} +},getIdentity:function(_a){ +return (_a===this.root)?this.root.id:this.inherited(arguments); +},getLabel:function(_b){ +return (_b===this.root)?this.root.label:this.inherited(arguments); +},newItem:function(_c,_d,_e){ +if(_d===this.root){ +this.onNewRootItem(_c); +return this.store.newItem(_c); +}else{ +return this.inherited(arguments); +} +},onNewRootItem:function(_f){ +},pasteItem:function(_10,_11,_12,_13,_14){ +if(_11===this.root){ +if(!_13){ +this.onLeaveRoot(_10); +} +} +dijit.tree.TreeStoreModel.prototype.pasteItem.call(this,_10,_11===this.root?null:_11,_12===this.root?null:_12,_13,_14); +if(_12===this.root){ +this.onAddToRoot(_10); +} +},onAddToRoot:function(_15){ +},onLeaveRoot:function(_16){ +},_requeryTop:function(){ +var _17=this.root.children||[]; +this.store.fetch({query:this.query,onComplete:dojo.hitch(this,function(_18){ +this.root.children=_18; +if(_17.length!=_18.length||dojo.some(_17,function(_19,idx){ +return _18[idx]!=_19; +})){ +this.onChildrenChange(this.root,_18); +} +})}); +},onNewItem:function(_1a,_1b){ +this._requeryTop(); +this.inherited(arguments); +},onDeleteItem:function(_1c){ +if(dojo.indexOf(this.root.children,_1c)!=-1){ +this._requeryTop(); +} +this.inherited(arguments); +}}); +} diff --git a/lib/dijit/tree/TreeStoreModel.js b/lib/dijit/tree/TreeStoreModel.js new file mode 100644 index 000000000..c03bef526 --- /dev/null +++ b/lib/dijit/tree/TreeStoreModel.js @@ -0,0 +1,145 @@ +/* + Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Available via Academic Free License >= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + + +if(!dojo._hasResource["dijit.tree.TreeStoreModel"]){ +dojo._hasResource["dijit.tree.TreeStoreModel"]=true; +dojo.provide("dijit.tree.TreeStoreModel"); +dojo.declare("dijit.tree.TreeStoreModel",null,{store:null,childrenAttrs:["children"],newItemIdAttr:"id",labelAttr:"",root:null,query:null,deferItemLoadingUntilExpand:false,constructor:function(_1){ +dojo.mixin(this,_1); +this.connects=[]; +var _2=this.store; +if(!_2.getFeatures()["dojo.data.api.Identity"]){ +throw new Error("dijit.Tree: store must support dojo.data.Identity"); +} +if(_2.getFeatures()["dojo.data.api.Notification"]){ +this.connects=this.connects.concat([dojo.connect(_2,"onNew",this,"onNewItem"),dojo.connect(_2,"onDelete",this,"onDeleteItem"),dojo.connect(_2,"onSet",this,"onSetItem")]); +} +},destroy:function(){ +dojo.forEach(this.connects,dojo.disconnect); +},getRoot:function(_3,_4){ +if(this.root){ +_3(this.root); +}else{ +this.store.fetch({query:this.query,onComplete:dojo.hitch(this,function(_5){ +if(_5.length!=1){ +throw new Error(this.declaredClass+": query "+dojo.toJson(this.query)+" returned "+_5.length+" items, but must return exactly one item"); +} +this.root=_5[0]; +_3(this.root); +}),onError:_4}); +} +},mayHaveChildren:function(_6){ +return dojo.some(this.childrenAttrs,function(_7){ +return this.store.hasAttribute(_6,_7); +},this); +},getChildren:function(_8,_9,_a){ +var _b=this.store; +if(!_b.isItemLoaded(_8)){ +var _c=dojo.hitch(this,arguments.callee); +_b.loadItem({item:_8,onItem:function(_d){ +_c(_d,_9,_a); +},onError:_a}); +return; +} +var _e=[]; +for(var i=0;i= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + + +if(!dojo._hasResource["dijit.tree._dndContainer"]){ +dojo._hasResource["dijit.tree._dndContainer"]=true; +dojo.provide("dijit.tree._dndContainer"); +dojo.require("dojo.dnd.common"); +dojo.require("dojo.dnd.Container"); +dojo.declare("dijit.tree._dndContainer",null,{constructor:function(_1,_2){ +this.tree=_1; +this.node=_1.domNode; +dojo.mixin(this,_2); +this.map={}; +this.current=null; +this.containerState=""; +dojo.addClass(this.node,"dojoDndContainer"); +this.events=[dojo.connect(this.node,"onmouseenter",this,"onOverEvent"),dojo.connect(this.node,"onmouseleave",this,"onOutEvent"),dojo.connect(this.tree,"_onNodeMouseEnter",this,"onMouseOver"),dojo.connect(this.tree,"_onNodeMouseLeave",this,"onMouseOut"),dojo.connect(this.node,"ondragstart",dojo,"stopEvent"),dojo.connect(this.node,"onselectstart",dojo,"stopEvent")]; +},getItem:function(_3){ +var _4=this.selection[_3],_5={data:dijit.getEnclosingWidget(_4),type:["treeNode"]}; +return _5; +},destroy:function(){ +dojo.forEach(this.events,dojo.disconnect); +this.node=this.parent=null; +},onMouseOver:function(_6,_7){ +this.current=_6.rowNode; +this.currentWidget=_6; +},onMouseOut:function(_8,_9){ +this.current=null; +this.currentWidget=null; +},_changeState:function(_a,_b){ +var _c="dojoDnd"+_a; +var _d=_a.toLowerCase()+"State"; +dojo.removeClass(this.node,_c+this[_d]); +dojo.addClass(this.node,_c+_b); +this[_d]=_b; +},_addItemClass:function(_e,_f){ +dojo.addClass(_e,"dojoDndItem"+_f); +},_removeItemClass:function(_10,_11){ +dojo.removeClass(_10,"dojoDndItem"+_11); +},onOverEvent:function(){ +this._changeState("Container","Over"); +},onOutEvent:function(){ +this._changeState("Container",""); +}}); +} diff --git a/lib/dijit/tree/_dndSelector.js b/lib/dijit/tree/_dndSelector.js new file mode 100644 index 000000000..3d7795598 --- /dev/null +++ b/lib/dijit/tree/_dndSelector.js @@ -0,0 +1,125 @@ +/* + Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Available via Academic Free License >= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + + +if(!dojo._hasResource["dijit.tree._dndSelector"]){ +dojo._hasResource["dijit.tree._dndSelector"]=true; +dojo.provide("dijit.tree._dndSelector"); +dojo.require("dojo.dnd.common"); +dojo.require("dijit.tree._dndContainer"); +dojo.declare("dijit.tree._dndSelector",dijit.tree._dndContainer,{constructor:function(_1,_2){ +this.selection={}; +this.anchor=null; +this.simpleSelection=false; +this.events.push(dojo.connect(this.tree.domNode,"onmousedown",this,"onMouseDown"),dojo.connect(this.tree.domNode,"onmouseup",this,"onMouseUp"),dojo.connect(this.tree.domNode,"onmousemove",this,"onMouseMove")); +},singular:false,getSelectedNodes:function(){ +return this.selection; +},selectNone:function(){ +return this._removeSelection()._removeAnchor(); +},destroy:function(){ +this.inherited(arguments); +this.selection=this.anchor=null; +},onMouseDown:function(e){ +if(!this.current){ +return; +} +if(e.button==dojo.mouseButtons.RIGHT){ +return; +} +var _3=dijit.getEnclosingWidget(this.current),id=_3.id+"-dnd"; +if(!dojo.hasAttr(this.current,"id")){ +dojo.attr(this.current,"id",id); +} +if(!this.singular&&!dojo.isCopyKey(e)&&!e.shiftKey&&(this.current.id in this.selection)){ +this.simpleSelection=true; +dojo.stopEvent(e); +return; +} +if(this.singular){ +if(this.anchor==this.current){ +if(dojo.isCopyKey(e)){ +this.selectNone(); +} +}else{ +this.selectNone(); +this.anchor=this.current; +this._addItemClass(this.anchor,"Anchor"); +this.selection[this.current.id]=this.current; +} +}else{ +if(!this.singular&&e.shiftKey){ +if(dojo.isCopyKey(e)){ +}else{ +} +}else{ +if(dojo.isCopyKey(e)){ +if(this.anchor==this.current){ +delete this.selection[this.anchor.id]; +this._removeAnchor(); +}else{ +if(this.current.id in this.selection){ +this._removeItemClass(this.current,"Selected"); +delete this.selection[this.current.id]; +}else{ +if(this.anchor){ +this._removeItemClass(this.anchor,"Anchor"); +this._addItemClass(this.anchor,"Selected"); +} +this.anchor=this.current; +this._addItemClass(this.current,"Anchor"); +this.selection[this.current.id]=this.current; +} +} +}else{ +if(!(id in this.selection)){ +this.selectNone(); +this.anchor=this.current; +this._addItemClass(this.current,"Anchor"); +this.selection[id]=this.current; +} +} +} +} +dojo.stopEvent(e); +},onMouseUp:function(e){ +if(!this.simpleSelection){ +return; +} +this.simpleSelection=false; +this.selectNone(); +if(this.current){ +this.anchor=this.current; +this._addItemClass(this.anchor,"Anchor"); +this.selection[this.current.id]=this.current; +} +},onMouseMove:function(e){ +this.simpleSelection=false; +},_removeSelection:function(){ +var e=dojo.dnd._empty; +for(var i in this.selection){ +if(i in e){ +continue; +} +var _4=dojo.byId(i); +if(_4){ +this._removeItemClass(_4,"Selected"); +} +} +this.selection={}; +return this; +},_removeAnchor:function(){ +if(this.anchor){ +this._removeItemClass(this.anchor,"Anchor"); +this.anchor=null; +} +return this; +},forInSelectedItems:function(f,o){ +o=o||dojo.global; +for(var id in this.selection){ +f.call(o,this.getItem(id),id,this); +} +}}); +} diff --git a/lib/dijit/tree/dndSource.js b/lib/dijit/tree/dndSource.js new file mode 100644 index 000000000..ef129d9cb --- /dev/null +++ b/lib/dijit/tree/dndSource.js @@ -0,0 +1,240 @@ +/* + Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Available via Academic Free License >= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + + +if(!dojo._hasResource["dijit.tree.dndSource"]){ +dojo._hasResource["dijit.tree.dndSource"]=true; +dojo.provide("dijit.tree.dndSource"); +dojo.require("dijit.tree._dndSelector"); +dojo.require("dojo.dnd.Manager"); +dojo.declare("dijit.tree.dndSource",dijit.tree._dndSelector,{isSource:true,accept:["text","treeNode"],copyOnly:false,dragThreshold:5,betweenThreshold:0,constructor:function(_1,_2){ +if(!_2){ +_2={}; +} +dojo.mixin(this,_2); +this.isSource=typeof _2.isSource=="undefined"?true:_2.isSource; +var _3=_2.accept instanceof Array?_2.accept:["text","treeNode"]; +this.accept=null; +if(_3.length){ +this.accept={}; +for(var i=0;i<_3.length;++i){ +this.accept[_3[i]]=1; +} +} +this.isDragging=false; +this.mouseDown=false; +this.targetAnchor=null; +this.targetBox=null; +this.dropPosition=""; +this._lastX=0; +this._lastY=0; +this.sourceState=""; +if(this.isSource){ +dojo.addClass(this.node,"dojoDndSource"); +} +this.targetState=""; +if(this.accept){ +dojo.addClass(this.node,"dojoDndTarget"); +} +this.topics=[dojo.subscribe("/dnd/source/over",this,"onDndSourceOver"),dojo.subscribe("/dnd/start",this,"onDndStart"),dojo.subscribe("/dnd/drop",this,"onDndDrop"),dojo.subscribe("/dnd/cancel",this,"onDndCancel")]; +},checkAcceptance:function(_4,_5){ +return true; +},copyState:function(_6){ +return this.copyOnly||_6; +},destroy:function(){ +this.inherited("destroy",arguments); +dojo.forEach(this.topics,dojo.unsubscribe); +this.targetAnchor=null; +},_onDragMouse:function(e){ +var m=dojo.dnd.manager(),_7=this.targetAnchor,_8=this.current,_9=this.currentWidget,_a=this.dropPosition; +var _b="Over"; +if(_8&&this.betweenThreshold>0){ +if(!this.targetBox||_7!=_8){ +this.targetBox=dojo.position(_8,true); +} +if((e.pageY-this.targetBox.y)<=this.betweenThreshold){ +_b="Before"; +}else{ +if((e.pageY-this.targetBox.y)>=(this.targetBox.h-this.betweenThreshold)){ +_b="After"; +} +} +} +if(_8!=_7||_b!=_a){ +if(_7){ +this._removeItemClass(_7,_a); +} +if(_8){ +this._addItemClass(_8,_b); +} +if(!_8){ +m.canDrop(false); +}else{ +if(_9==this.tree.rootNode&&_b!="Over"){ +m.canDrop(false); +}else{ +if(m.source==this&&(_8.id in this.selection)){ +m.canDrop(false); +}else{ +if(this.checkItemAcceptance(_8,m.source,_b.toLowerCase())&&!this._isParentChildDrop(m.source,_8)){ +m.canDrop(true); +}else{ +m.canDrop(false); +} +} +} +} +this.targetAnchor=_8; +this.dropPosition=_b; +} +},onMouseMove:function(e){ +if(this.isDragging&&this.targetState=="Disabled"){ +return; +} +this.inherited(arguments); +var m=dojo.dnd.manager(); +if(this.isDragging){ +this._onDragMouse(e); +}else{ +if(this.mouseDown&&this.isSource&&(Math.abs(e.pageX-this._lastX)>=this.dragThreshold||Math.abs(e.pageY-this._lastY)>=this.dragThreshold)){ +var n=this.getSelectedNodes(); +var _c=[]; +for(var i in n){ +_c.push(n[i]); +} +if(_c.length){ +m.startDrag(this,_c,this.copyState(dojo.isCopyKey(e))); +} +} +} +},onMouseDown:function(e){ +this.mouseDown=true; +this.mouseButton=e.button; +this._lastX=e.pageX; +this._lastY=e.pageY; +this.inherited("onMouseDown",arguments); +},onMouseUp:function(e){ +if(this.mouseDown){ +this.mouseDown=false; +this.inherited("onMouseUp",arguments); +} +},onMouseOut:function(){ +this.inherited(arguments); +this._unmarkTargetAnchor(); +},checkItemAcceptance:function(_d,_e,_f){ +return true; +},onDndSourceOver:function(_10){ +if(this!=_10){ +this.mouseDown=false; +this._unmarkTargetAnchor(); +}else{ +if(this.isDragging){ +var m=dojo.dnd.manager(); +m.canDrop(false); +} +} +},onDndStart:function(_11,_12,_13){ +if(this.isSource){ +this._changeState("Source",this==_11?(_13?"Copied":"Moved"):""); +} +var _14=this.checkAcceptance(_11,_12); +this._changeState("Target",_14?"":"Disabled"); +if(this==_11){ +dojo.dnd.manager().overSource(this); +} +this.isDragging=true; +},itemCreator:function(_15,_16,_17){ +return dojo.map(_15,function(_18){ +return {"id":_18.id,"name":_18.textContent||_18.innerText||""}; +}); +},onDndDrop:function(_19,_1a,_1b){ +if(this.containerState=="Over"){ +var _1c=this.tree,_1d=_1c.model,_1e=this.targetAnchor,_1f=false; +this.isDragging=false; +var _20=dijit.getEnclosingWidget(_1e); +var _21; +var _22; +_21=(_20&&_20.item)||_1c.item; +if(this.dropPosition=="Before"||this.dropPosition=="After"){ +_21=(_20.getParent()&&_20.getParent().item)||_1c.item; +_22=_20.getIndexInParent(); +if(this.dropPosition=="After"){ +_22=_20.getIndexInParent()+1; +} +}else{ +_21=(_20&&_20.item)||_1c.item; +} +var _23; +dojo.forEach(_1a,function(_24,idx){ +var _25=_19.getItem(_24.id); +if(dojo.indexOf(_25.type,"treeNode")!=-1){ +var _26=_25.data,_27=_26.item,_28=_26.getParent().item; +} +if(_19==this){ +if(typeof _22=="number"){ +if(_21==_28&&_26.getIndexInParent()<_22){ +_22-=1; +} +} +_1d.pasteItem(_27,_28,_21,_1b,_22); +}else{ +if(_1d.isItem(_27)){ +_1d.pasteItem(_27,_28,_21,_1b,_22); +}else{ +if(!_23){ +_23=this.itemCreator(_1a,_1e,_19); +} +_1d.newItem(_23[idx],_21,_22); +} +} +},this); +this.tree._expandNode(_20); +} +this.onDndCancel(); +},onDndCancel:function(){ +this._unmarkTargetAnchor(); +this.isDragging=false; +this.mouseDown=false; +delete this.mouseButton; +this._changeState("Source",""); +this._changeState("Target",""); +},onOverEvent:function(){ +this.inherited(arguments); +dojo.dnd.manager().overSource(this); +},onOutEvent:function(){ +this._unmarkTargetAnchor(); +var m=dojo.dnd.manager(); +if(this.isDragging){ +m.canDrop(false); +} +m.outSource(this); +this.inherited(arguments); +},_isParentChildDrop:function(_29,_2a){ +if(!_29.tree||_29.tree!=this.tree){ +return false; +} +var _2b=_29.tree.domNode; +var ids={}; +for(var x in _29.selection){ +ids[_29.selection[x].parentNode.id]=true; +} +var _2c=_2a.parentNode; +while(_2c!=_2b&&(!_2c.id||!ids[_2c.id])){ +_2c=_2c.parentNode; +} +return _2c.id&&ids[_2c.id]; +},_unmarkTargetAnchor:function(){ +if(!this.targetAnchor){ +return; +} +this._removeItemClass(this.targetAnchor,this.dropPosition); +this.targetAnchor=null; +this.targetBox=null; +this.dropPosition=null; +},_markDndStatus:function(_2d){ +this._changeState("Source",_2d?"Copied":"Moved"); +}}); +} diff --git a/lib/dijit/tree/model.js b/lib/dijit/tree/model.js new file mode 100644 index 000000000..091d72fca --- /dev/null +++ b/lib/dijit/tree/model.js @@ -0,0 +1,20 @@ +/* + Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Available via Academic Free License >= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + + +dojo.declare("dijit.tree.model",null,{destroy:function(){ +},getRoot:function(_1){ +},mayHaveChildren:function(_2){ +},getChildren:function(_3,_4){ +},isItem:function(_5){ +},fetchItemByIdentity:function(_6){ +},getIdentity:function(_7){ +},getLabel:function(_8){ +},newItem:function(_9,_a,_b){ +},pasteItem:function(_c,_d,_e,_f){ +},onChange:function(_10){ +},onChildrenChange:function(_11,_12){ +}}); -- cgit v1.2.3