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.
15 Ext.define('FV.controller.Feeds', {
16 extend: 'Ext.app.Controller',
18 stores: ['Feeds', 'Articles'],
23 {ref: 'feedList', selector: 'feedlist'},
24 {ref: 'feedData', selector: 'feedlist dataview'},
25 {ref: 'feedShow', selector: 'feedshow'},
26 {ref: 'feedForm', selector: 'feedwindow form'},
27 {ref: 'feedCombo', selector: 'feedwindow combobox'},
28 {ref: 'articleGrid', selector: 'articlegrid'},
31 selector: 'feedwindow',
37 requires: ['FV.lib.FeedValidator'],
39 // At this point things haven't rendered yet since init gets called on controllers before the launch function
40 // is executed on the Application
43 'feedlist dataview': {
44 selectionchange: this.loadFeed
46 'feedlist button[action=add]': {
49 'feedlist button[action=remove]': {
50 click: this.removeFeed
52 'feedwindow button[action=create]': {
53 click: this.createFeed
58 onLaunch: function() {
59 var dataview = this.getFeedData(),
60 store = this.getFeedsStore();
62 dataview.bindStore(store);
63 dataview.getSelectionModel().select(store.getAt(0));
67 * Loads the given feed into the viewer
68 * @param {FV.model.feed} feed The feed to load
70 loadFeed: function(selModel, selected) {
71 var grid = this.getArticleGrid(),
72 store = this.getArticlesStore(),
76 this.getFeedShow().setTitle(feed.get('name'));
87 * Shows the add feed dialog window
90 this.getFeedWindow().show();
94 * Removes the given feed from the Feeds store
95 * @param {FV.model.Feed} feed The feed to remove
97 removeFeed: function() {
98 this.getFeedsStore().remove(this.getFeedData().getSelectionModel().getSelection()[0]);
103 * Creates a new feed in the store based on a given url. First validates that the feed is well formed
104 * using FV.lib.FeedValidator.
105 * @param {String} name The name of the Feed to create
106 * @param {String} url The url of the Feed to create
108 createFeed: function() {
109 var win = this.getFeedWindow(),
110 form = this.getFeedForm(),
111 combo = this.getFeedCombo(),
112 store = this.getFeedsStore(),
113 feed = this.getFeedModel().create({
114 name: combo.getDisplayValue(),
115 url: combo.getValue()
119 msg: 'Validating feed...'
122 FV.lib.FeedValidator.validate(feed, {
123 success: function() {
125 form.setLoading(false);
128 failure: function() {
129 form.setLoading(false);
130 form.down('[name=feed]').markInvalid('The URL specified is not a valid RSS2 feed.');