3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
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.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class FeedViewer.FeedPanel
17 * @extends Ext.panel.Panel
19 * Shows a list of available feeds. Also has the ability to add/remove and load feeds.
22 * Create a new Feed Panel
23 * @param {Object} config The config object
26 Ext.define('FeedViewer.FeedPanel', {
27 extend: 'Ext.panel.Panel',
29 alias: 'widget.feedpanel',
35 initComponent: function(){
37 items: this.createView(),
38 dockedItems: this.createToolbar()
43 * @event feedremove Fired when a feed is removed
44 * @param {FeedPanel} this
45 * @param {String} title The title of the feed
46 * @param {String} url The url of the feed
51 * @event feedselect Fired when a feed is selected
52 * @param {FeedPanel} this
53 * @param {String} title The title of the feed
54 * @param {String} url The url of the feed
59 this.callParent(arguments);
63 afterRender: function(){
64 this.callParent(arguments);
66 view.getSelectionModel().select(view.store.first());
70 * Create the DataView to be used for the feed list.
72 * @return {Ext.view.View}
74 createView: function(){
75 this.view = Ext.create('widget.dataview', {
76 store: Ext.create('Ext.data.Store', {
84 selectionchange: this.onSelectionChange
89 contextmenu: this.onContextMenu
93 itemSelector: '.feed-list-item',
94 overItemCls: 'feed-list-item-hover',
95 tpl: '<tpl for="."><div class="feed-list-item">{title}</div></tpl>'
101 * Creates the toolbar to be used for controlling feeds.
103 * @return {Ext.toolbar.Toolbar}
105 createToolbar: function(){
106 this.createActions();
107 this.toolbar = Ext.create('widget.toolbar', {
108 items: [this.addAction, this.removeAction]
114 * Create actions to share between toolbar and menu
117 createActions: function(){
118 this.addAction = Ext.create('Ext.Action', {
120 handler: this.onAddFeedClick,
125 this.removeAction = Ext.create('Ext.Action', {
128 handler: this.onRemoveFeedClick,
130 iconCls: 'feed-remove'
135 * Create the context menu
138 createMenu: function(){
139 this.menu = Ext.create('widget.menu', {
142 handler: this.onLoadClick,
145 }, this.removeAction, '-', this.addAction],
155 * Used when view selection changes so we can disable toolbar buttons.
158 onSelectionChange: function(){
159 var selected = this.getSelectedItem();
160 this.toolbar.getComponent('remove').setDisabled(!selected);
161 this.loadFeed(selected);
165 * React to the load feed menu click.
168 onLoadClick: function(){
169 this.loadFeed(this.menu.activeFeed);
175 * @param {Ext.data.Model} rec The feed
177 loadFeed: function(rec){
179 this.fireEvent('feedselect', this, rec.get('title'), rec.get('url'));
184 * Gets the currently selected record in the view.
186 * @return {Ext.data.Model} Returns the selected model. false if nothing is selected.
188 getSelectedItem: function(){
189 return this.view.getSelectionModel().getSelection()[0] || false;
193 * Listens for the context menu event on the view
196 onContextMenu: function(view, index, el, event){
197 var menu = this.menu;
200 menu.activeFeed = view.store.getAt(index);
201 menu.showAt(event.getXY());
205 * React to a feed being removed
208 onRemoveFeedClick: function(){
209 var active = this.menu.activeFeed || this.getSelectedItem();
212 this.animateNode(this.view.getNode(active), 1, 0, {
214 afteranimate: function(){
215 this.view.store.remove(active);
218 this.fireEvent('feedremove', this, active.get('title'), active.get('url'));
223 * React to a feed attempting to be added
226 onAddFeedClick: function(){
227 var win = Ext.create('widget.feedwindow', {
230 feedvalid: this.onFeedValid
237 * React to a validation on a feed passing
239 * @param {FeedViewer.FeedWindow} win
240 * @param {String} title The title of the feed
241 * @param {String} url The url of the feed
243 onFeedValid: function(win, title, url){
244 var view = this.view,
252 this.animateNode(view.getNode(rec), 0, 1);
256 * Animate a node in the view when it is added/removed
258 * @param {Mixed} el The element to animate
259 * @param {Number} start The start opacity
260 * @param {Number} end The end opacity
261 * @param {Object} listeners (optional) Any listeners
263 animateNode: function(el, start, end, listeners){
264 Ext.create('Ext.fx.Anim', {
278 onDestroy: function(){
279 this.callParent(arguments);