]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dijit/_tree/dndSelector.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dijit / _tree / dndSelector.js
1 if(!dojo._hasResource["dijit._tree.dndSelector"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dijit._tree.dndSelector"] = true;
3 dojo.provide("dijit._tree.dndSelector");
4 dojo.require("dojo.dnd.common");
5 dojo.require("dijit._tree.dndContainer");
6
7 dojo.declare("dijit._tree.dndSelector",
8         dijit._tree.dndContainer,
9         {
10                 constructor: function(tree, params){
11                         this.selection={};
12                         this.anchor = null;
13                         this.simpleSelection=false;
14                 
15                         this.events.push(
16                                 dojo.connect(this.tree.domNode, "onmousedown", this,"onMouseDown"),
17                                 dojo.connect(this.tree.domNode, "onmouseup", this,"onMouseUp")
18                         );
19                 },
20         
21                 // object attributes (for markup)
22                 singular: false,        // is singular property
23         
24                 // methods
25                 getSelectedItems: function(){
26                         var selectedItems = []
27                         for (var i in this.selection){
28                                 selectedItems.push(dijit.getEnclosingWidget(this.selection[i]).item);
29                         }
30                         return selectedItems;
31                 },
32
33                 getSelectedNodes: function(){
34                         return this.selection;
35                 },
36
37                 selectNone: function(){
38                         // summary: unselects all items
39                         return this._removeSelection()._removeAnchor(); // self
40                 },
41
42                 insertItems: function(item, parent){
43                         // summary: inserts new data items (see Container's insertNodes method for details)
44                         
45                         //we actually need to add things to the store here instead of adding noes to the tree directly          
46                 },
47
48                 destroy: function(){
49                         // summary: prepares the object to be garbage-collected
50                         dojo.dnd.Selector.superclass.destroy.call(this);
51                         this.selection = this.anchor = null;
52                 },
53
54                 // mouse events
55                 onMouseDown: function(e){
56                         // summary: event processor for onmousedown
57                         // e: Event: mouse event
58                         if(!this.current){ return; }
59
60                         var item = dijit.getEnclosingWidget(this.current).item
61                         var id = this.tree.model.getIdentity(item);
62
63                         if (!this.current.id) {
64                                 this.current.id=id;
65                         }
66
67                         if (!this.current.type) {
68                                 this.current.type="data";
69                         }
70
71                         if(!this.singular && !dojo.dnd.getCopyKeyState(e) && !e.shiftKey && (this.current.id in this.selection)){
72                                 this.simpleSelection = true;
73                                 dojo.stopEvent(e);
74                                 return;
75                         }
76
77                         if(this.singular){
78                                 if(this.anchor == this.current){
79                                         if(dojo.dnd.getCopyKeyState(e)){
80                                                 this.selectNone();
81                                         }
82                                 }else{
83                                         this.selectNone();
84                                         this.anchor = this.current;
85                                         this._addItemClass(this.anchor, "Anchor");
86
87                                         this.selection[this.current.id] = this.current;
88                                 }
89                         }else{
90                                 if(!this.singular && e.shiftKey){       
91                                         if (dojo.dnd.getCopyKeyState(e)){
92                                                 //TODO add range to selection
93                                         }else{
94                                                 //TODO select new range from anchor 
95                                         }
96                                 }else{
97                                         if(dojo.dnd.getCopyKeyState(e)){
98                                                 if(this.anchor == this.current){
99                                                         delete this.selection[this.anchor.id];
100                                                         this._removeAnchor();
101                                                 }else{
102                                                         if(this.current.id in this.selection){
103                                                                 this._removeItemClass(this.current, "Selected");
104                                                                 delete this.selection[this.current.id];
105                                                         }else{
106                                                                 if(this.anchor){
107                                                                         this._removeItemClass(this.anchor, "Anchor");
108                                                                         this._addItemClass(this.anchor, "Selected");
109                                                                 }
110                                                                 this.anchor = this.current;
111                                                                 this._addItemClass(this.current, "Anchor");
112                                                                 this.selection[this.current.id] = this.current;
113                                                         }
114                                                 }
115                                         }else{
116                                                 var item = dijit.getEnclosingWidget(this.current).item
117                                                 var id = this.tree.model.getIdentity(item);
118                                                 if(!(id in this.selection)){
119                                                         this.selectNone();
120                                                         this.anchor = this.current;
121                                                         this._addItemClass(this.current, "Anchor");
122                                                         this.selection[id] = this.current;
123                                                 }
124                                         }
125                                 }
126                         }
127
128                         dojo.stopEvent(e);
129                 },
130
131                 onMouseMove: function() {
132
133                 },
134
135                 onOverEvent: function() {
136                         this.onmousemoveEvent = dojo.connect(this.node, "onmousemove", this, "onMouseMove");
137                 },
138
139                 onMouseUp: function(e){
140                         // summary: event processor for onmouseup
141                         // e: Event: mouse event
142                         if(!this.simpleSelection){ return; }
143                         this.simpleSelection = false;
144                         this.selectNone();
145                         if(this.current){
146                                 this.anchor = this.current;
147                                 this._addItemClass(this.anchor, "Anchor");
148                                 this.selection[this.current.id] = this.current;
149                         }
150                 },
151                 _removeSelection: function(){
152                         // summary: unselects all items
153                         var e = dojo.dnd._empty;
154                         for(var i in this.selection){
155                                 if(i in e){ continue; }
156                                 var node = dojo.byId(i);
157                                 if(node){ this._removeItemClass(node, "Selected"); }
158                         }
159                         this.selection = {};
160                         return this;    // self
161                 },
162                 _removeAnchor: function(){
163                         if(this.anchor){
164                                 this._removeItemClass(this.anchor, "Anchor");
165                                 this.anchor = null;
166                         }
167                         return this;    // self
168                 }
169 });
170
171 }