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(),
86 * Shows the add feed dialog window
89 this.getFeedWindow().show();
93 * Removes the given feed from the Feeds store
94 * @param {FV.model.Feed} feed The feed to remove
96 removeFeed: function() {
97 this.getFeedsStore().remove(this.getFeedData().getSelectionModel().getSelection()[0]);
102 * Creates a new feed in the store based on a given url. First validates that the feed is well formed
103 * using FV.lib.FeedValidator.
104 * @param {String} name The name of the Feed to create
105 * @param {String} url The url of the Feed to create
107 createFeed: function() {
108 var win = this.getFeedWindow(),
109 form = this.getFeedForm(),
110 combo = this.getFeedCombo(),
111 store = this.getFeedsStore(),
112 feed = this.getFeedModel().create({
113 name: combo.getDisplayValue(),
114 url: combo.getValue()
118 msg: 'Validating feed...'
121 FV.lib.FeedValidator.validate(feed, {
122 success: function() {
124 form.setLoading(false);
127 failure: function() {
128 form.setLoading(false);
129 form.down('[name=feed]').markInvalid('The URL specified is not a valid RSS2 feed.');