+++ /dev/null
-<html>\r
-<head>\r
- <title>The source code</title>\r
- <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
- <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
-</head>\r
-<body onload="prettyPrint();">\r
- <pre class="prettyprint lang-js">\r
-tx.data.TaskStore = Ext.extend(Ext.data.GroupingStore, {\r
- constructor: function(){\r
- tx.data.TaskStore.superclass.constructor.call(this, {\r
- sortInfo:{field: 'dueDate', direction: "ASC"},\r
- groupField:'dueDate',\r
- taskFilter: 'all',\r
- reader: new Ext.data.JsonReader({\r
- id: 'taskId',\r
- fields: tx.data.Task\r
- })\r
- });\r
- this.conn = tx.data.conn;\r
- this.proxy = new Ext.sql.Proxy(tx.data.conn, 'task', 'taskId', this);\r
- },\r
- \r
- applyFilter : function(filter){\r
- if(filter !== undefined){\r
- this.taskFilter = filter;\r
- }\r
- var value = this.taskFilter;\r
- if(value == 'all'){\r
- return this.clearFilter();\r
- }\r
- return this.filterBy(function(item){\r
- return item.data.completed === value;\r
- });\r
- },\r
-\r
- addTask : function(data){\r
- this.suspendEvents();\r
- this.clearFilter();\r
- this.resumeEvents();\r
- this.loadData([data], true);\r
- this.suspendEvents();\r
- this.applyFilter();\r
- this.applyGrouping(true);\r
- this.resumeEvents();\r
- this.fireEvent('datachanged', this);\r
- },\r
-\r
- loadList: function(listId){\r
- var multi = Ext.isArray(listId);\r
- this.activeList = multi ? listId[0] : listId;\r
- this.suspendEvents();\r
- if(multi){\r
- var ps = [];\r
- for(var i = 0, len = listId.length; i < len; i++){\r
- ps.push('?');\r
- }\r
- this.load({\r
- params: {\r
- where: 'where listId in (' + ps.join(',') + ')',\r
- args: listId\r
- }\r
- });\r
- }else{\r
- this.load({params: {\r
- where: 'where listId = ?',\r
- args: [listId]\r
- }});\r
- } \r
- this.applyFilter();\r
- this.applyGrouping(true);\r
- this.resumeEvents();\r
- this.fireEvent('datachanged', this);\r
- },\r
- \r
- removeList: function(listId){\r
- this.conn.execBy('delete from task where listId = ?', [listId]);\r
- this.reload();\r
- },\r
- \r
- prepareTable : function(){\r
- try{\r
- this.createTable({\r
- name: 'task',\r
- key: 'taskId',\r
- fields: tx.data.Task.prototype.fields\r
- });\r
- }catch(e){console.log(e);}\r
- },\r
- \r
- createTask : function(title, listText, dueDate, description, completed){\r
- if(!Ext.isEmpty(title)){\r
- var listId = '';\r
- if(!Ext.isEmpty(listText)){\r
- listId = tx.data.lists.addList(Ext.util.Format.htmlEncode(listText)).id;\r
- }else{\r
- listId = tx.data.lists.newList(false).id;\r
- }\r
- this.addTask({\r
- taskId: Ext.uniqueId(),\r
- title: Ext.util.Format.htmlEncode(title),\r
- dueDate: dueDate||'',\r
- description: description||'',\r
- listId: listId,\r
- completed: completed || false\r
- });\r
- }\r
- },\r
- \r
- afterEdit : function(r){\r
- if(r.isModified(this.getGroupState())){\r
- this.applyGrouping();\r
- }\r
- //workaround WebKit cross-frame date issue\r
- fixDateMember(r.data, 'completedDate');\r
- fixDateMember(r.data, 'reminder');\r
- fixDateMember(r.data, 'dueDate');\r
- if(r.isModified('completed')){\r
- r.editing = true;\r
- r.set('completedDate', r.data.completed ? new Date() : '');\r
- r.editing = false;\r
- }\r
- tx.data.TaskStore.superclass.afterEdit.apply(this, arguments);\r
- },\r
- \r
- init : function(){\r
- tx.data.lists.load();\r
- this.load({\r
- callback: function(){\r
- // first time?\r
- if(this.getCount() < 1){\r
- Ext.Msg.confirm('Create Tasks?', 'Your database is currently empty. Would you like to insert some demo data?', \r
- function(btn){\r
- if(btn == 'yes'){\r
- tx.data.lists.loadDemoLists();\r
- this.loadDemoTasks(); \r
- }\r
- }, this);\r
- }\r
- },\r
- scope: this\r
- });\r
- },\r
- \r
- lookup : function(id){\r
- var task;\r
- if(task = this.getById(id)){\r
- return task;\r
- }\r
- var data = this.proxy.table.lookup(id);\r
- if (data) {\r
- var result = this.reader.readRecords([data]);\r
- return result.records[0];\r
- }\r
- return null; \r
- },\r
- \r
- /* This is used to laod some demo tasks if the task database is empty */\r
- loadDemoTasks: function(){\r
- var s = new Date();\r
- // hardcoded demo tasks\r
- this.addTask({taskId: Ext.uniqueId(), title:'Update Ext 2.0 documentation', listId:'ext2', description:'', dueDate: s.add('d', 21), completed: false, reminder: ''});\r
- 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
- this.addTask({taskId: Ext.uniqueId(), title:'Take wife to see movie', listId:'family', description:'', dueDate:s.add('d', 2), completed: false, reminder: ''});\r
- this.addTask({taskId: Ext.uniqueId(), title:'Finish Simple Tasks v2 sample app', listId:'ext2', description:'', dueDate:s.add('d', 2), completed: false, reminder: ''});\r
- this.addTask({taskId: Ext.uniqueId(), title:'Do something other than work', listId:'fun', description:'', dueDate:s.add('d', -1), completed: false, reminder: ''});\r
- 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
- this.addTask({taskId: Ext.uniqueId(), title:'Reboot my computer', listId:'personal-misc', description:'', dueDate:s, completed: false, reminder: ''});\r
- this.addTask({taskId: Ext.uniqueId(), title:'Respond to emails', listId:'work-misc', description:'', dueDate:s, completed: true, reminder: '', completedDate: new Date()});\r
- }\r
-});</pre> \r
-</body>\r
-</html>
\ No newline at end of file