2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
9 Ext.BLANK_IMAGE_URL = 'images/s.gif';
\r
11 Task = Ext.data.Record.create([
\r
12 {name: 'taskId', type:'string'},
\r
13 {name: 'title', type:'string'},
\r
14 {name: 'category', type:'string'},
\r
15 {name: 'description', type:'string'},
\r
16 {name: 'dueDate', type:'date', dateFormat: 'Y-m-d H:i:s'},
\r
17 {name: 'completed', type:'boolean'}
\r
20 Task.nextId = function(){
\r
21 // if the time isn't unique enough, the addition
\r
22 // of random chars should be
\r
23 var t = String(new Date().getTime()).substr(4);
\r
24 var s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
\r
25 for(var i = 0; i < 4; i++){
\r
26 t += s.charAt(Math.floor(Math.random()*26));
\r
31 // The main grid's store
\r
32 TaskStore = function(conn){
\r
33 TaskStore.superclass.constructor.call(this, {
\r
34 sortInfo:{field: 'dueDate', direction: "ASC"},
\r
35 groupField:'dueDate',
\r
37 reader: new Ext.data.JsonReader({
\r
38 idProperty: 'taskId'
\r
42 this.proxy = new Ext.data.SqlDB.Proxy(conn, 'task', 'taskId', this);
\r
44 if(window.google){ // google needs the table created
\r
45 this.proxy.on('beforeload', this.prepareTable, conn);
\r
48 this.addEvents({newcategory: true});
\r
51 Ext.extend(TaskStore, Ext.data.GroupingStore, {
\r
52 applyFilter : function(filter){
\r
53 if(filter !== undefined){
\r
54 this.taskFilter = filter;
\r
56 var value = this.taskFilter;
\r
58 return this.clearFilter();
\r
60 return this.filterBy(function(item){
\r
61 return item.data.completed === value;
\r
65 addTask : function(data){
\r
66 this.suspendEvents();
\r
68 this.resumeEvents();
\r
69 this.loadData([data], true);
\r
70 this.suspendEvents();
\r
72 this.applyGrouping(true);
\r
73 this.resumeEvents();
\r
74 this.fireEvent('datachanged', this);
\r
75 this.fireEvent('newcategory', data.category);
\r
78 prepareTable : function(){
\r
83 fields: Task.prototype.fields
\r
85 }catch(e){console.log(e)}
\r
89 // The store for Categories
\r
90 CategoryStore = function(){
\r
91 CategoryStore.superclass.constructor.call(this, {
\r
94 fields:[{name: 'text', type:'string'}],
\r
95 sortInfo:{field:'text', direction:'ASC'},
\r
100 Ext.extend(CategoryStore, Ext.data.SimpleStore, {
\r
101 init : function(store){
\r
102 var cats = store.collect('category', false, true);
\r
103 this.loadData(cats);
\r
106 addCategory : function(cat){
\r
107 if(cat && this.indexOfId(cat) === -1){
\r
108 this.clearFilter(true);
\r
109 this.loadData([cat], true);
\r
115 // Grid column plugin that does the complete/active button in the left-most column
\r
116 CompleteColumn = function(){
\r
119 function getRecord(t){
\r
120 var index = grid.getView().findRowIndex(t);
\r
121 return grid.store.getAt(index);
\r
124 function onMouseDown(e, t){
\r
125 if(Ext.fly(t).hasClass('task-check')){
\r
127 var record = getRecord(t);
\r
128 record.set('completed', !record.data.completed);
\r
129 grid.store.applyFilter();
\r
133 function onMouseOver(e, t){
\r
134 if(Ext.fly(t).hasClass('task-check')){
\r
135 Ext.fly(t.parentNode).addClass('task-check-over');
\r
139 function onMouseOut(e, t){
\r
140 if(Ext.fly(t).hasClass('task-check')){
\r
141 Ext.fly(t.parentNode).removeClass('task-check-over');
\r
147 header: '<div class="task-col-hd"></div>',
\r
151 renderer: function(){
\r
152 return '<div class="task-check"></div>';
\r
154 init : function(xg){
\r
156 grid.on('render', function(){
\r
157 var view = grid.getView();
\r
158 view.mainBody.on('mousedown', onMouseDown);
\r
159 view.mainBody.on('mouseover', onMouseOver);
\r
160 view.mainBody.on('mouseout', onMouseOut);
\r