3213783b2308f4ab6da8b27a5c6f162fb8c42a65.svn-base 4.1 KB

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