3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">
\r
9 tx.data.TaskStore = Ext.extend(Ext.data.GroupingStore, {
\r
10 constructor: function(){
\r
11 tx.data.TaskStore.superclass.constructor.call(this, {
\r
12 sortInfo:{field: 'dueDate', direction: "ASC"},
\r
13 groupField:'dueDate',
\r
15 reader: new Ext.data.JsonReader({
\r
17 fields: tx.data.Task
\r
20 this.conn = tx.data.conn;
\r
21 this.proxy = new Ext.sql.Proxy(tx.data.conn, 'task', 'taskId', this);
\r
24 applyFilter : function(filter){
\r
25 if(filter !== undefined){
\r
26 this.taskFilter = filter;
\r
28 var value = this.taskFilter;
\r
30 return this.clearFilter();
\r
32 return this.filterBy(function(item){
\r
33 return item.data.completed === value;
\r
37 addTask : function(data){
\r
38 this.suspendEvents();
\r
40 this.resumeEvents();
\r
41 this.loadData([data], true);
\r
42 this.suspendEvents();
\r
44 this.applyGrouping(true);
\r
45 this.resumeEvents();
\r
46 this.fireEvent('datachanged', this);
\r
49 loadList: function(listId){
\r
50 var multi = Ext.isArray(listId);
\r
51 this.activeList = multi ? listId[0] : listId;
\r
52 this.suspendEvents();
\r
55 for(var i = 0, len = listId.length; i < len; i++){
\r
60 where: 'where listId in (' + ps.join(',') + ')',
\r
65 this.load({params: {
\r
66 where: 'where listId = ?',
\r
71 this.applyGrouping(true);
\r
72 this.resumeEvents();
\r
73 this.fireEvent('datachanged', this);
\r
76 removeList: function(listId){
\r
77 this.conn.execBy('delete from task where listId = ?', [listId]);
\r
81 prepareTable : function(){
\r
86 fields: tx.data.Task.prototype.fields
\r
88 }catch(e){console.log(e);}
\r
91 createTask : function(title, listText, dueDate, description, completed){
\r
92 if(!Ext.isEmpty(title)){
\r
94 if(!Ext.isEmpty(listText)){
\r
95 listId = tx.data.lists.addList(Ext.util.Format.htmlEncode(listText)).id;
\r
97 listId = tx.data.lists.newList(false).id;
\r
100 taskId: Ext.uniqueId(),
\r
101 title: Ext.util.Format.htmlEncode(title),
\r
102 dueDate: dueDate||'',
\r
103 description: description||'',
\r
105 completed: completed || false
\r
110 afterEdit : function(r){
\r
111 if(r.isModified(this.getGroupState())){
\r
112 this.applyGrouping();
\r
114 //workaround WebKit cross-frame date issue
\r
115 fixDateMember(r.data, 'completedDate');
\r
116 fixDateMember(r.data, 'reminder');
\r
117 fixDateMember(r.data, 'dueDate');
\r
118 if(r.isModified('completed')){
\r
120 r.set('completedDate', r.data.completed ? new Date() : '');
\r
123 tx.data.TaskStore.superclass.afterEdit.apply(this, arguments);
\r
127 tx.data.lists.load();
\r
129 callback: function(){
\r
131 if(this.getCount() < 1){
\r
132 Ext.Msg.confirm('Create Tasks?', 'Your database is currently empty. Would you like to insert some demo data?',
\r
135 tx.data.lists.loadDemoLists();
\r
136 this.loadDemoTasks();
\r
145 lookup : function(id){
\r
147 if(task = this.getById(id)){
\r
150 var data = this.proxy.table.lookup(id);
\r
152 var result = this.reader.readRecords([data]);
\r
153 return result.records[0];
\r
158 /* This is used to laod some demo tasks if the task database is empty */
\r
159 loadDemoTasks: function(){
\r
160 var s = new Date();
\r
161 // hardcoded demo tasks
\r
162 this.addTask({taskId: Ext.uniqueId(), title:'Update Ext 2.0 documentation', listId:'ext2', description:'', dueDate: s.add('d', 21), completed: false, reminder: ''});
\r
163 this.addTask({taskId: Ext.uniqueId(), title:'Release Ext 2.l Beta 1', listId:'ext2', description:'', dueDate:s.add('d', 2), completed: false, reminder: s.add('d', 2).clearTime(true).add('h', 9)});
\r
164 this.addTask({taskId: Ext.uniqueId(), title:'Take wife to see movie', listId:'family', description:'', dueDate:s.add('d', 2), completed: false, reminder: ''});
\r
165 this.addTask({taskId: Ext.uniqueId(), title:'Finish Simple Tasks v2 sample app', listId:'ext2', description:'', dueDate:s.add('d', 2), completed: false, reminder: ''});
\r
166 this.addTask({taskId: Ext.uniqueId(), title:'Do something other than work', listId:'fun', description:'', dueDate:s.add('d', -1), completed: false, reminder: ''});
\r
167 this.addTask({taskId: Ext.uniqueId(), title:'Go to the grocery store', listId:'family', description:'', dueDate:s.add('d', -1), completed: true, reminder: '', completedDate: new Date()});
\r
168 this.addTask({taskId: Ext.uniqueId(), title:'Reboot my computer', listId:'personal-misc', description:'', dueDate:s, completed: false, reminder: ''});
\r
169 this.addTask({taskId: Ext.uniqueId(), title:'Respond to emails', listId:'work-misc', description:'', dueDate:s, completed: true, reminder: '', completedDate: new Date()});
\r