source: trunk/web/addons/job_monarch/lib/extjs/air/samples/tasks/js/ListStore.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 2.9 KB
Line 
1/*
2 * Ext JS Library 0.30
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9
10tx.data.ListStore = Ext.extend(Ext.data.Store, {
11        constructor: function(){
12                tx.data.ListStore.superclass.constructor.call(this, {
13                sortInfo:{field: 'listName', direction: "ASC"},
14                reader: new Ext.data.JsonReader({
15                    id: 'listId',
16                                fields: tx.data.List
17                })
18            });
19                this.boundTrees = {};
20            this.conn = tx.data.conn;
21            this.proxy = new Ext.sql.Proxy(tx.data.conn, 'list', 'listId', this);
22        },
23       
24    getName : function(id){
25                var l = this.data.map[id];
26                return l ? l.data.listName : '';
27        },
28       
29        addList : function(name, id, isFolder, parentId){
30                var l = this.findList(name);
31                if(!l){
32                        var id = id || Ext.uniqueId();
33                        l = new tx.data.List({listId: id, listName: name, isFolder: isFolder === true, parentId: parentId || 'root'}, id);
34                        this.add(l);
35                }
36                return l;
37        },
38       
39        newList : function(isFolder, parentId){
40                var i = 1;
41                var text = isFolder ? 'New Folder ' : 'New List '; 
42                while(this.findList(text + i)){
43                        i++;
44                }
45                return this.addList(text + i, undefined, isFolder, parentId);
46        },
47       
48        findList : function(name){
49                var d = this.data;
50                for(var i = 0, len = d.length; i < len; i++){
51                        if(d.items[i].data.listName === name){
52                                return d.items[i];
53                        }
54                }
55                return null;
56        },
57       
58        loadDemoLists: function(){
59                this.addList('Personal', 'personal', true, 'root');
60                this.addList('Family', 'family', false, 'personal');
61                this.addList('Bills', 'bills', false, 'personal');
62                this.addList('Fun', 'fun', false, 'personal');
63                this.addList('Other Stuff', 'personal-misc', false, 'personal');
64                this.addList('Work', 'work', true, 'root');
65                this.addList('Ext 2.x', 'ext2', false, 'work');
66                this.addList('Ext 1.x', 'ext1', false, 'work');
67                this.addList('Meetings', 'meetings', false, 'work');
68                this.addList('Miscellaneous', 'work-misc', false, 'work');
69        },
70       
71        bindTree : function(tree){
72                this.boundTrees[tree.id] = {
73                        add: function(ls, records){
74                                var pnode = tree.getNodeById(records[0].data.parentId);
75                                if(pnode){
76                                        pnode.reload();
77                                }
78                        },
79                       
80                        remove: function(ls, record){
81                                var node = tree.getNodeById(record.id);
82                                if(node && node.parentNode){
83                                        node.parentNode.removeChild(node);
84                                }
85                        },
86                       
87                        update: function(ls, record){
88                                var node = tree.getNodeById(record.id);
89                                if(node){
90                                        node.setText(record.data.listName);
91                                }
92                        }
93                };
94               
95                this.on(this.boundTrees[tree.id]);
96        },
97       
98        unbindTree : function(tree){
99                var h = this.boundTrees[tree.id];
100                if (h) {
101                        this.un('add', h.add);
102                        this.un('remove', h.remove);
103                        this.un('update', h.update);
104                }
105        },
106       
107        prepareTable : function(){
108        try{
109        this.createTable({
110            name: 'list',
111            key: 'listId',
112            fields: tx.data.List.prototype.fields
113        });
114        }catch(e){console.log(e);}
115    }
116});
Note: See TracBrowser for help on using the repository browser.