Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / data.html
1 <html>\r
2 <head>\r
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
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js">// Unique task ids, if the time isn't unique enough, the addition \r
9 // of random chars should be\r
10 Ext.uniqueId = function(){\r
11         var t = String(new Date().getTime()).substr(4);\r
12         var s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r
13         for(var i = 0; i < 4; i++){\r
14                 t += s.charAt(Math.floor(Math.random()*26));\r
15         }\r
16         return t;\r
17 }\r
18 \r
19 // Define the Task data type\r
20 tx.data.Task = Ext.data.Record.create([\r
21     {name: 'taskId', type:'string'},\r
22     {name: 'listId', type:'string'},\r
23     {name: 'title', type:'string'},\r
24     {name: 'description', type:'string'},\r
25     {name: 'dueDate', type:'date', dateFormat: Ext.sql.Proxy.DATE_FORMAT, defaultValue: ''},\r
26     {name: 'completed', type:'boolean'},\r
27     {name: 'completedDate', type:'date', dateFormat: Ext.sql.Proxy.DATE_FORMAT, defaultValue: ''},\r
28     {name: 'reminder', type:'date', dateFormat: Ext.sql.Proxy.DATE_FORMAT, defaultValue: ''}\r
29 ]);\r
30 \r
31 // Define the List data type\r
32 tx.data.List = Ext.data.Record.create([\r
33     {name: 'listId', type:'string'},\r
34     {name: 'parentId', type:'string'},\r
35     {name: 'listName', type:'string'},\r
36     {name: 'isFolder', type:'boolean'}\r
37 ]);\r
38 \r
39 tx.data.conn = Ext.sql.Connection.getInstance();\r
40 \r
41 tx.data.tasks = new tx.data.TaskStore();\r
42 tx.data.lists = new tx.data.ListStore();\r
43 \r
44 \r
45 tx.data.getDefaultReminder = function(task){\r
46         var s = task.data.dueDate ? task.data.dueDate.clearTime(true) : new Date().clearTime();\r
47         s = s.add('mi', Ext.state.Manager.get('defaultReminder'));\r
48         return s;\r
49 };\r
50 \r
51 \r
52 tx.data.getActiveListId = function(){\r
53     var id = tx.data.tasks.activeList;\r
54     if(!id){\r
55         var first = tx.data.lists.getAt(0);\r
56         if(first){\r
57             id = first.id;\r
58         }else{\r
59             id = tx.data.lists.newList().id;\r
60         }\r
61     }\r
62     return id;\r
63 };\r
64 \r
65 </pre>    \r
66 </body>\r
67 </html>