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