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.

316 lines
11 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. // A DropZone which cooperates with DragZones whose dragData contains
  8. // a "field" property representing a form Field. Fields may be dropped onto
  9. // grid data cells containing a matching data type.
  10. Ext.ux.CellFieldDropZone = Ext.extend(Ext.dd.DropZone, {
  11. constructor: function(){},
  12. // Call the DropZone constructor using the View's scrolling element
  13. // only after the grid has been rendered.
  14. init: function(grid) {
  15. if (grid.rendered) {
  16. this.grid = grid;
  17. this.view = grid.getView();
  18. this.store = grid.getStore();
  19. Ext.ux.CellFieldDropZone.superclass.constructor.call(this, this.view.scroller);
  20. } else {
  21. grid.on('render', this.init, this);
  22. }
  23. },
  24. // Scroll the main configured Element when we drag close to the edge
  25. containerScroll: true,
  26. getTargetFromEvent: function(e) {
  27. // Ascertain whether the mousemove is within a grid cell
  28. var t = e.getTarget(this.view.cellSelector);
  29. if (t) {
  30. // We *are* within a grid cell, so ask the View exactly which one,
  31. // Extract data from the Model to create a target object for
  32. // processing in subsequent onNodeXXXX methods. Note that the target does
  33. // not have to be a DOM element. It can be whatever the noNodeXXX methods are
  34. // programmed to expect.
  35. var rowIndex = this.view.findRowIndex(t);
  36. var columnIndex = this.view.findCellIndex(t);
  37. if ((rowIndex !== false) && (columnIndex !== false)) {
  38. return {
  39. node: t,
  40. record: this.store.getAt(rowIndex),
  41. fieldName: this.grid.getColumnModel().getDataIndex(columnIndex)
  42. };
  43. }
  44. }
  45. },
  46. // On Node enter, see if it is valid for us to drop the field on that type of column.
  47. onNodeEnter: function(target, dd, e, dragData) {
  48. delete this.dropOK;
  49. if (!target) {
  50. return;
  51. }
  52. // Check that a field is being dragged.
  53. var f = dragData.field;
  54. if (!f) {
  55. return;
  56. }
  57. // Check whether the data type of the column being dropped on accepts the
  58. // dragged field type. If so, set dropOK flag, and highlight the target node.
  59. var type = target.record.fields.get(target.fieldName).type,
  60. types = Ext.data.Types;
  61. switch(type){
  62. case types.FLOAT:
  63. case types.INT:
  64. if (!f.isXType('numberfield')) {
  65. return;
  66. }
  67. break;
  68. case types.DATE:
  69. if (!f.isXType('datefield')) {
  70. return;
  71. }
  72. break;
  73. case types.BOOL:
  74. if (!f.isXType('checkbox')) {
  75. return;
  76. }
  77. }
  78. this.dropOK = true;
  79. Ext.fly(target.node).addClass('x-drop-target-active');
  80. },
  81. // Return the class name to add to the drag proxy. This provides a visual indication
  82. // of drop allowed or not allowed.
  83. onNodeOver: function(target, dd, e, dragData) {
  84. return this.dropOK ? this.dropAllowed : this.dropNotAllowed;
  85. },
  86. // nhighlight the target node.
  87. onNodeOut: function(target, dd, e, dragData) {
  88. Ext.fly(target.node).removeClass('x-drop-target-active');
  89. },
  90. // Process the drop event if we have previously ascertained that a drop is OK.
  91. onNodeDrop: function(target, dd, e, dragData) {
  92. if (this.dropOK) {
  93. target.record.set(target.fieldName, dragData.field.getValue());
  94. return true;
  95. }
  96. }
  97. });
  98. // A class which makes Fields within a Panel draggable.
  99. // the dragData delivered to a coooperating DropZone's methods contains
  100. // the dragged Field in the property "field".
  101. Ext.ux.PanelFieldDragZone = Ext.extend(Ext.dd.DragZone, {
  102. constructor: function(){},
  103. // Call the DRagZone's constructor. The Panel must have been rendered.
  104. init: function(panel) {
  105. if (panel.nodeType) {
  106. Ext.ux.PanelFieldDragZone.superclass.init.apply(this, arguments);
  107. } else {
  108. if (panel.rendered) {
  109. Ext.ux.PanelFieldDragZone.superclass.constructor.call(this, panel.getEl());
  110. var i = Ext.fly(panel.getEl()).select('input');
  111. i.unselectable();
  112. } else {
  113. panel.on('afterlayout', this.init, this, {single: true});
  114. }
  115. }
  116. },
  117. scroll: false,
  118. // On mousedown, we ascertain whether it is on one of our draggable Fields.
  119. // If so, we collect data about the draggable object, and return a drag data
  120. // object which contains our own data, plus a "ddel" property which is a DOM
  121. // node which provides a "view" of the dragged data.
  122. getDragData: function(e) {
  123. var t = e.getTarget('input');
  124. if (t) {
  125. e.stopEvent();
  126. // Ugly code to "detach" the drag gesture from the input field.
  127. // Without this, Opera never changes the mouseover target from the input field
  128. // even when dragging outside of the field - it just keeps selecting.
  129. if (Ext.isOpera) {
  130. Ext.fly(t).on('mousemove', function(e1){
  131. t.style.visibility = 'hidden';
  132. (function(){
  133. t.style.visibility = '';
  134. }).defer(1);
  135. }, null, {single:true});
  136. }
  137. // Get the data we are dragging: the Field
  138. // create a ddel for the drag proxy to display
  139. var f = Ext.getCmp(t.id);
  140. var d = document.createElement('div');
  141. d.className = 'x-form-text';
  142. d.appendChild(document.createTextNode(t.value));
  143. Ext.fly(d).setWidth(f.getEl().getWidth());
  144. return {
  145. field: f,
  146. ddel: d
  147. };
  148. }
  149. },
  150. // The coordinates to slide the drag proxy back to on failed drop.
  151. getRepairXY: function() {
  152. return this.dragData.field.getEl().getXY();
  153. }
  154. });
  155. Ext.onReady(function(){
  156. var myData = [
  157. ['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
  158. ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
  159. ['Altria Group Inc',83.81,0.28,0.34,'9/1 12:00am'],
  160. ['American Express Company',52.55,0.01,0.02,'9/1 12:00am'],
  161. ['American International Group, Inc.',64.13,0.31,0.49,'9/1 12:00am'],
  162. ['AT&T Inc.',31.61,-0.48,-1.54,'9/1 12:00am'],
  163. ['Boeing Co.',75.43,0.53,0.71,'9/1 12:00am'],
  164. ['Caterpillar Inc.',67.27,0.92,1.39,'9/1 12:00am'],
  165. ['Citigroup, Inc.',49.37,0.02,0.04,'9/1 12:00am'],
  166. ['E.I. du Pont de Nemours and Company',40.48,0.51,1.28,'9/1 12:00am'],
  167. ['Exxon Mobil Corp',68.1,-0.43,-0.64,'9/1 12:00am'],
  168. ['General Electric Company',34.14,-0.08,-0.23,'9/1 12:00am'],
  169. ['General Motors Corporation',30.27,1.09,3.74,'9/1 12:00am'],
  170. ['Hewlett-Packard Co.',36.53,-0.03,-0.08,'9/1 12:00am'],
  171. ['Honeywell Intl Inc',38.77,0.05,0.13,'9/1 12:00am'],
  172. ['Intel Corporation',19.88,0.31,1.58,'9/1 12:00am'],
  173. ['International Business Machines',81.41,0.44,0.54,'9/1 12:00am'],
  174. ['Johnson & Johnson',64.72,0.06,0.09,'9/1 12:00am'],
  175. ['JP Morgan & Chase & Co',45.73,0.07,0.15,'9/1 12:00am'],
  176. ['McDonald\'s Corporation',36.76,0.86,2.40,'9/1 12:00am'],
  177. ['Merck & Co., Inc.',40.96,0.41,1.01,'9/1 12:00am'],
  178. ['Microsoft Corporation',25.84,0.14,0.54,'9/1 12:00am'],
  179. ['Pfizer Inc',27.96,0.4,1.45,'9/1 12:00am'],
  180. ['The Coca-Cola Company',45.07,0.26,0.58,'9/1 12:00am'],
  181. ['The Home Depot, Inc.',34.64,0.35,1.02,'9/1 12:00am'],
  182. ['The Procter & Gamble Company',61.91,0.01,0.02,'9/1 12:00am'],
  183. ['United Technologies Corporation',63.26,0.55,0.88,'9/1 12:00am'],
  184. ['Verizon Communications',35.57,0.39,1.11,'9/1 12:00am'],
  185. ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am']
  186. ];
  187. // example of custom renderer function
  188. function change(val){
  189. if(val > 0){
  190. return '<span style="color:green;">' + val + '</span>';
  191. }else if(val < 0){
  192. return '<span style="color:red;">' + val + '</span>';
  193. }
  194. return val;
  195. }
  196. // example of custom renderer function
  197. function pctChange(val){
  198. if(val > 0){
  199. return '<span style="color:green;">' + val + '%</span>';
  200. }else if(val < 0){
  201. return '<span style="color:red;">' + val + '%</span>';
  202. }
  203. return val;
  204. }
  205. // create the data store
  206. var store = new Ext.data.ArrayStore({
  207. fields: [
  208. {name: 'company'},
  209. {name: 'price', type: 'float'},
  210. {name: 'change', type: 'float'},
  211. {name: 'pctChange', type: 'float'},
  212. {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
  213. ]
  214. });
  215. store.loadData(myData);
  216. var helpWindow = new Ext.Window({
  217. title: 'Source code',
  218. width: 920,
  219. height: 500,
  220. closeAction: 'hide',
  221. bodyCfg: {tag: 'textarea', readonly: true},
  222. bodyStyle: {
  223. backgroundColor: 'white',
  224. margin: '0px',
  225. border: '0px none'
  226. },
  227. listeners: {
  228. render: function(w) {
  229. Ext.Ajax.request({
  230. url: 'field-to-grid-dd.js',
  231. success: function(r) {
  232. w.body.dom.value = r.responseText;
  233. }
  234. });
  235. }
  236. }
  237. });
  238. // create the Grid
  239. var grid = new Ext.grid.GridPanel({
  240. store: store,
  241. columns: [
  242. {id:'company',header: "Company", width: 160, sortable: true, dataIndex: 'company'},
  243. {header: "Price", width: 75, sortable: true, renderer: 'usMoney', dataIndex: 'price'},
  244. {header: "Change", width: 75, sortable: true, renderer: change, dataIndex: 'change'},
  245. {header: "% Change", width: 75, sortable: true, renderer: pctChange, dataIndex: 'pctChange'},
  246. {header: "Last Updated", width: 85, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
  247. ],
  248. plugins: new Ext.ux.CellFieldDropZone(),
  249. stripeRows: true,
  250. autoExpandColumn: 'company',
  251. height:350,
  252. width:600,
  253. title:'Array Grid',
  254. bbar: new Ext.PagingToolbar({
  255. buttons: [{
  256. text: 'View Source',
  257. handler: function() {
  258. helpWindow.show();
  259. }
  260. }],
  261. store: store,
  262. pageSize: 25
  263. })
  264. });
  265. grid.render('grid-example');
  266. grid.getSelectionModel().selectFirstRow();
  267. var f = new Ext.Panel({
  268. frame: true,
  269. layout: 'form',
  270. width: 600,
  271. plugins: new Ext.ux.PanelFieldDragZone(),
  272. style: {
  273. 'margin-top': '10px'
  274. },
  275. labelWidth: 150,
  276. items: [{
  277. xtype: 'textfield',
  278. fieldLabel: 'Drag this text',
  279. value: 'test'
  280. },{
  281. xtype: 'numberfield',
  282. fieldLabel: 'Drag this number',
  283. value: '1.2'
  284. },{
  285. xtype: 'datefield',
  286. fieldLabel: 'Drag this date',
  287. value: new Date()
  288. }],
  289. renderTo: Ext.getBody()
  290. });
  291. });