You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
4.1 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. FeedWindow = function() {
  16. this.feedUrl = new Ext.form.ComboBox({
  17. id: 'feed-url',
  18. fieldLabel: 'Enter the URL of the feed to add',
  19. emptyText: 'http://example.com/blog/feed',
  20. width: 450,
  21. validationEvent: false,
  22. validateOnBlur: false,
  23. msgTarget: 'under',
  24. triggerAction: 'all',
  25. displayField: 'url',
  26. mode: 'local',
  27. listeners:{
  28. valid: this.syncShadow,
  29. invalid: this.syncShadow,
  30. scope: this
  31. },
  32. tpl: new Ext.XTemplate(
  33. '<tpl for="."><div class="x-combo-list-item">',
  34. '<em>{url}</em><strong>{text}</strong>',
  35. '<div class="x-clear"></div>',
  36. '</div></tpl>'),
  37. store: new Ext.data.ArrayStore({
  38. fields: ['url', 'text'],
  39. data : this.defaultFeeds
  40. })
  41. });
  42. this.form = new Ext.FormPanel({
  43. labelAlign:'top',
  44. items:this.feedUrl,
  45. border: false,
  46. bodyStyle:'background:transparent;padding:10px;'
  47. });
  48. FeedWindow.superclass.constructor.call(this, {
  49. title: 'Add Feed',
  50. iconCls: 'feed-icon',
  51. id: 'add-feed-win',
  52. autoHeight: true,
  53. width: 500,
  54. resizable: false,
  55. plain:true,
  56. modal: true,
  57. y: 100,
  58. autoScroll: true,
  59. closeAction: 'hide',
  60. buttons:[{
  61. text: 'Add Feed!',
  62. handler: this.onFeedAdd,
  63. scope: this
  64. },{
  65. text: 'Cancel',
  66. handler: this.hide.createDelegate(this, [])
  67. }],
  68. items: this.form
  69. });
  70. this.addEvents({add:true});
  71. }
  72. Ext.extend(FeedWindow, Ext.Window, {
  73. defaultFeeds : [
  74. ['http://www.divergingpath.com/rss.cfm?mode=full', 'Aaron Conran\'s Blog'],
  75. ['http://feeds.yuiblog.com/YahooUserInterfaceBlog', 'Yahoo! UI Blog'],
  76. ['http://feeds.feedburner.com/jquery/', 'jQuery Blog'],
  77. ['http://sports.yahoo.com/nba/rss.xml', 'NBA News'],
  78. ['http://feeds.dzone.com/dzone/frontpage', 'DZone.com']
  79. ],
  80. show : function(){
  81. if(this.rendered){
  82. this.feedUrl.setValue('');
  83. }
  84. FeedWindow.superclass.show.apply(this, arguments);
  85. },
  86. onFeedAdd: function() {
  87. this.el.mask('Validating Feed...', 'x-mask-loading');
  88. var url = this.feedUrl.getValue();
  89. Ext.Ajax.request({
  90. url: 'feed-proxy.php',
  91. params: {feed: url},
  92. success: this.validateFeed,
  93. failure: this.markInvalid,
  94. scope: this,
  95. feedUrl: url
  96. });
  97. },
  98. markInvalid : function(){
  99. this.feedUrl.markInvalid('The URL specified is not a valid RSS2 feed.');
  100. this.el.unmask();
  101. },
  102. validateFeed : function(response, options){
  103. var dq = Ext.DomQuery;
  104. var url = options.feedUrl;
  105. try{
  106. var xml = response.responseXML;
  107. var channel = xml.getElementsByTagName('channel')[0];
  108. if(channel){
  109. var text = dq.selectValue('title', channel, url);
  110. var description = dq.selectValue('description', channel, 'No description available.');
  111. this.el.unmask();
  112. this.hide();
  113. return this.fireEvent('validfeed', {
  114. url: url,
  115. text: text,
  116. description: description
  117. });
  118. }
  119. }catch(e){
  120. }
  121. this.markInvalid();
  122. }
  123. });