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 var view = 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>'
83 view.on('render', function() {
90 * Creates the toolbar to be used for controlling feeds.
92 * @return {Ext.toolbar.Toolbar}
94 createToolbar: function(){
96 this.toolbar = Ext.create('widget.toolbar', {
97 items: [this.addAction, this.removeAction]
103 * Create actions to share between toolbar and menu
106 createActions: function(){
107 this.addAction = Ext.create('Ext.Action', {
109 handler: this.onAddFeedClick,
114 this.removeAction = Ext.create('Ext.Action', {
117 handler: this.onRemoveFeedClick,
119 iconCls: 'feed-remove'
124 * Create the context menu
127 createMenu: function(){
128 this.menu = Ext.create('widget.menu', {
131 handler: this.onLoadClick,
134 }, this.removeAction, '-', this.addAction],
144 * Used when view selection changes so we can disable toolbar buttons.
147 onSelectionChange: function(){
148 var selected = this.getSelectedItem();
149 this.toolbar.getComponent('remove').setDisabled(!selected);
150 this.loadFeed(selected);
154 * React to the load feed menu click.
157 onLoadClick: function(){
158 this.loadFeed(this.menu.activeFeed);
164 * @param {Ext.data.Model} rec The feed
166 loadFeed: function(rec){
168 this.fireEvent('feedselect', this, rec.get('title'), rec.get('url'));
173 * Gets the currently selected record in the view.
175 * @return {Ext.data.Model} Returns the selected model. false if nothing is selected.
177 getSelectedItem: function(){
178 return this.view.getSelectionModel().getSelection()[0] || false;
182 * Listens for the context menu event on the view
185 onContextMenu: function(view, index, el, event){
186 var menu = this.menu;
189 menu.activeFeed = view.store.getAt(index);
190 menu.showAt(event.getXY());
194 * React to a feed being removed
197 onRemoveFeedClick: function(){
198 var active = this.menu.activeFeed || this.getSelectedItem();
201 this.animateNode(this.view.getNode(active), 1, 0, {
203 afteranimate: function(){
204 this.view.store.remove(active);
207 this.fireEvent('feedremove', this, active.get('title'), active.get('url'));
212 * React to a feed attempting to be added
215 onAddFeedClick: function(){
216 var win = Ext.create('widget.feedwindow', {
219 feedvalid: this.onFeedValid
226 * React to a validation on a feed passing
228 * @param {FeedViewer.FeedWindow} win
229 * @param {String} title The title of the feed
230 * @param {String} url The url of the feed
232 onFeedValid: function(win, title, url){
233 var view = this.view,
241 this.animateNode(view.getNode(rec), 0, 1);
245 * Animate a node in the view when it is added/removed
247 * @param {Mixed} el The element to animate
248 * @param {Number} start The start opacity
249 * @param {Number} end The end opacity
250 * @param {Object} listeners (optional) Any listeners
252 animateNode: function(el, start, end, listeners){
253 Ext.create('Ext.fx.Anim', {
267 onDestroy: function(){
272 this.callParent(arguments);