3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
7 Ext.BLANK_IMAGE_URL = 'images/s.gif';
9 Task = Ext.data.Record.create([
10 {name: 'taskId', type:'string'},
11 {name: 'title', type:'string'},
12 {name: 'category', type:'string'},
13 {name: 'description', type:'string'},
14 {name: 'dueDate', type:'date', dateFormat: 'Y-m-d H:i:s'},
15 {name: 'completed', type:'boolean'}
18 Task.nextId = function(){
19 // if the time isn't unique enough, the addition
20 // of random chars should be
21 var t = String(new Date().getTime()).substr(4);
22 var s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
23 for(var i = 0; i < 4; i++){
24 t += s.charAt(Math.floor(Math.random()*26));
29 // The main grid's store
30 TaskStore = function(conn){
31 TaskStore.superclass.constructor.call(this, {
32 sortInfo:{field: 'dueDate', direction: "ASC"},
35 reader: new Ext.data.JsonReader({
40 this.proxy = new Ext.data.SqlDB.Proxy(conn, 'task', 'taskId', this);
42 if(window.google){ // google needs the table created
43 this.proxy.on('beforeload', this.prepareTable, conn);
46 this.addEvents({newcategory: true});
49 Ext.extend(TaskStore, Ext.data.GroupingStore, {
50 applyFilter : function(filter){
51 if(filter !== undefined){
52 this.taskFilter = filter;
54 var value = this.taskFilter;
56 return this.clearFilter();
58 return this.filterBy(function(item){
59 return item.data.completed === value;
63 addTask : function(data){
67 this.loadData([data], true);
70 this.applyGrouping(true);
72 this.fireEvent('datachanged', this);
73 this.fireEvent('newcategory', data.category);
76 prepareTable : function(){
81 fields: Task.prototype.fields
83 }catch(e){console.log(e)}
87 // The store for Categories
88 CategoryStore = function(){
89 CategoryStore.superclass.constructor.call(this, {
92 fields:[{name: 'text', type:'string'}],
93 sortInfo:{field:'text', direction:'ASC'},
98 Ext.extend(CategoryStore, Ext.data.ArrayStore, {
99 init : function(store){
100 var cats = store.collect('category', false, true);
104 addCategory : function(cat){
105 if(cat && this.indexOfId(cat) === -1){
106 this.clearFilter(true);
107 this.loadData([cat], true);
113 // Grid column plugin that does the complete/active button in the left-most column
114 CompleteColumn = function(){
117 function getRecord(t){
118 var index = grid.getView().findRowIndex(t);
119 return grid.store.getAt(index);
122 function onMouseDown(e, t){
123 if(Ext.fly(t).hasClass('task-check')){
125 var record = getRecord(t);
126 record.set('completed', !record.data.completed);
127 grid.store.applyFilter();
131 function onMouseOver(e, t){
132 if(Ext.fly(t).hasClass('task-check')){
133 Ext.fly(t.parentNode).addClass('task-check-over');
137 function onMouseOut(e, t){
138 if(Ext.fly(t).hasClass('task-check')){
139 Ext.fly(t.parentNode).removeClass('task-check-over');
145 header: '<div class="task-col-hd"></div>',
149 renderer: function(){
150 return '<div class="task-check"></div>';
154 grid.on('render', function(){
155 var view = grid.getView();
156 view.mainBody.on('mousedown', onMouseDown);
157 view.mainBody.on('mouseover', onMouseOver);
158 view.mainBody.on('mouseout', onMouseOut);