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 var view = 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>'
98 view.on('render', function() {
105 * Creates the toolbar to be used for controlling feeds.
107 * @return {Ext.toolbar.Toolbar}
109 createToolbar: function(){
110 this.createActions();
111 this.toolbar = Ext.create('widget.toolbar', {
112 items: [this.addAction, this.removeAction]
118 * Create actions to share between toolbar and menu
121 createActions: function(){
122 this.addAction = Ext.create('Ext.Action', {
124 handler: this.onAddFeedClick,
129 this.removeAction = Ext.create('Ext.Action', {
132 handler: this.onRemoveFeedClick,
134 iconCls: 'feed-remove'
139 * Create the context menu
142 createMenu: function(){
143 this.menu = Ext.create('widget.menu', {
146 handler: this.onLoadClick,
149 }, this.removeAction, '-', this.addAction],
159 * Used when view selection changes so we can disable toolbar buttons.
162 onSelectionChange: function(){
163 var selected = this.getSelectedItem();
164 this.toolbar.getComponent('remove').setDisabled(!selected);
165 this.loadFeed(selected);
169 * React to the load feed menu click.
172 onLoadClick: function(){
173 this.loadFeed(this.menu.activeFeed);
179 * @param {Ext.data.Model} rec The feed
181 loadFeed: function(rec){
183 this.fireEvent('feedselect', this, rec.get('title'), rec.get('url'));
188 * Gets the currently selected record in the view.
190 * @return {Ext.data.Model} Returns the selected model. false if nothing is selected.
192 getSelectedItem: function(){
193 return this.view.getSelectionModel().getSelection()[0] || false;
197 * Listens for the context menu event on the view
200 onContextMenu: function(view, index, el, event){
201 var menu = this.menu;
204 menu.activeFeed = view.store.getAt(index);
205 menu.showAt(event.getXY());
209 * React to a feed being removed
212 onRemoveFeedClick: function(){
213 var active = this.menu.activeFeed || this.getSelectedItem();
216 this.animateNode(this.view.getNode(active), 1, 0, {
218 afteranimate: function(){
219 this.view.store.remove(active);
222 this.fireEvent('feedremove', this, active.get('title'), active.get('url'));
227 * React to a feed attempting to be added
230 onAddFeedClick: function(){
231 var win = Ext.create('widget.feedwindow', {
234 feedvalid: this.onFeedValid
241 * React to a validation on a feed passing
243 * @param {FeedViewer.FeedWindow} win
244 * @param {String} title The title of the feed
245 * @param {String} url The url of the feed
247 onFeedValid: function(win, title, url){
248 var view = this.view,
256 this.animateNode(view.getNode(rec), 0, 1);
260 * Animate a node in the view when it is added/removed
262 * @param {Mixed} el The element to animate
263 * @param {Number} start The start opacity
264 * @param {Number} end The end opacity
265 * @param {Object} listeners (optional) Any listeners
267 animateNode: function(el, start, end, listeners){
268 Ext.create('Ext.fx.Anim', {
282 onDestroy: function(){
287 this.callParent(arguments);