Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / examples / 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 items = [],
76             item;
77         if (Ext.isArray(rec)) {
78             Ext.each(rec, function(rec) {
79                 items.push({
80                     inTab: true,
81                     xtype: 'feedpost',
82                     title: rec.get('title'),
83                     closable: true,
84                     data: rec.data,
85                     active: rec
86                 });
87             });
88             this.add(items);
89         }
90         else {
91             item = this.add({
92                 inTab: true,
93                 xtype: 'feedpost',
94                 title: rec.get('title'),
95                 closable: true,
96                 data: rec.data,
97                 active: rec
98             });
99             this.setActiveTab(item);
100         }
101     },
102     
103     /**
104      * Listens for a row dblclick
105      * @private
106      * @param {FeedViewer.Detail} detail The detail
107      * @param {Ext.data.Model} model The model
108      */
109     onRowDblClick: function(info, rec){
110         this.onTabOpen(null, rec);
111     },
112     
113     /**
114      * Listens for the open all click
115      * @private
116      * @param {FeedViewer.FeedDetail}
117      */
118     onOpenAll: function(detail) {
119         this.onTabOpen(null, detail.getFeedData());
120     }
121 });