1 | /*! |
---|
2 | * Ext JS Library 3.0.0 |
---|
3 | * Copyright(c) 2006-2009 Ext JS, LLC |
---|
4 | * licensing@extjs.com |
---|
5 | * http://www.extjs.com/license |
---|
6 | */ |
---|
7 | FeedWindow = function() { |
---|
8 | this.feedUrl = new Ext.form.ComboBox({ |
---|
9 | id: 'feed-url', |
---|
10 | fieldLabel: 'Enter the URL of the feed to add', |
---|
11 | emptyText: 'http://example.com/blog/feed', |
---|
12 | width: 450, |
---|
13 | validationEvent: false, |
---|
14 | validateOnBlur: false, |
---|
15 | msgTarget: 'under', |
---|
16 | triggerAction: 'all', |
---|
17 | displayField: 'url', |
---|
18 | mode: 'local', |
---|
19 | |
---|
20 | listeners:{ |
---|
21 | valid: this.syncShadow, |
---|
22 | invalid: this.syncShadow, |
---|
23 | scope: this |
---|
24 | }, |
---|
25 | tpl: new Ext.XTemplate( |
---|
26 | '<tpl for="."><div class="x-combo-list-item">', |
---|
27 | '<em>{url}</em><strong>{text}</strong>', |
---|
28 | '<div class="x-clear"></div>', |
---|
29 | '</div></tpl>'), |
---|
30 | store: new Ext.data.ArrayStore({ |
---|
31 | fields: ['url', 'text'], |
---|
32 | data : this.defaultFeeds |
---|
33 | }) |
---|
34 | }); |
---|
35 | |
---|
36 | this.form = new Ext.FormPanel({ |
---|
37 | labelAlign:'top', |
---|
38 | items:this.feedUrl, |
---|
39 | border: false, |
---|
40 | bodyStyle:'background:transparent;padding:10px;' |
---|
41 | }); |
---|
42 | |
---|
43 | FeedWindow.superclass.constructor.call(this, { |
---|
44 | title: 'Add Feed', |
---|
45 | iconCls: 'feed-icon', |
---|
46 | id: 'add-feed-win', |
---|
47 | autoHeight: true, |
---|
48 | width: 500, |
---|
49 | resizable: false, |
---|
50 | plain:true, |
---|
51 | modal: true, |
---|
52 | y: 100, |
---|
53 | autoScroll: true, |
---|
54 | closeAction: 'hide', |
---|
55 | |
---|
56 | buttons:[{ |
---|
57 | text: 'Add Feed!', |
---|
58 | handler: this.onAdd, |
---|
59 | scope: this |
---|
60 | },{ |
---|
61 | text: 'Cancel', |
---|
62 | handler: this.hide.createDelegate(this, []) |
---|
63 | }], |
---|
64 | |
---|
65 | items: this.form |
---|
66 | }); |
---|
67 | |
---|
68 | this.addEvents({add:true}); |
---|
69 | } |
---|
70 | |
---|
71 | Ext.extend(FeedWindow, Ext.Window, { |
---|
72 | defaultFeeds : [ |
---|
73 | ['http://www.divergingpath.com/rss.cfm?mode=full', 'Aaron Conran\'s Blog'], |
---|
74 | ['http://feeds.yuiblog.com/YahooUserInterfaceBlog', 'Yahoo! UI Blog'], |
---|
75 | ['http://feeds.feedburner.com/jquery/', 'jQuery Blog'], |
---|
76 | ['http://sports.yahoo.com/nba/rss.xml', 'NBA News'], |
---|
77 | ['http://feeds.dzone.com/dzone/frontpage', 'DZone.com'] |
---|
78 | ], |
---|
79 | |
---|
80 | show : function(){ |
---|
81 | if(this.rendered){ |
---|
82 | this.feedUrl.setValue(''); |
---|
83 | } |
---|
84 | FeedWindow.superclass.show.apply(this, arguments); |
---|
85 | }, |
---|
86 | |
---|
87 | onAdd: function() { |
---|
88 | this.el.mask('Validating Feed...', 'x-mask-loading'); |
---|
89 | var url = this.feedUrl.getValue(); |
---|
90 | Ext.Ajax.request({ |
---|
91 | url: 'feed-proxy.php', |
---|
92 | params: {feed: url}, |
---|
93 | success: this.validateFeed, |
---|
94 | failure: this.markInvalid, |
---|
95 | scope: this, |
---|
96 | feedUrl: url |
---|
97 | }); |
---|
98 | }, |
---|
99 | |
---|
100 | markInvalid : function(){ |
---|
101 | this.feedUrl.markInvalid('The URL specified is not a valid RSS2 feed.'); |
---|
102 | this.el.unmask(); |
---|
103 | }, |
---|
104 | |
---|
105 | validateFeed : function(response, options){ |
---|
106 | var dq = Ext.DomQuery; |
---|
107 | var url = options.feedUrl; |
---|
108 | |
---|
109 | try{ |
---|
110 | var xml = response.responseXML; |
---|
111 | var channel = xml.getElementsByTagName('channel')[0]; |
---|
112 | if(channel){ |
---|
113 | var text = dq.selectValue('title', channel, url); |
---|
114 | var description = dq.selectValue('description', channel, 'No description available.'); |
---|
115 | this.el.unmask(); |
---|
116 | this.hide(); |
---|
117 | |
---|
118 | return this.fireEvent('validfeed', { |
---|
119 | url: url, |
---|
120 | text: text, |
---|
121 | description: description |
---|
122 | }); |
---|
123 | } |
---|
124 | }catch(e){ |
---|
125 | } |
---|
126 | this.markInvalid(); |
---|
127 | } |
---|
128 | }); |
---|