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.

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