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