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.

161 lines
4.3 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.BLANK_IMAGE_URL = 'images/s.gif';
  8. Task = Ext.data.Record.create([
  9. {name: 'taskId', type:'string'},
  10. {name: 'title', type:'string'},
  11. {name: 'category', type:'string'},
  12. {name: 'description', type:'string'},
  13. {name: 'dueDate', type:'date', dateFormat: 'Y-m-d H:i:s'},
  14. {name: 'completed', type:'boolean'}
  15. ]);
  16. Task.nextId = function(){
  17. // if the time isn't unique enough, the addition
  18. // of random chars should be
  19. var t = String(new Date().getTime()).substr(4);
  20. var s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  21. for(var i = 0; i < 4; i++){
  22. t += s.charAt(Math.floor(Math.random()*26));
  23. }
  24. return t;
  25. }
  26. // The main grid's store
  27. TaskStore = function(conn){
  28. TaskStore.superclass.constructor.call(this, {
  29. sortInfo:{field: 'dueDate', direction: "ASC"},
  30. groupField:'dueDate',
  31. taskFilter: 'all',
  32. reader: new Ext.data.JsonReader({
  33. idProperty: 'taskId'
  34. }, Task)
  35. });
  36. this.proxy = new Ext.data.SqlDB.Proxy(conn, 'task', 'taskId', this);
  37. if(window.google){ // google needs the table created
  38. this.proxy.on('beforeload', this.prepareTable, conn);
  39. }
  40. this.addEvents({newcategory: true});
  41. };
  42. Ext.extend(TaskStore, Ext.data.GroupingStore, {
  43. applyFilter : function(filter){
  44. if(filter !== undefined){
  45. this.taskFilter = filter;
  46. }
  47. var value = this.taskFilter;
  48. if(value == 'all'){
  49. return this.clearFilter();
  50. }
  51. return this.filterBy(function(item){
  52. return item.data.completed === value;
  53. });
  54. },
  55. addTask : function(data){
  56. this.suspendEvents();
  57. this.clearFilter();
  58. this.resumeEvents();
  59. this.loadData([data], true);
  60. this.suspendEvents();
  61. this.applyFilter();
  62. this.applyGrouping(true);
  63. this.resumeEvents();
  64. this.fireEvent('datachanged', this);
  65. this.fireEvent('newcategory', data.category);
  66. },
  67. prepareTable : function(){
  68. try{
  69. this.createTable({
  70. name: 'task',
  71. key: 'taskId',
  72. fields: Task.prototype.fields
  73. });
  74. }catch(e){console.log(e)}
  75. }
  76. });
  77. // The store for Categories
  78. CategoryStore = function(){
  79. CategoryStore.superclass.constructor.call(this, {
  80. expandData: true,
  81. data: [],
  82. fields:[{name: 'text', type:'string'}],
  83. sortInfo:{field:'text', direction:'ASC'},
  84. id: 0
  85. });
  86. }
  87. Ext.extend(CategoryStore, Ext.data.ArrayStore, {
  88. init : function(store){
  89. var cats = store.collect('category', false, true);
  90. this.loadData(cats);
  91. },
  92. addCategory : function(cat){
  93. if(cat && this.indexOfId(cat) === -1){
  94. this.clearFilter(true);
  95. this.loadData([cat], true);
  96. this.applySort();
  97. }
  98. }
  99. });
  100. // Grid column plugin that does the complete/active button in the left-most column
  101. CompleteColumn = function(){
  102. var grid;
  103. function getRecord(t){
  104. var index = grid.getView().findRowIndex(t);
  105. return grid.store.getAt(index);
  106. }
  107. function onMouseDown(e, t){
  108. if(Ext.fly(t).hasClass('task-check')){
  109. e.stopEvent();
  110. var record = getRecord(t);
  111. record.set('completed', !record.data.completed);
  112. grid.store.applyFilter();
  113. }
  114. }
  115. function onMouseOver(e, t){
  116. if(Ext.fly(t).hasClass('task-check')){
  117. Ext.fly(t.parentNode).addClass('task-check-over');
  118. }
  119. }
  120. function onMouseOut(e, t){
  121. if(Ext.fly(t).hasClass('task-check')){
  122. Ext.fly(t.parentNode).removeClass('task-check-over');
  123. }
  124. }
  125. Ext.apply(this, {
  126. width: 22,
  127. header: '<div class="task-col-hd"></div>',
  128. menuDisabled:true,
  129. fixed: true,
  130. id: 'task-col',
  131. renderer: function(){
  132. return '<div class="task-check"></div>';
  133. },
  134. init : function(xg){
  135. grid = xg;
  136. grid.on('render', function(){
  137. var view = grid.getView();
  138. view.mainBody.on('mousedown', onMouseDown);
  139. view.mainBody.on('mouseover', onMouseOver);
  140. view.mainBody.on('mouseout', onMouseOut);
  141. });
  142. }
  143. });
  144. };