Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / examples / key-feed-viewer / viewer / FeedInfo.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class FeedViewer.FeedInfo
17  * @extends Ext.tab.Panel
18  *
19  * A container class for showing a series of feed details
20  * 
21  * @constructor
22  * Create a new Feed Info
23  * @param {Object} config The config object
24  */
25 Ext.define('FeedViewer.FeedInfo', {
26     
27     extend: 'Ext.tab.Panel',
28     alias: 'widget.feedinfo',
29     
30     maxTabWidth: 230,
31     border: false,
32     
33     initComponent: function() {
34         this.tabBar = {
35             border: true
36         };
37         
38         this.callParent();
39     },
40     
41     /**
42      * Add a new feed
43      * @param {String} title The title of the feed
44      * @param {String} url The url of the feed
45      */
46     addFeed: function(title, url){
47         var active = this.items.first();
48         if (!active) {
49             active = this.add({
50                 xtype: 'feeddetail',
51                 title: title,
52                 url: url,
53                 closable: false,
54                 listeners: {
55                     scope: this,
56                     opentab: this.onTabOpen,
57                     openall: this.onOpenAll,
58                     rowdblclick: this.onRowDblClick
59                 }
60             });
61         } else {
62             active.loadFeed(url);
63             active.tab.setText(title);
64         }
65         this.setActiveTab(active);
66     },
67     
68     /**
69      * Listens for a new tab request
70      * @private
71      * @param {FeedViewer.FeedPost} The post
72      * @param {Ext.data.Model} model The model
73      */
74     onTabOpen: function(post, rec){
75         var item = this.add({
76             inTab: true,
77             xtype: 'feedpost',
78             title: rec.get('title'),
79             closable: true,
80             data: rec.data,
81             active: rec
82         });
83         item.tab.setClosable(true);
84         this.setActiveTab(item);
85     },
86     
87     /**
88      * Listens for a row dblclick
89      * @private
90      * @param {FeedViewer.Detail} detail The detail
91      * @param {Ext.data.Model} model The model
92      */
93     onRowDblClick: function(info, rec){
94         this.onTabOpen(null, rec);
95     },
96     
97     /**
98      * Listens for the open all click
99      * @private
100      * @param {FeedViewer.FeedDetail}
101      */
102     onOpenAll: function(detail){
103         var items = detail.getFeedData();
104         Ext.each(items, function(rec){
105             this.onTabOpen(null, rec);
106         }, this);
107     }
108 });