commit extjs-2.2.1
[extjs.git] / air / samples / tasks / js / data.js
1 /*\r
2  * Ext JS Library 0.30\r
3  * Copyright(c) 2006-2009, Ext JS, LLC.\r
4  * licensing@extjs.com\r
5  * \r
6  * http://extjs.com/license\r
7  */\r
8 \r
9 // Unique task ids, if the time isn't unique enough, the addition \r
10 // of random chars should be\r
11 Ext.uniqueId = function(){\r
12         var t = String(new Date().getTime()).substr(4);\r
13         var s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r
14         for(var i = 0; i < 4; i++){\r
15                 t += s.charAt(Math.floor(Math.random()*26));\r
16         }\r
17         return t;\r
18 }\r
19 \r
20 // Define the Task data type\r
21 tx.data.Task = Ext.data.Record.create([\r
22     {name: 'taskId', type:'string'},\r
23     {name: 'listId', type:'string'},\r
24     {name: 'title', type:'string'},\r
25     {name: 'description', type:'string'},\r
26     {name: 'dueDate', type:'date', dateFormat: Ext.sql.Proxy.DATE_FORMAT, defaultValue: ''},\r
27     {name: 'completed', type:'boolean'},\r
28     {name: 'completedDate', type:'date', dateFormat: Ext.sql.Proxy.DATE_FORMAT, defaultValue: ''},\r
29     {name: 'reminder', type:'date', dateFormat: Ext.sql.Proxy.DATE_FORMAT, defaultValue: ''}\r
30 ]);\r
31 \r
32 // Define the List data type\r
33 tx.data.List = Ext.data.Record.create([\r
34     {name: 'listId', type:'string'},\r
35     {name: 'parentId', type:'string'},\r
36     {name: 'listName', type:'string'},\r
37     {name: 'isFolder', type:'boolean'}\r
38 ]);\r
39 \r
40 \r
41 // Grab a SQL connection instance\r
42 tx.data.conn = Ext.sql.Connection.getInstance();\r
43 \r
44 tx.data.tasks = new tx.data.TaskStore();\r
45 tx.data.lists = new tx.data.ListStore();\r
46 \r
47 \r
48 tx.data.getDefaultReminder = function(task){\r
49         var s = task.data.dueDate ? task.data.dueDate.clearTime(true) : new Date().clearTime();\r
50         s = s.add('mi', Ext.state.Manager.get('defaultReminder'));\r
51         return s;\r
52 };\r
53 \r
54 \r
55 tx.data.getActiveListId = function(){\r
56     var id = tx.data.tasks.activeList;\r
57     if(!id){\r
58         var first = tx.data.lists.getAt(0);\r
59         if(first){\r
60             id = first.id;\r
61         }else{\r
62             id = tx.data.lists.newList().id;\r
63         }\r
64     }\r
65     return id;\r
66 };\r
67 \r