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.

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