1 Ext.define('FV.controller.Feeds', {
2 extend: 'Ext.app.Controller',
4 stores: ['Feeds', 'Articles'],
9 {ref: 'feedList', selector: 'feedlist'},
10 {ref: 'feedData', selector: 'feedlist dataview'},
11 {ref: 'feedShow', selector: 'feedshow'},
12 {ref: 'feedForm', selector: 'feedwindow form'},
13 {ref: 'feedCombo', selector: 'feedwindow combobox'},
14 {ref: 'articleGrid', selector: 'articlegrid'},
17 selector: 'feedwindow',
23 requires: ['FV.lib.FeedValidator'],
25 // At this point things haven't rendered yet since init gets called on controllers before the launch function
26 // is executed on the Application
29 'feedlist dataview': {
30 selectionchange: this.loadFeed
32 'feedlist button[action=add]': {
35 'feedlist button[action=remove]': {
36 click: this.removeFeed
38 'feedwindow button[action=create]': {
39 click: this.createFeed
44 onLaunch: function() {
45 var dataview = this.getFeedData(),
46 store = this.getFeedsStore();
48 dataview.bindStore(store);
49 dataview.getSelectionModel().select(store.getAt(0));
53 * Loads the given feed into the viewer
54 * @param {FV.model.feed} feed The feed to load
56 loadFeed: function(selModel, selected) {
57 var grid = this.getArticleGrid(),
58 store = this.getArticlesStore(),
72 * Shows the add feed dialog window
75 this.getFeedWindow().show();
79 * Removes the given feed from the Feeds store
80 * @param {FV.model.Feed} feed The feed to remove
82 removeFeed: function() {
83 this.getFeedsStore().remove(this.getFeedData().getSelectionModel().getSelection()[0]);
88 * Creates a new feed in the store based on a given url. First validates that the feed is well formed
89 * using FV.lib.FeedValidator.
90 * @param {String} name The name of the Feed to create
91 * @param {String} url The url of the Feed to create
93 createFeed: function() {
94 var win = this.getFeedWindow(),
95 form = this.getFeedForm(),
96 combo = this.getFeedCombo(),
97 store = this.getFeedsStore(),
98 feed = this.getFeedModel().create({
99 name: combo.getDisplayValue(),
100 url: combo.getValue()
104 msg: 'Validating feed...'
107 FV.lib.FeedValidator.validate(feed, {
108 success: function() {
110 form.setLoading(false);
113 failure: function() {
114 form.setLoading(false);
115 form.down('[name=feed]').markInvalid('The URL specified is not a valid RSS2 feed.');