Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / examples / feed-viewer / viewer / FeedInfo.js
1 /**
2  * @class FeedViewer.FeedInfo
3  * @extends Ext.tab.Panel
4  *
5  * A container class for showing a series of feed details
6  * 
7  * @constructor
8  * Create a new Feed Info
9  * @param {Object} config The config object
10  */
11 Ext.define('FeedViewer.FeedInfo', {
12     
13     extend: 'Ext.tab.Panel',
14     alias: 'widget.feedinfo',
15     
16     maxTabWidth: 230,
17     border: false,
18     
19     initComponent: function() {
20         this.tabBar = {
21             border: true
22         };
23         
24         this.callParent();
25     },
26     
27     /**
28      * Add a new feed
29      * @param {String} title The title of the feed
30      * @param {String} url The url of the feed
31      */
32     addFeed: function(title, url){
33         var active = this.items.first();
34         if (!active) {
35             active = this.add({
36                 xtype: 'feeddetail',
37                 title: title,
38                 url: url,
39                 closable: false,
40                 listeners: {
41                     scope: this,
42                     opentab: this.onTabOpen,
43                     openall: this.onOpenAll,
44                     rowdblclick: this.onRowDblClick
45                 }
46             });
47         } else {
48             active.loadFeed(url);
49             active.tab.setText(title);
50         }
51         this.setActiveTab(active);
52     },
53     
54     /**
55      * Listens for a new tab request
56      * @private
57      * @param {FeedViewer.FeedPost} The post
58      * @param {Ext.data.Model} model The model
59      */
60     onTabOpen: function(post, rec) {
61         var items = [],
62             item;
63         if (Ext.isArray(rec)) {
64             Ext.each(rec, function(rec) {
65                 items.push({
66                     inTab: true,
67                     xtype: 'feedpost',
68                     title: rec.get('title'),
69                     closable: true,
70                     data: rec.data,
71                     active: rec
72                 });
73             });
74             this.add(items);
75         }
76         else {
77             item = this.add({
78                 inTab: true,
79                 xtype: 'feedpost',
80                 title: rec.get('title'),
81                 closable: true,
82                 data: rec.data,
83                 active: rec
84             });
85             this.setActiveTab(item);
86         }
87     },
88     
89     /**
90      * Listens for a row dblclick
91      * @private
92      * @param {FeedViewer.Detail} detail The detail
93      * @param {Ext.data.Model} model The model
94      */
95     onRowDblClick: function(info, rec){
96         this.onTabOpen(null, rec);
97     },
98     
99     /**
100      * Listens for the open all click
101      * @private
102      * @param {FeedViewer.FeedDetail}
103      */
104     onOpenAll: function(detail) {
105         this.onTabOpen(null, detail.getFeedData());
106     }
107 });