]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | Ext.onReady(function() {\r |
2 | // Create an object that we'll use to implement and override drag behaviors a little later\r | |
3 | var overrides = {\r | |
4 | // Called the instance the element is dragged.\r | |
5 | b4StartDrag : function() {\r | |
6 | // Cache the drag element\r | |
7 | if (!this.el) {\r | |
8 | this.el = Ext.get(this.getEl());\r | |
9 | }\r | |
10 | \r | |
11 | //Cache the original XY Coordinates of the element, we'll use this later.\r | |
12 | this.originalXY = this.el.getXY();\r | |
13 | },\r | |
14 | // Called when element is dropped not anything other than a dropzone with the same ddgroup\r | |
15 | onInvalidDrop : function() {\r | |
16 | // Set a flag to invoke the animated repair\r | |
17 | this.invalidDrop = true;\r | |
18 | },\r | |
19 | // Called when the drag operation completes\r | |
20 | endDrag : function() {\r | |
21 | // Invoke the animation if the invalidDrop flag is set to true\r | |
22 | if (this.invalidDrop === true) {\r | |
23 | // Remove the drop invitation\r | |
24 | this.el.removeCls('dropOK');\r | |
25 | \r | |
26 | // Create the animation configuration object\r | |
27 | var animCfgObj = {\r | |
28 | easing : 'elasticOut',\r | |
29 | duration : 1,\r | |
30 | scope : this,\r | |
31 | callback : function() {\r | |
32 | // Remove the position attribute\r | |
33 | this.el.dom.style.position = '';\r | |
34 | }\r | |
35 | };\r | |
36 | \r | |
37 | // Apply the repair animation\r | |
38 | this.el.setXY([this.originalXY[0], this.originalXY[1]], animCfgObj);\r | |
39 | delete this.invalidDrop;\r | |
40 | }\r | |
41 | },\r | |
42 | // Called upon successful drop of an element on a DDTarget with the same\r | |
43 | onDragDrop : function(evtObj, targetElId) {\r | |
44 | // Wrap the drop target element with Ext.Element\r | |
45 | var dropEl = Ext.get(targetElId);\r | |
46 | \r | |
47 | // Perform the node move only if the drag element's\r | |
48 | // parent is not the same as the drop target\r | |
49 | if (this.el.dom.parentNode.id != targetElId) {\r | |
50 | \r | |
51 | // Move the element\r | |
52 | dropEl.appendChild(this.el);\r | |
53 | \r | |
54 | // Remove the drag invitation\r | |
55 | this.onDragOut(evtObj, targetElId);\r | |
56 | \r | |
57 | // Clear the styles\r | |
58 | this.el.dom.style.position ='';\r | |
59 | this.el.dom.style.top = '';\r | |
60 | this.el.dom.style.left = '';\r | |
61 | }\r | |
62 | else {\r | |
63 | // This was an invalid drop, initiate a repair\r | |
64 | this.onInvalidDrop();\r | |
65 | }\r | |
66 | },\r | |
67 | // Only called when the drag element is dragged over the a drop target with the same ddgroup\r | |
68 | onDragEnter : function(evtObj, targetElId) {\r | |
69 | // Colorize the drag target if the drag node's parent is not the same as the drop target\r | |
70 | if (targetElId != this.el.dom.parentNode.id) {\r | |
71 | this.el.addCls('dropOK');\r | |
72 | }\r | |
73 | else {\r | |
74 | // Remove the invitation\r | |
75 | this.onDragOut();\r | |
76 | }\r | |
77 | },\r | |
78 | // Only called when element is dragged out of a dropzone with the same ddgroup\r | |
79 | onDragOut : function(evtObj, targetElId) {\r | |
80 | this.el.removeCls('dropOK');\r | |
81 | }\r | |
82 | };\r | |
83 | \r | |
84 | // Configure the cars to be draggable\r | |
85 | var carElements = Ext.get('cars').select('div');\r | |
86 | Ext.each(carElements.elements, function(el) {\r | |
87 | var dd = Ext.create('Ext.dd.DD', el, 'carsDDGroup', {\r | |
88 | isTarget : false\r | |
89 | });\r | |
90 | //Apply the overrides object to the newly created instance of DD\r | |
91 | Ext.apply(dd, overrides);\r | |
92 | });\r | |
93 | \r | |
94 | var truckElements = Ext.get('trucks').select('div');\r | |
95 | Ext.each(truckElements.elements, function(el) {\r | |
96 | var dd = Ext.create('Ext.dd.DD', el, 'trucksDDGroup', {\r | |
97 | isTarget : false\r | |
98 | });\r | |
99 | Ext.apply(dd, overrides);\r | |
100 | });\r | |
101 | \r | |
102 | // Instantiate instances of Ext.dd.DDTarget for the cars and trucks container\r | |
103 | var carsDDTarget = Ext.create('Ext.dd.DDTarget', 'cars','carsDDGroup');\r | |
104 | var trucksDDTarget = Ext.create('Ext.dd.DDTarget', 'trucks', 'trucksDDGroup');\r | |
105 | \r | |
106 | // Instantiate instnaces of DDTarget for the rented and repair drop target elements\r | |
107 | var rentedDDTarget = Ext.create('Ext.dd.DDTarget', 'rented', 'carsDDGroup');\r | |
108 | var repairDDTarget = Ext.create('Ext.dd.DDTarget', 'repair', 'carsDDGroup');\r | |
109 | \r | |
110 | // Ensure that the rented and repair DDTargets will participate in the trucksDDGroup\r | |
111 | rentedDDTarget.addToGroup('trucksDDGroup');\r | |
112 | repairDDTarget.addToGroup('trucksDDGroup');\r | |
113 | \r | |
114 | });\r |