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.

193 lines
5.5 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. FeedPanel = function() {
  16. FeedPanel.superclass.constructor.call(this, {
  17. id:'feed-tree',
  18. region:'west',
  19. title:'Feeds',
  20. split:true,
  21. width: 225,
  22. minSize: 175,
  23. maxSize: 400,
  24. collapsible: true,
  25. margins:'0 0 5 5',
  26. cmargins:'0 5 5 5',
  27. rootVisible:false,
  28. lines:false,
  29. autoScroll:true,
  30. root: new Ext.tree.TreeNode('My Feeds'),
  31. collapseFirst:false,
  32. tbar: [{
  33. iconCls:'add-feed',
  34. text:'Add Feed',
  35. handler: this.showWindow,
  36. scope: this
  37. },{
  38. id:'delete',
  39. iconCls:'delete-icon',
  40. text:'Remove',
  41. handler: function(){
  42. var s = this.getSelectionModel().getSelectedNode();
  43. if(s){
  44. this.removeFeed(s.attributes.url);
  45. }
  46. },
  47. scope: this
  48. }]
  49. });
  50. this.feeds = this.root.appendChild(
  51. new Ext.tree.TreeNode({
  52. text:'My Feeds',
  53. cls:'feeds-node',
  54. expanded:true
  55. })
  56. );
  57. this.getSelectionModel().on({
  58. 'beforeselect' : function(sm, node){
  59. return node.isLeaf();
  60. },
  61. 'selectionchange' : function(sm, node){
  62. if(node){
  63. this.fireEvent('feedselect', node.attributes);
  64. }
  65. this.getTopToolbar().items.get('delete').setDisabled(!node);
  66. },
  67. scope:this
  68. });
  69. this.addEvents({feedselect:true});
  70. this.on('contextmenu', this.onContextMenu, this);
  71. };
  72. Ext.extend(FeedPanel, Ext.tree.TreePanel, {
  73. onContextMenu : function(node, e){
  74. if(!this.menu){ // create context menu on first right click
  75. this.menu = new Ext.menu.Menu({
  76. id:'feeds-ctx',
  77. items: [{
  78. id:'load',
  79. iconCls:'load-icon',
  80. text:'Load Feed',
  81. scope: this,
  82. handler:function(){
  83. this.ctxNode.select();
  84. }
  85. },{
  86. text:'Remove',
  87. iconCls:'delete-icon',
  88. scope: this,
  89. handler:function(){
  90. this.ctxNode.ui.removeClass('x-node-ctx');
  91. this.removeFeed(this.ctxNode.attributes.url);
  92. this.ctxNode = null;
  93. }
  94. },'-',{
  95. iconCls:'add-feed',
  96. text:'Add Feed',
  97. handler: this.showWindow,
  98. scope: this
  99. }]
  100. });
  101. this.menu.on('hide', this.onContextHide, this);
  102. }
  103. if(this.ctxNode){
  104. this.ctxNode.ui.removeClass('x-node-ctx');
  105. this.ctxNode = null;
  106. }
  107. if(node.isLeaf()){
  108. this.ctxNode = node;
  109. this.ctxNode.ui.addClass('x-node-ctx');
  110. this.menu.items.get('load').setDisabled(node.isSelected());
  111. this.menu.showAt(e.getXY());
  112. }
  113. },
  114. onContextHide : function(){
  115. if(this.ctxNode){
  116. this.ctxNode.ui.removeClass('x-node-ctx');
  117. this.ctxNode = null;
  118. }
  119. },
  120. showWindow : function(btn){
  121. if(!this.win){
  122. this.win = new FeedWindow();
  123. this.win.on('validfeed', this.addFeed, this);
  124. }
  125. this.win.show(btn);
  126. },
  127. selectFeed: function(url){
  128. this.getNodeById(url).select();
  129. },
  130. removeFeed: function(url){
  131. var node = this.getNodeById(url);
  132. if(node){
  133. node.unselect();
  134. Ext.fly(node.ui.elNode).ghost('l', {
  135. callback: node.remove, scope: node, duration: .4
  136. });
  137. }
  138. },
  139. addFeed : function(attrs, inactive, preventAnim){
  140. var exists = this.getNodeById(attrs.url);
  141. if(exists){
  142. if(!inactive){
  143. exists.select();
  144. exists.ui.highlight();
  145. }
  146. return;
  147. }
  148. Ext.apply(attrs, {
  149. iconCls: 'feed-icon',
  150. leaf:true,
  151. cls:'feed',
  152. id: attrs.url
  153. });
  154. var node = new Ext.tree.TreeNode(attrs);
  155. this.feeds.appendChild(node);
  156. if(!inactive){
  157. if(!preventAnim){
  158. Ext.fly(node.ui.elNode).slideIn('l', {
  159. callback: node.select, scope: node, duration: .4
  160. });
  161. }else{
  162. node.select();
  163. }
  164. }
  165. return node;
  166. },
  167. // prevent the default context menu when you miss the node
  168. afterRender : function(){
  169. FeedPanel.superclass.afterRender.call(this);
  170. this.el.on('contextmenu', function(e){
  171. e.preventDefault();
  172. });
  173. }
  174. });
  175. Ext.reg('appfeedpanel', FeedPanel);