2 * @class FeedViewer.FeedPanel
3 * @extends Ext.panel.Panel
5 * Shows a list of available feeds. Also has the ability to add/remove and load feeds.
8 * Create a new Feed Panel
9 * @param {Object} config The config object
12 Ext.define('FeedViewer.FeedPanel', {
13 extend: 'Ext.panel.Panel',
15 alias: 'widget.feedpanel',
17 initComponent: function(){
22 items: this.createView(),
23 dockedItems: this.createToolbar()
28 * @event feedremove Fired when a feed is removed
29 * @param {FeedPanel} this
30 * @param {String} title The title of the feed
31 * @param {String} url The url of the feed
36 * @event feedselect Fired when a feed is selected
37 * @param {FeedPanel} this
38 * @param {String} title The title of the feed
39 * @param {String} url The url of the feed
44 this.callParent(arguments);
48 afterRender: function(){
49 this.callParent(arguments);
51 view.getSelectionModel().select(view.store.first());
55 * Create the DataView to be used for the feed list.
57 * @return {Ext.view.View}
59 createView: function(){
60 this.view = Ext.create('widget.dataview', {
61 store: Ext.create('Ext.data.Store', {
69 selectionchange: this.onSelectionChange
74 contextmenu: this.onContextMenu
78 itemSelector: '.feed-list-item',
79 overItemCls: 'feed-list-item-hover',
80 tpl: '<tpl for="."><div class="feed-list-item">{title}</div></tpl>'
86 * Creates the toolbar to be used for controlling feeds.
88 * @return {Ext.toolbar.Toolbar}
90 createToolbar: function(){
92 this.toolbar = Ext.create('widget.toolbar', {
93 items: [this.addAction, this.removeAction]
99 * Create actions to share between toolbar and menu
102 createActions: function(){
103 this.addAction = Ext.create('Ext.Action', {
105 handler: this.onAddFeedClick,
110 this.removeAction = Ext.create('Ext.Action', {
113 handler: this.onRemoveFeedClick,
115 iconCls: 'feed-remove'
120 * Create the context menu
123 createMenu: function(){
124 this.menu = Ext.create('widget.menu', {
127 handler: this.onLoadClick,
130 }, this.removeAction, '-', this.addAction],
140 * Used when view selection changes so we can disable toolbar buttons.
143 onSelectionChange: function(){
144 var selected = this.getSelectedItem();
145 this.toolbar.getComponent('remove').setDisabled(!selected);
146 this.loadFeed(selected);
150 * React to the load feed menu click.
153 onLoadClick: function(){
154 this.loadFeed(this.menu.activeFeed);
160 * @param {Ext.data.Model} rec The feed
162 loadFeed: function(rec){
164 this.fireEvent('feedselect', this, rec.get('title'), rec.get('url'));
169 * Gets the currently selected record in the view.
171 * @return {Ext.data.Model} Returns the selected model. false if nothing is selected.
173 getSelectedItem: function(){
174 return this.view.getSelectionModel().getSelection()[0] || false;
178 * Listens for the context menu event on the view
181 onContextMenu: function(view, index, el, event){
182 var menu = this.menu;
185 menu.activeFeed = view.store.getAt(index);
186 menu.showAt(event.getXY());
190 * React to a feed being removed
193 onRemoveFeedClick: function(){
194 var active = this.menu.activeFeed || this.getSelectedItem();
197 this.animateNode(this.view.getNode(active), 1, 0, {
199 afteranimate: function(){
200 this.view.store.remove(active);
203 this.fireEvent('feedremove', this, active.get('title'), active.get('url'));
208 * React to a feed attempting to be added
211 onAddFeedClick: function(){
212 var win = Ext.create('widget.feedwindow', {
215 feedvalid: this.onFeedValid
222 * React to a validation on a feed passing
224 * @param {FeedViewer.FeedWindow} win
225 * @param {String} title The title of the feed
226 * @param {String} url The url of the feed
228 onFeedValid: function(win, title, url){
229 var view = this.view,
237 this.animateNode(view.getNode(rec), 0, 1);
241 * Animate a node in the view when it is added/removed
243 * @param {Mixed} el The element to animate
244 * @param {Number} start The start opacity
245 * @param {Number} end The end opacity
246 * @param {Object} listeners (optional) Any listeners
248 animateNode: function(el, start, end, listeners){
249 Ext.create('Ext.fx.Anim', {
263 onDestroy: function(){
264 this.callParent(arguments);