Web Interface For Lite Argus Control modules
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.

284 lines
9.2 KiB

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