FeedPanel.js
上传用户:dawnssy
上传日期:2022-08-06
资源大小:9345k
文件大小:5k
源码类别:

JavaScript

开发平台:

JavaScript

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