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