You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

298 lines
9.8 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.onReady(function() {
  16. var patients = [{
  17. insuranceCode: '11111',
  18. name: 'Fred Bloggs',
  19. address: 'Main Street',
  20. telephone: '555 1234 123'
  21. }, {
  22. insuranceCode: '22222',
  23. name: 'Fred West',
  24. address: 'Cromwell Street',
  25. telephone: '666 666 666'
  26. }, {
  27. insuranceCode: '33333',
  28. name: 'Fred Mercury',
  29. address: 'Over The Rainbow',
  30. telephone: '555 321 0987'
  31. }, {
  32. insuranceCode: '44444',
  33. name: 'Fred Forsyth',
  34. address: 'Blimp Street',
  35. telephone: '555 111 2222'
  36. }, {
  37. insuranceCode: '55555',
  38. name: 'Fred Douglass',
  39. address: 'Talbot County, Maryland',
  40. telephone: 'N/A'
  41. }];
  42. var PatientRecord = Ext.data.Record.create([{
  43. name: 'name'
  44. }, {
  45. name: 'address'
  46. }, {
  47. name: 'telephone'
  48. }]);
  49. var patientStore = new Ext.data.Store({
  50. data: patients,
  51. reader: new Ext.data.JsonReader({
  52. id: 'insuranceCode'
  53. }, PatientRecord)
  54. });
  55. var hospitals = [{
  56. code: 'AAAAA',
  57. name: 'Saint Thomas',
  58. address: 'Westminster Bridge Road, SE1 7EH',
  59. telephone: '020 7188 7188'
  60. }, {
  61. code: 'BBBBB',
  62. name: 'Queen\'s Medical Centre',
  63. address: 'Derby Road, NG7 2UH',
  64. telephone: '0115 924 9924'
  65. }, {
  66. code: 'CCCCC',
  67. name: 'Saint Bartholomew',
  68. address: 'West Smithfield, EC1A 7BE',
  69. telephone: '020 7377 7000'
  70. }, {
  71. code: 'DDDDD',
  72. name: 'Royal London',
  73. address: 'Whitechapel, E1 1BB',
  74. telephone: '020 7377 7000'
  75. }];
  76. var HospitalRecord = Ext.data.Record.create([{
  77. name: 'name'
  78. }, {
  79. name: 'address'
  80. }, {
  81. name: 'telephone'
  82. }]);
  83. var hospitalStore = new Ext.data.Store({
  84. data: hospitals,
  85. reader: new Ext.data.JsonReader({
  86. id: 'code'
  87. }, HospitalRecord)
  88. });
  89. var patientView = new Ext.DataView({
  90. cls: 'patient-view',
  91. tpl: '<tpl for=".">' +
  92. '<div class="patient-source"><table><tbody>' +
  93. '<tr><td class="patient-label">Name</td><td class="patient-name">{name}</td></tr>' +
  94. '<tr><td class="patient-label">Address</td><td class="patient-name">{address}</td></tr>' +
  95. '<tr><td class="patient-label">Telephone</td><td class="patient-name">{telephone}</td></tr>' +
  96. '</tbody></table></div>' +
  97. '</tpl>',
  98. itemSelector: 'div.patient-source',
  99. overClass: 'patient-over',
  100. selectedClass: 'patient-selected',
  101. singleSelect: true,
  102. store: patientStore,
  103. listeners: {
  104. render: initializePatientDragZone
  105. }
  106. });
  107. var helpWindow = new Ext.Window({
  108. title: 'Source code',
  109. width: 920,
  110. height: 500,
  111. closeAction: 'hide',
  112. bodyCfg: {tag: 'textarea', readonly: true},
  113. bodyStyle: {
  114. backgroundColor: 'white',
  115. margin: '0px',
  116. border: '0px none'
  117. },
  118. listeners: {
  119. render: function(w) {
  120. Ext.Ajax.request({
  121. url: 'dragdropzones.js',
  122. success: function(r) {
  123. w.body.dom.value = r.responseText;
  124. }
  125. });
  126. }
  127. }
  128. });
  129. var hospitalGrid = new Ext.grid.GridPanel({
  130. title: 'Hospitals',
  131. region: 'center',
  132. margins: '0 5 5 0',
  133. bbar: [{
  134. text: 'View Source',
  135. handler: function() {
  136. helpWindow.show();
  137. }
  138. }],
  139. columns: [{
  140. dataIndex: 'name',
  141. header: 'Name',
  142. width: 200
  143. }, {
  144. dataIndex: 'address',
  145. header: 'Address',
  146. width: 300
  147. }, {
  148. dataIndex: 'telephone',
  149. header: 'Telephone',
  150. width: 100
  151. }],
  152. viewConfig: {
  153. tpl: new Ext.XTemplate('<div class="hospital-target">Drop Patient Here</div>'),
  154. enableRowBody: true,
  155. getRowClass: function(rec, idx, p, store) {
  156. p.body = this.tpl.apply(rec.data);
  157. }
  158. },
  159. store: hospitalStore,
  160. listeners: {
  161. render: initializeHospitalDropZone
  162. }
  163. });
  164. new Ext.Viewport({
  165. layout: 'border',
  166. items: [{
  167. cls: 'app-header',
  168. region: 'north',
  169. height: 30,
  170. html: '<h1>Patient Hospital Assignment</h1>',
  171. margins: '5 5 5 5'
  172. }, {
  173. title: 'Patients',
  174. region: 'west',
  175. width: 300,
  176. margins: '0 5 5 5',
  177. items: patientView
  178. }, hospitalGrid ]
  179. });
  180. });
  181. /*
  182. * Here is where we "activate" the DataView.
  183. * We have decided that each node with the class "patient-source" encapsulates a single draggable
  184. * object.
  185. *
  186. * So we inject code into the DragZone which, when passed a mousedown event, interrogates
  187. * the event to see if it was within an element with the class "patient-source". If so, we
  188. * return non-null drag data.
  189. *
  190. * Returning non-null drag data indicates that the mousedown event has begun a dragging process.
  191. * The data must contain a property called "ddel" which is a DOM element which provides an image
  192. * of the data being dragged. The actual node clicked on is not dragged, a proxy element is dragged.
  193. * We can insert any other data into the data object, and this will be used by a cooperating DropZone
  194. * to perform the drop operation.
  195. */
  196. function initializePatientDragZone(v) {
  197. v.dragZone = new Ext.dd.DragZone(v.getEl(), {
  198. // On receipt of a mousedown event, see if it is within a draggable element.
  199. // Return a drag data object if so. The data object can contain arbitrary application
  200. // data, but it should also contain a DOM element in the ddel property to provide
  201. // a proxy to drag.
  202. getDragData: function(e) {
  203. var sourceEl = e.getTarget(v.itemSelector, 10);
  204. if (sourceEl) {
  205. d = sourceEl.cloneNode(true);
  206. d.id = Ext.id();
  207. return v.dragData = {
  208. sourceEl: sourceEl,
  209. repairXY: Ext.fly(sourceEl).getXY(),
  210. ddel: d,
  211. patientData: v.getRecord(sourceEl).data
  212. }
  213. }
  214. },
  215. // Provide coordinates for the proxy to slide back to on failed drag.
  216. // This is the original XY coordinates of the draggable element.
  217. getRepairXY: function() {
  218. return this.dragData.repairXY;
  219. }
  220. });
  221. }
  222. /*
  223. * Here is where we "activate" the GridPanel.
  224. * We have decided that the element with class "hospital-target" is the element which can receieve
  225. * drop gestures. So we inject a method "getTargetFromEvent" into the DropZone. This is constantly called
  226. * while the mouse is moving over the DropZone, and it returns the target DOM element if it detects that
  227. * the mouse if over an element which can receieve drop gestures.
  228. *
  229. * Once the DropZone has been informed by getTargetFromEvent that it is over a target, it will then
  230. * call several "onNodeXXXX" methods at various points. These include:
  231. *
  232. * onNodeEnter
  233. * onNodeOut
  234. * onNodeOver
  235. * onNodeDrop
  236. *
  237. * We provide implementations of each of these to provide behaviour for these events.
  238. */
  239. function initializeHospitalDropZone(g) {
  240. g.dropZone = new Ext.dd.DropZone(g.getView().scroller, {
  241. // If the mouse is over a target node, return that node. This is
  242. // provided as the "target" parameter in all "onNodeXXXX" node event handling functions
  243. getTargetFromEvent: function(e) {
  244. return e.getTarget('.hospital-target');
  245. },
  246. // On entry into a target node, highlight that node.
  247. onNodeEnter : function(target, dd, e, data){
  248. Ext.fly(target).addClass('hospital-target-hover');
  249. },
  250. // On exit from a target node, unhighlight that node.
  251. onNodeOut : function(target, dd, e, data){
  252. Ext.fly(target).removeClass('hospital-target-hover');
  253. },
  254. // While over a target node, return the default drop allowed class which
  255. // places a "tick" icon into the drag proxy.
  256. onNodeOver : function(target, dd, e, data){
  257. return Ext.dd.DropZone.prototype.dropAllowed;
  258. },
  259. // On node drop, we can interrogate the target node to find the underlying
  260. // application object that is the real target of the dragged data.
  261. // In this case, it is a Record in the GridPanel's Store.
  262. // We can use the data set up by the DragZone's getDragData method to read
  263. // any data we decided to attach.
  264. onNodeDrop : function(target, dd, e, data){
  265. var rowIndex = g.getView().findRowIndex(target);
  266. var h = g.getStore().getAt(rowIndex);
  267. var targetEl = Ext.get(target);
  268. targetEl.update(data.patientData.name+', '+targetEl.dom.innerHTML);
  269. Ext.Msg.alert('Drop gesture', 'Dropped patient ' + data.patientData.name +
  270. ' on hospital ' + h.data.name);
  271. return true;
  272. }
  273. });
  274. }