FeedWindow.js
3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* @class FeedViewer.FeedWindow
* @extends Ext.window.Window
*
* Shows a dialog for creating and validating a new feed.
*
* @constructor
* Create a new Feed Window
* @param {Object} config The config object
*/
Ext.define('FeedViewer.FeedWindow', {
extend: 'Ext.window.Window',
alias: 'widget.feedwindow',
plain: true,
resizable: false,
modal: true,
closeAction: 'hide',
defaultFocus: '#feed',
defaultFeeds: [
['http://rss.cnn.com/rss/edition.rss', 'CNN Top Stories'],
['http://sports.espn.go.com/espn/rss/news', 'ESPN Top News'],
['http://news.google.com/news?ned=us&topic=t&output=rss', 'Sci/Tech - Google News'],
['http://rss.news.yahoo.com/rss/software', 'Yahoo Software News']
],
initComponent: function(){
var me = this;
me.addEvents(
/**
* @event feedvalid
* @param {FeedViewer.FeedWindow} this
* @param {String} title
* @param {String} url
* @param {String} description
*/
'feedvalid'
);
me.form = Ext.create('widget.form', {
bodyPadding: '12 10 10',
border: false,
unstyled: true,
items: [{
anchor: '100%',
itemId: 'feed',
fieldLabel: 'Enter the URL of the feed to add',
labelAlign: 'top',
msgTarget: 'under',
xtype: 'combo',
store: this.defaultFeeds,
getInnerTpl: function(){
return '<div class="feed-picker-url">{field1}</div><div class="feed-picker-title">{field2}</div>';
}
}]
});
Ext.apply(me, {
width: 500,
title: 'Add Feed',
iconCls: 'feed',
layout: 'fit',
items: me.form,
buttons: [{
xtype: 'button',
text: 'Add Feed',
scope: me,
handler: me.onAddClick
}, {
xtype: 'button',
text: 'Cancel',
scope: me,
handler: me.hide
}]
});
me.callParent(arguments);
},
/**
* React to the add button being clicked.
* @private
*/
onAddClick: function(addBtn) {
addBtn.disable();
var url = this.form.getComponent('feed').getValue();
this.form.setLoading({
msg: 'Validating feed...'
});
Ext.Ajax.request({
url: 'feed-proxy.php',
params: {
feed: url
},
success: this.validateFeed,
failure: this.markInvalid,
scope: this
});
},
/**
* React to the feed validation passing
* @private
* @param {Object} response The response object
*/
validateFeed: function(response) {
this.form.setLoading(false);
this.down('button[text=Add Feed]').enable();
var dq = Ext.DomQuery,
url = this.form.getComponent('feed').getValue(),
xml,
channel,
title;
try {
xml = response.responseXML;
channel = xml.getElementsByTagName('channel')[0];
if (channel) {
title = dq.selectValue('title', channel, url);
this.fireEvent('feedvalid', this, title, url);
this.hide();
return;
}
} catch(e) {
}
this.markInvalid();
},
/**
* React to the feed validation failing
* @private
*/
markInvalid: function(){
this.down('button[text=Add Feed]').enable();
this.form.setLoading(false);
this.form.getComponent('feed').markInvalid('The URL specified is not a valid RSS2 feed.');
}
});