Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / examples / feed-viewer / viewer / FeedViewer.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.FeedViewer
17  * @extends Ext.container.Viewport
18  *
19  * The main FeedViewer application
20  * 
21  * @constructor
22  * Create a new Feed Viewer app
23  * @param {Object} config The config object
24  */
25
26 Ext.define('FeedViewer.App', {
27     extend: 'Ext.container.Viewport',
28     
29     initComponent: function(){
30         
31         Ext.define('Feed', {
32             extend: 'Ext.data.Model',
33             fields: ['title', 'url']
34         });
35
36         Ext.define('FeedItem', {
37             extend: 'Ext.data.Model',
38             fields: ['title', 'author', {
39                 name: 'pubDate',
40                 type: 'date'
41             }, 'link', 'description', 'content']
42         });
43         
44         Ext.apply(this, {
45             layout: 'border',
46             padding: 5,
47             items: [this.createFeedPanel(), this.createFeedInfo()]
48         });
49         this.callParent(arguments);
50     },
51     
52     /**
53      * Create the list of fields to be shown on the left
54      * @private
55      * @return {FeedViewer.FeedPanel} feedPanel
56      */
57     createFeedPanel: function(){
58         this.feedPanel = Ext.create('widget.feedpanel', {
59             region: 'west',
60             collapsible: true,
61             width: 225,
62             floatable: false,
63             split: true,
64             minWidth: 175,
65             feeds: [{
66                 title: 'Sencha Blog',
67                 url: 'http://feeds.feedburner.com/extblog'
68             }, {
69                 title: 'Sencha Forums',
70                 url: 'http://sencha.com/forum/external.php?type=RSS2'
71             }, {
72                 title: 'Ajaxian',
73                 url: 'http://feeds.feedburner.com/ajaxian'
74             }],
75             listeners: {
76                 scope: this,
77                 feedselect: this.onFeedSelect
78             }
79         });
80         return this.feedPanel;
81     },
82     
83     /**
84      * Create the feed info container
85      * @private
86      * @return {FeedViewer.FeedInfo} feedInfo
87      */
88     createFeedInfo: function(){
89         this.feedInfo = Ext.create('widget.feedinfo', {
90             region: 'center',
91             minWidth: 300
92         });
93         return this.feedInfo;
94     },
95     
96     /**
97      * Reacts to a feed being selected
98      * @private
99      */
100     onFeedSelect: function(feed, title, url){
101         this.feedInfo.addFeed(title, url);
102     }
103 });
104