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.

441 lines
13 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. Ext.QuickTips.init();
  9. var xg = Ext.grid;
  10. // turn off default shadows which look funky in air
  11. xg.GridEditor.prototype.shadow = false;
  12. var conn = Ext.data.SqlDB.getInstance();
  13. conn.open('tasks.db');
  14. // the main grid store
  15. var taskStore = new TaskStore(conn);
  16. // Category store shared by category combos
  17. var catStore = new CategoryStore();
  18. taskStore.load({
  19. callback: function(){
  20. // first time?
  21. if(taskStore.getCount() < 1){
  22. Ext.Msg.confirm('Create Tasks?', 'Your database is currently empty. Would you like to insert some demo data?',
  23. function(btn){
  24. if(btn == 'yes'){
  25. loadDemoTasks(taskStore);
  26. }
  27. catStore.init(taskStore);
  28. });
  29. }else{
  30. catStore.init(taskStore);
  31. }
  32. }
  33. });
  34. // custom event to notify when a new category is available
  35. taskStore.on('newcategory', catStore.addCategory, catStore);
  36. // set of event handlers shared by combos to allow them to share
  37. // the same local store
  38. var comboEvents = {
  39. focus: function(){
  40. this.bindStore(catStore);
  41. },
  42. blur: function(c){
  43. catStore.purgeListeners();
  44. }
  45. }
  46. var completeColumn = new CompleteColumn();
  47. // custom template for the grid header
  48. var headerTpl = new Ext.Template(
  49. '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
  50. '<thead><tr class="x-grid3-hd-row">{cells}</tr></thead>',
  51. '<tbody><tr class="new-task-row">',
  52. '<td><div id="new-task-icon"></div></td>',
  53. '<td><div class="x-small-editor" id="new-task-title"></div></td>',
  54. '<td><div class="x-small-editor" id="new-task-cat"></div></td>',
  55. '<td><div class="x-small-editor" id="new-task-due"></div></td>',
  56. '</tr></tbody>',
  57. "</table>"
  58. );
  59. var selections = new Ext.grid.RowSelectionModel();
  60. // The main grid in all its configuration option glory
  61. var grid = new xg.EditorGridPanel({
  62. id:'tasks-grid',
  63. store: taskStore,
  64. sm: selections,
  65. clicksToEdit: 'auto',
  66. enableColumnHide:false,
  67. enableColumnMove:false,
  68. border:false,
  69. title:'All Tasks',
  70. iconCls:'icon-show-all',
  71. region:'center',
  72. plugins: completeColumn,
  73. columns: [
  74. completeColumn,
  75. {
  76. header: "Task",
  77. width:400,
  78. sortable: true,
  79. dataIndex: 'title',
  80. id:'task-title',
  81. editor: new Ext.form.TextField({
  82. allowBlank: false
  83. })
  84. },
  85. {
  86. header: "Category",
  87. width:150,
  88. sortable: true,
  89. dataIndex: 'category',
  90. editor: new Ext.form.ComboBox({
  91. displayField: 'text',
  92. triggerAction: 'all',
  93. mode:'local',
  94. selectOnFocus:true,
  95. listClass:'x-combo-list-small',
  96. listeners: comboEvents
  97. })
  98. },
  99. {
  100. header: "Due Date",
  101. width: 150,
  102. sortable: true,
  103. renderer: Ext.util.Format.dateRenderer('D m/d/Y'),
  104. dataIndex: 'dueDate',
  105. groupRenderer: textDate(),
  106. groupName: 'Due',
  107. editor: new Ext.form.DateField({
  108. format : "m/d/Y"
  109. })
  110. }
  111. ],
  112. view: new Ext.grid.GroupingView({
  113. forceFit:true,
  114. ignoreAdd: true,
  115. emptyText: 'No Tasks to display',
  116. templates: {
  117. header: headerTpl
  118. },
  119. getRowClass : function(r){
  120. var d = r.data;
  121. if(d.completed){
  122. return 'task-completed';
  123. }
  124. if(d.dueDate && d.dueDate.getTime() < new Date().clearTime().getTime()){
  125. return 'task-overdue';
  126. }
  127. return '';
  128. }
  129. })
  130. });
  131. var viewPanel = new Ext.Panel({
  132. frame:true,
  133. title: 'Views',
  134. collapsible:true,
  135. contentEl:'task-views',
  136. titleCollapse: true
  137. });
  138. var taskActions = new Ext.Panel({
  139. frame:true,
  140. title: 'Task Actions',
  141. collapsible:true,
  142. contentEl:'task-actions',
  143. titleCollapse: true
  144. });
  145. var groupActions = new Ext.Panel({
  146. frame:true,
  147. title: 'Task Grouping',
  148. collapsible:true,
  149. contentEl:'task-grouping',
  150. titleCollapse: true
  151. });
  152. var actionPanel = new Ext.Panel({
  153. id:'action-panel',
  154. region:'west',
  155. split:true,
  156. collapsible: true,
  157. collapseMode: 'mini',
  158. header: false,
  159. width:200,
  160. minWidth: 150,
  161. border: false,
  162. baseCls:'x-plain',
  163. items: [taskActions, viewPanel, groupActions]
  164. });
  165. if(Ext.isAir){ // create AIR window
  166. var win = new Ext.air.MainWindow({
  167. layout:'border',
  168. items: [actionPanel, grid],
  169. title: 'Simple Tasks',
  170. iconCls: 'icon-show-all'
  171. }).render();
  172. }else{
  173. var viewport = new Ext.Viewport({
  174. layout:'border',
  175. items: [actionPanel, grid]
  176. });
  177. }
  178. var ab = actionPanel.body;
  179. ab.on('mousedown', doAction, null, {delegate:'a'});
  180. ab.on('click', Ext.emptyFn, null, {delegate:'a', preventDefault:true});
  181. grid.on('resize', syncFields);
  182. grid.on('columnresize', syncFields);
  183. grid.on('afteredit', function(e){
  184. if(e.field == 'category'){
  185. catStore.addCategory(e.value);
  186. }
  187. if(e.field == taskStore.getGroupState()){
  188. taskStore.applyGrouping();
  189. }
  190. });
  191. grid.on('keydown', function(e){
  192. if(e.getKey() == e.DELETE && !grid.editing){
  193. actions['action-delete']();
  194. }
  195. });
  196. selections.on('selectionchange', function(sm){
  197. var bd = taskActions.body, c = sm.getCount();
  198. bd.select('li:not(#new-task)').setDisplayed(c > 0);
  199. bd.select('span.s').setDisplayed(c > 1);
  200. });
  201. // The fields in the grid's header
  202. var ntTitle = new Ext.form.TextField({
  203. renderTo: 'new-task-title',
  204. emptyText: 'Add a task...'
  205. });
  206. var ntCat = new Ext.form.ComboBox({
  207. renderTo: 'new-task-cat',
  208. disabled:true,
  209. displayField: 'text',
  210. triggerAction: 'all',
  211. mode:'local',
  212. selectOnFocus:true,
  213. listClass:'x-combo-list-small',
  214. listeners: comboEvents
  215. });
  216. var ntDue = new Ext.form.DateField({
  217. renderTo: 'new-task-due',
  218. value: new Date(),
  219. disabled:true,
  220. format : "m/d/Y"
  221. });
  222. // syncs the header fields' widths with the grid column widths
  223. function syncFields(){
  224. var cm = grid.getColumnModel();
  225. ntTitle.setSize(cm.getColumnWidth(1)-2);
  226. ntCat.setSize(cm.getColumnWidth(2)-4);
  227. ntDue.setSize(cm.getColumnWidth(3)-4);
  228. }
  229. syncFields();
  230. var editing = false, focused = false, userTriggered = false;
  231. var handlers = {
  232. focus: function(){
  233. focused = true;
  234. },
  235. blur: function(){
  236. focused = false;
  237. doBlur.defer(250);
  238. },
  239. specialkey: function(f, e){
  240. if(e.getKey()==e.ENTER){
  241. userTriggered = true;
  242. e.stopEvent();
  243. f.el.blur();
  244. if(f.triggerBlur){
  245. f.triggerBlur();
  246. }
  247. }
  248. }
  249. }
  250. ntTitle.on(handlers);
  251. ntCat.on(handlers);
  252. ntDue.on(handlers);
  253. ntTitle.on('focus', function(){
  254. focused = true;
  255. if(!editing){
  256. ntCat.enable();
  257. ntDue.enable();
  258. syncFields();
  259. editing = true;
  260. }
  261. });
  262. // when a field in the add bar is blurred, this determines
  263. // whether a new task should be created
  264. function doBlur(){
  265. if(editing && !focused){
  266. var title = ntTitle.getValue();
  267. if(!Ext.isEmpty(title)){
  268. taskStore.addTask({
  269. taskId: Task.nextId(),
  270. title: title,
  271. dueDate: ntDue.getValue()||'',
  272. description: '', // ???
  273. category: ntCat.getValue(),
  274. completed: false
  275. });
  276. ntTitle.setValue('');
  277. if(userTriggered){ // if the entered to add the task, then go to a new add automatically
  278. userTriggered = false;
  279. ntTitle.focus.defer(100, ntTitle);
  280. }
  281. }
  282. ntCat.disable();
  283. ntDue.disable();
  284. editing = false;
  285. }
  286. }
  287. var actions = {
  288. 'view-all' : function(){
  289. taskStore.applyFilter('all');
  290. grid.setTitle('All Tasks', 'icon-show-all');
  291. },
  292. 'view-active' : function(){
  293. taskStore.applyFilter(false);
  294. grid.setTitle('Active Tasks', 'icon-show-active');
  295. },
  296. 'view-complete' : function(){
  297. taskStore.applyFilter(true);
  298. grid.setTitle('Completed Tasks', 'icon-show-complete');
  299. },
  300. 'action-new' : function(){
  301. ntTitle.focus();
  302. },
  303. 'action-complete' : function(){
  304. selections.each(function(s){
  305. s.set('completed', true);
  306. });
  307. taskStore.applyFilter();
  308. },
  309. 'action-active' : function(){
  310. selections.each(function(s){
  311. s.set('completed', false);
  312. });
  313. taskStore.applyFilter();
  314. },
  315. 'action-delete' : function(){
  316. Ext.Msg.confirm('Confirm', 'Are you sure you want to delete the selected task(s)?',
  317. function(btn){
  318. if(btn == 'yes'){
  319. selections.each(function(s){
  320. taskStore.remove(s);
  321. });
  322. }
  323. });
  324. },
  325. 'group-date' : function(){
  326. taskStore.groupBy('dueDate');
  327. },
  328. 'group-cat' : function(){
  329. taskStore.groupBy('category');
  330. },
  331. 'no-group' : function(){
  332. taskStore.clearGrouping();
  333. }
  334. };
  335. function doAction(e, t){
  336. e.stopEvent();
  337. actions[t.id]();
  338. }
  339. // generates a renderer function to be used for textual date groups
  340. function textDate(){
  341. // create the cache of ranges to be reused
  342. var today = new Date().clearTime(true);
  343. var year = today.getFullYear();
  344. var todayTime = today.getTime();
  345. var yesterday = today.add('d', -1).getTime();
  346. var tomorrow = today.add('d', 1).getTime();
  347. var weekDays = today.add('d', 6).getTime();
  348. var lastWeekDays = today.add('d', -6).getTime();
  349. return function(date){
  350. if(!date) {
  351. return '(No Date)';
  352. }
  353. var notime = date.clearTime(true).getTime();
  354. if (notime == todayTime) {
  355. return 'Today';
  356. }
  357. if(notime > todayTime){
  358. if (notime == tomorrow) {
  359. return 'Tomorrow';
  360. }
  361. if (notime <= weekDays) {
  362. return date.format('l');
  363. }
  364. }else {
  365. if(notime == yesterday) {
  366. return 'Yesterday';
  367. }
  368. if(notime >= lastWeekDays) {
  369. return 'Last ' + date.format('l');
  370. }
  371. }
  372. return date.getFullYear() == year ? date.format('D m/d') : date.format('D m/d/Y');
  373. }
  374. }
  375. });
  376. /* This is used to laod some demo tasks if the task database is empty */
  377. function loadDemoTasks(store){
  378. var s = new Date();
  379. // hardcoded demo tasks
  380. store.addTask({taskId: Task.nextId(), title:'Start documentation of Ext 2.0', category:'Ext', description:'', dueDate: s.add('d', 21), completed: false});
  381. store.addTask({taskId: Task.nextId(), title:'Release Ext 1.l Beta 2', category:'Ext', description:'', dueDate:s.add('d', 2), completed: false});
  382. store.addTask({taskId: Task.nextId(), title:'Take wife to see movie', category:'Family', description:'', dueDate:s.add('d', 2), completed: false});
  383. store.addTask({taskId: Task.nextId(), title:'Finish task list demo app', category:'Ext', description:'', dueDate:s.add('d', 2), completed: false});
  384. store.addTask({taskId: Task.nextId(), title:'Do something other than work', category:'Family', description:'', dueDate:s.add('d', -1), completed: false});
  385. store.addTask({taskId: Task.nextId(), title:'Go to the grocery store', category:'Family', description:'', dueDate:s.add('d', -1), completed: true});
  386. store.addTask({taskId: Task.nextId(), title:'Reboot my computer', category:'Misc', description:'', dueDate:s, completed: false});
  387. store.addTask({taskId: Task.nextId(), title:'Respond to emails', category:'Ext', description:'', dueDate:s, completed: true});
  388. }