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',
21 initComponent: function(){
23 items: this.createView(),
24 dockedItems: [this.createToolbar()]
29 * @event feedremove Fired when a feed is removed
30 * @param {FeedPanel} this
31 * @param {String} title The title of the feed
32 * @param {String} url The url of the feed
37 * @event feedselect Fired when a feed is selected
38 * @param {FeedPanel} this
39 * @param {String} title The title of the feed
40 * @param {String} url The url of the feed
45 this.callParent(arguments);
49 afterRender: function(){
50 this.callParent(arguments);
52 view.getSelectionModel().select(view.store.first());
56 * Create the DataView to be used for the feed list.
58 * @return {Ext.view.View}
60 createView: function(){
61 var view = this.view = Ext.create('widget.dataview', {
62 store: Ext.create('Ext.data.Store', {
70 selectionchange: this.onSelectionChange
75 contextmenu: this.onContextMenu
79 itemSelector: '.feed-list-item',
80 overItemCls: 'feed-list-item-hover',
81 tpl: '<tpl for="."><div class="feed-list-item">{title}</div></tpl>'
84 view.on('render', function() {
91 * Creates the toolbar to be used for controlling feeds.
93 * @return {Ext.toolbar.Toolbar}
95 createToolbar: function(){
97 this.toolbar = Ext.create('widget.toolbar', {
98 items: [this.addAction, this.removeAction]
104 * Create actions to share between toolbar and menu
107 createActions: function(){
108 this.addAction = Ext.create('Ext.Action', {
110 handler: this.onAddFeedClick,
115 this.removeAction = Ext.create('Ext.Action', {
118 handler: this.onRemoveFeedClick,
120 iconCls: 'feed-remove'
125 * Create the context menu
128 createMenu: function(){
129 this.menu = Ext.create('widget.menu', {
132 handler: this.onLoadClick,
135 }, this.removeAction, '-', this.addAction],
145 * Used when view selection changes so we can disable toolbar buttons.
148 onSelectionChange: function(){
149 var selected = this.getSelectedItem();
150 this.toolbar.getComponent('remove').setDisabled(!selected);
151 this.loadFeed(selected);
155 * React to the load feed menu click.
158 onLoadClick: function(){
159 this.loadFeed(this.menu.activeFeed);
165 * @param {Ext.data.Model} rec The feed
167 loadFeed: function(rec){
169 this.fireEvent('feedselect', this, rec.get('title'), rec.get('url'));
174 * Gets the currently selected record in the view.
176 * @return {Ext.data.Model} Returns the selected model. false if nothing is selected.
178 getSelectedItem: function(){
179 return this.view.getSelectionModel().getSelection()[0] || false;
183 * Listens for the context menu event on the view
186 onContextMenu: function(view, index, el, event){
187 var menu = this.menu;
190 menu.activeFeed = view.store.getAt(index);
191 menu.showAt(event.getXY());
195 * React to a feed being removed
198 onRemoveFeedClick: function(){
199 var active = this.menu.activeFeed || this.getSelectedItem();
202 this.animateNode(this.view.getNode(active), 1, 0, {
204 afteranimate: function(){
205 this.view.store.remove(active);
208 this.fireEvent('feedremove', this, active.get('title'), active.get('url'));
213 * React to a feed attempting to be added
216 onAddFeedClick: function(){
217 var win = Ext.create('widget.feedwindow', {
220 feedvalid: this.onFeedValid
227 * React to a validation on a feed passing
229 * @param {FeedViewer.FeedWindow} win
230 * @param {String} title The title of the feed
231 * @param {String} url The url of the feed
233 onFeedValid: function(win, title, url){
234 var view = this.view,
242 this.animateNode(view.getNode(rec), 0, 1);
246 * Animate a node in the view when it is added/removed
248 * @param {Mixed} el The element to animate
249 * @param {Number} start The start opacity
250 * @param {Number} end The end opacity
251 * @param {Object} listeners (optional) Any listeners
253 animateNode: function(el, start, end, listeners){
254 Ext.create('Ext.fx.Anim', {
268 onDestroy: function(){
273 this.callParent(arguments);