]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | Ext.define('FV.controller.Feeds', {\r |
2 | extend: 'Ext.app.Controller',\r | |
3 | \r | |
4 | stores: ['Feeds', 'Articles'],\r | |
5 | models: ['Feed'],\r | |
6 | views: ['feed.Add'],\r | |
7 | \r | |
8 | refs: [\r | |
9 | {ref: 'feedList', selector: 'feedlist'},\r | |
10 | {ref: 'feedData', selector: 'feedlist dataview'},\r | |
11 | {ref: 'feedShow', selector: 'feedshow'},\r | |
12 | {ref: 'feedForm', selector: 'feedwindow form'},\r | |
13 | {ref: 'feedCombo', selector: 'feedwindow combobox'},\r | |
14 | {ref: 'articleGrid', selector: 'articlegrid'},\r | |
15 | {\r | |
16 | ref: 'feedWindow', \r | |
17 | selector: 'feedwindow', \r | |
18 | autoCreate: true,\r | |
19 | xtype: 'feedwindow'\r | |
20 | }\r | |
21 | ],\r | |
22 | \r | |
23 | requires: [\r | |
24 | 'FV.lib.FeedValidator',\r | |
25 | 'FV.store.Articles',\r | |
26 | 'FV.store.Feeds'\r | |
27 | ],\r | |
28 | \r | |
29 | // At this point things haven't rendered yet since init gets called on controllers before the launch function\r | |
30 | // is executed on the Application\r | |
31 | init: function() {\r | |
32 | this.control({\r | |
33 | 'feedlist dataview': {\r | |
34 | selectionchange: this.loadFeed\r | |
35 | },\r | |
36 | 'feedlist button[action=add]': {\r | |
37 | click: this.addFeed\r | |
38 | },\r | |
39 | 'feedlist button[action=remove]': {\r | |
40 | click: this.removeFeed\r | |
41 | },\r | |
42 | 'feedwindow button[action=create]': {\r | |
43 | click: this.createFeed\r | |
44 | }\r | |
45 | });\r | |
46 | },\r | |
47 | \r | |
48 | onLaunch: function() {\r | |
49 | var dataview = this.getFeedData(),\r | |
50 | store = this.getFeedsStore();\r | |
51 | \r | |
52 | dataview.bindStore(store);\r | |
53 | dataview.getSelectionModel().select(store.getAt(0));\r | |
54 | },\r | |
55 | \r | |
56 | /**\r | |
57 | * Loads the given feed into the viewer\r | |
58 | * @param {FV.model.feed} feed The feed to load\r | |
59 | */\r | |
60 | loadFeed: function(selModel, selected) {\r | |
61 | var grid = this.getArticleGrid(),\r | |
62 | store = this.getArticlesStore(),\r | |
63 | feed = selected[0];\r | |
64 | \r | |
65 | if (feed) {\r | |
66 | this.getFeedShow().setTitle(feed.get('name'));\r | |
67 | grid.enable();\r | |
68 | store.load({\r | |
69 | params: {\r | |
70 | feed: feed.get('url')\r | |
71 | }\r | |
72 | }); \r | |
73 | }\r | |
74 | },\r | |
75 | \r | |
76 | /**\r | |
77 | * Shows the add feed dialog window\r | |
78 | */\r | |
79 | addFeed: function() {\r | |
80 | this.getFeedWindow().show();\r | |
81 | },\r | |
82 | \r | |
83 | /**\r | |
84 | * Removes the given feed from the Feeds store\r | |
85 | * @param {FV.model.Feed} feed The feed to remove\r | |
86 | */\r | |
87 | removeFeed: function() {\r | |
88 | this.getFeedsStore().remove(this.getFeedData().getSelectionModel().getSelection()[0]);\r | |
89 | },\r | |
90 | \r | |
91 | /**\r | |
92 | * @private\r | |
93 | * Creates a new feed in the store based on a given url. First validates that the feed is well formed\r | |
94 | * using FV.lib.FeedValidator.\r | |
95 | * @param {String} name The name of the Feed to create\r | |
96 | * @param {String} url The url of the Feed to create\r | |
97 | */\r | |
98 | createFeed: function() {\r | |
99 | var win = this.getFeedWindow(),\r | |
100 | form = this.getFeedForm(),\r | |
101 | combo = this.getFeedCombo(),\r | |
102 | store = this.getFeedsStore(),\r | |
103 | feed = this.getFeedModel().create({\r | |
104 | name: combo.getDisplayValue(),\r | |
105 | url: combo.getValue()\r | |
106 | });\r | |
107 | \r | |
108 | form.setLoading({\r | |
109 | msg: 'Validating feed...'\r | |
110 | });\r | |
111 | \r | |
112 | FV.lib.FeedValidator.validate(feed, {\r | |
113 | success: function() {\r | |
114 | store.add(feed);\r | |
115 | form.setLoading(false);\r | |
116 | win.close();\r | |
117 | },\r | |
118 | failure: function() {\r | |
119 | form.setLoading(false);\r | |
120 | form.down('#feed').markInvalid('The URL specified is not a valid RSS2 feed.');\r | |
121 | }\r | |
122 | });\r | |
123 | }\r | |
124 | }); |