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 * Create the DataView to be used for the feed list.
65 * @return {Ext.view.View}
67 createView: function(){
68 this.view = Ext.create('widget.dataview', {
69 store: Ext.create('Ext.data.Store', {
77 selectionchange: this.onSelectionChange
82 contextmenu: this.onContextMenu,
83 viewready: this.onViewReady
87 itemSelector: '.feed-list-item',
88 overItemCls: 'feed-list-item-hover',
89 tpl: '<tpl for="."><div class="feed-list-item">{title}</div></tpl>'
94 onViewReady: function(){
95 this.view.getSelectionModel().select(this.view.store.first());
99 * Creates the toolbar to be used for controlling feeds.
101 * @return {Ext.toolbar.Toolbar}
103 createToolbar: function(){
104 this.createActions();
105 this.toolbar = Ext.create('widget.toolbar', {
106 items: [this.addAction, this.removeAction]
112 * Create actions to share between toolbar and menu
115 createActions: function(){
116 this.addAction = Ext.create('Ext.Action', {
118 handler: this.onAddFeedClick,
123 this.removeAction = Ext.create('Ext.Action', {
126 handler: this.onRemoveFeedClick,
128 iconCls: 'feed-remove'
133 * Create the context menu
136 createMenu: function(){
137 this.menu = Ext.create('widget.menu', {
140 handler: this.onLoadClick,
143 }, this.removeAction, '-', this.addAction],
153 * Used when view selection changes so we can disable toolbar buttons.
156 onSelectionChange: function(){
157 var selected = this.getSelectedItem();
158 this.toolbar.getComponent('remove').setDisabled(!selected);
159 this.loadFeed(selected);
163 * React to the load feed menu click.
166 onLoadClick: function(){
167 this.loadFeed(this.menu.activeFeed);
173 * @param {Ext.data.Model} rec The feed
175 loadFeed: function(rec){
177 this.fireEvent('feedselect', this, rec.get('title'), rec.get('url'));
182 * Gets the currently selected record in the view.
184 * @return {Ext.data.Model} Returns the selected model. false if nothing is selected.
186 getSelectedItem: function(){
187 return this.view.getSelectionModel().getSelection()[0] || false;
191 * Listens for the context menu event on the view
194 onContextMenu: function(view, index, el, event){
195 var menu = this.menu;
198 menu.activeFeed = view.store.getAt(index);
199 menu.showAt(event.getXY());
203 * React to a feed being removed
206 onRemoveFeedClick: function(){
207 var active = this.menu.activeFeed || this.getSelectedItem();
210 this.animateNode(this.view.getNode(active), 1, 0, {
212 afteranimate: function(){
213 this.view.store.remove(active);
216 this.fireEvent('feedremove', this, active.get('title'), active.get('url'));
221 * React to a feed attempting to be added
224 onAddFeedClick: function(){
225 var win = Ext.create('widget.feedwindow', {
228 feedvalid: this.onFeedValid
235 * React to a validation on a feed passing
237 * @param {FeedViewer.FeedWindow} win
238 * @param {String} title The title of the feed
239 * @param {String} url The url of the feed
241 onFeedValid: function(win, title, url){
242 var view = this.view,
250 this.animateNode(view.getNode(rec), 0, 1);
254 * Animate a node in the view when it is added/removed
256 * @param {Mixed} el The element to animate
257 * @param {Number} start The start opacity
258 * @param {Number} end The end opacity
259 * @param {Object} listeners (optional) Any listeners
261 animateNode: function(el, start, end, listeners){
262 Ext.create('Ext.fx.Anim', {
276 onDestroy: function(){
277 this.callParent(arguments);