source: trunk/web/addons/job_monarch/lib/extjs/examples/feed-viewer/FeedPanel.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: 5.1 KB
Line 
1/*
2 * Ext JS Library 2.2.1
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9FeedPanel = function() {
10    FeedPanel.superclass.constructor.call(this, {
11        id:'feed-tree',
12        region:'west',
13        title:'Feeds',
14        split:true,
15        width: 225,
16        minSize: 175,
17        maxSize: 400,
18        collapsible: true,
19        margins:'0 0 5 5',
20        cmargins:'0 5 5 5',
21        rootVisible:false,
22        lines:false,
23        autoScroll:true,
24        root: new Ext.tree.TreeNode('Feed Viewer'),
25        collapseFirst:false,
26
27        tbar: [{
28            iconCls:'add-feed',
29            text:'Add Feed',
30            handler: this.showWindow,
31            scope: this
32        },{
33            id:'delete',
34            iconCls:'delete-icon',
35            text:'Remove',
36            handler: function(){
37                var s = this.getSelectionModel().getSelectedNode();
38                if(s){
39                    this.removeFeed(s.attributes.url);
40                }
41            },
42            scope: this
43        }]
44    });
45
46    this.feeds = this.root.appendChild(
47        new Ext.tree.TreeNode({
48            text:'My Feeds',
49            cls:'feeds-node',
50            expanded:true
51        })
52    );
53
54    this.getSelectionModel().on({
55        'beforeselect' : function(sm, node){
56             return node.isLeaf();
57        },
58        'selectionchange' : function(sm, node){
59            if(node){
60                this.fireEvent('feedselect', node.attributes);
61            }
62            this.getTopToolbar().items.get('delete').setDisabled(!node);
63        },
64        scope:this
65    });
66
67    this.addEvents({feedselect:true});
68
69    this.on('contextmenu', this.onContextMenu, this);
70};
71
72Ext.extend(FeedPanel, Ext.tree.TreePanel, {
73
74    onContextMenu : function(node, e){
75        if(!this.menu){ // create context menu on first right click
76            this.menu = new Ext.menu.Menu({
77                id:'feeds-ctx',
78                items: [{
79                    id:'load',
80                    iconCls:'load-icon',
81                    text:'Load Feed',
82                    scope: this,
83                    handler:function(){
84                        this.ctxNode.select();
85                    }
86                },{
87                    text:'Remove',
88                    iconCls:'delete-icon',
89                    scope: this,
90                    handler:function(){
91                        this.ctxNode.ui.removeClass('x-node-ctx');
92                        this.removeFeed(this.ctxNode.attributes.url);
93                        this.ctxNode = null;
94                    }
95                },'-',{
96                    iconCls:'add-feed',
97                    text:'Add Feed',
98                    handler: this.showWindow,
99                    scope: this
100                }]
101            });
102            this.menu.on('hide', this.onContextHide, this);
103        }
104        if(this.ctxNode){
105            this.ctxNode.ui.removeClass('x-node-ctx');
106            this.ctxNode = null;
107        }
108        if(node.isLeaf()){
109            this.ctxNode = node;
110            this.ctxNode.ui.addClass('x-node-ctx');
111            this.menu.items.get('load').setDisabled(node.isSelected());
112            this.menu.showAt(e.getXY());
113        }
114    },
115
116    onContextHide : function(){
117        if(this.ctxNode){
118            this.ctxNode.ui.removeClass('x-node-ctx');
119            this.ctxNode = null;
120        }
121    },
122
123    showWindow : function(btn){
124        if(!this.win){
125            this.win = new FeedWindow();
126            this.win.on('validfeed', this.addFeed, this);
127        }
128        this.win.show(btn);
129    },
130
131    selectFeed: function(url){
132        this.getNodeById(url).select();
133    },
134
135    removeFeed: function(url){
136        var node = this.getNodeById(url);
137        if(node){
138            node.unselect();
139            Ext.fly(node.ui.elNode).ghost('l', {
140                callback: node.remove, scope: node, duration: .4
141            });
142        }
143    },
144
145    addFeed : function(attrs, inactive, preventAnim){
146        var exists = this.getNodeById(attrs.url);
147        if(exists){
148            if(!inactive){
149                exists.select();
150                exists.ui.highlight();
151            }
152            return;
153        }
154        Ext.apply(attrs, {
155            iconCls: 'feed-icon',
156            leaf:true,
157            cls:'feed',
158            id: attrs.url
159        });
160        var node = new Ext.tree.TreeNode(attrs);
161        this.feeds.appendChild(node);
162        if(!inactive){
163            if(!preventAnim){
164                Ext.fly(node.ui.elNode).slideIn('l', {
165                    callback: node.select, scope: node, duration: .4
166                });
167            }else{
168                node.select();
169            }
170        }
171        return node;
172    },
173
174    // prevent the default context menu when you miss the node
175    afterRender : function(){
176        FeedPanel.superclass.afterRender.call(this);
177        this.el.on('contextmenu', function(e){
178            e.preventDefault();
179        });
180    }
181});
Note: See TracBrowser for help on using the repository browser.