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

JavaScript

开发平台:

JavaScript

  1. /*!  * Ext JS Library 3.1.0  * Copyright(c) 2006-2009 Ext JS, LLC  * licensing@extjs.com  * http://www.extjs.com/license  */ MainPanel = function(){
  2.     this.preview = new Ext.Panel({
  3.         id: 'preview',
  4.         region: 'south',
  5.         cls:'preview',
  6.         autoScroll: true,
  7.         listeners: FeedViewer.LinkInterceptor,
  8.         tbar: [{
  9.             id:'tab',
  10.             text: 'View in New Tab',
  11.             iconCls: 'new-tab',
  12.             disabled:true,
  13.             handler : this.openTab,
  14.             scope: this
  15.         },
  16.         '-',
  17.         {
  18.             id:'win',
  19.             text: 'Go to Post',
  20.             iconCls: 'new-win',
  21.             disabled:true,
  22.             scope: this,
  23.             handler : function(){
  24.                 window.open(this.gsm.getSelected().data.link);
  25.             }
  26.         }],
  27.         clear: function(){
  28.             this.body.update('');
  29.             var items = this.topToolbar.items;
  30.             items.get('tab').disable();
  31.             items.get('win').disable();
  32.         }
  33.     });
  34.     this.grid = new FeedGrid(this, {
  35.         tbar:[{
  36.             text:'Open All',
  37.             tooltip: {title:'Open All',text:'Opens all item in tabs'},
  38.             iconCls: 'tabs',
  39.             handler: this.openAll,
  40.             scope:this
  41.         },
  42.         '-',
  43.         {
  44.             split:true,
  45.             text:'Reading Pane',
  46.             tooltip: {title:'Reading Pane',text:'Show, move or hide the Reading Pane'},
  47.             iconCls: 'preview-bottom',
  48.             handler: this.movePreview.createDelegate(this, []),
  49.             menu:{
  50.                 id:'reading-menu',
  51.                 cls:'reading-menu',
  52.                 width:100,
  53.                 items: [{
  54.                     text:'Bottom',
  55.                     checked:true,
  56.                     group:'rp-group',
  57.                     checkHandler:this.movePreview,
  58.                     scope:this,
  59.                     iconCls:'preview-bottom'
  60.                 },{
  61.                     text:'Right',
  62.                     checked:false,
  63.                     group:'rp-group',
  64.                     checkHandler:this.movePreview,
  65.                     scope:this,
  66.                     iconCls:'preview-right'
  67.                 },{
  68.                     text:'Hide',
  69.                     checked:false,
  70.                     group:'rp-group',
  71.                     checkHandler:this.movePreview,
  72.                     scope:this,
  73.                     iconCls:'preview-hide'
  74.                 }]
  75.             }
  76.         },
  77.         '-',
  78.         {
  79.             pressed: true,
  80.             enableToggle:true,
  81.             text:'Summary',
  82.             tooltip: {title:'Post Summary',text:'View a short summary of each item in the list'},
  83.             iconCls: 'summary',
  84.             scope:this,
  85.             toggleHandler: function(btn, pressed){
  86.                 this.grid.togglePreview(pressed);
  87.             }
  88.         }]
  89.     });
  90.     MainPanel.superclass.constructor.call(this, {
  91.         id:'main-tabs',
  92.         activeTab:0,
  93.         region:'center',
  94.         margins:'0 5 5 0',
  95.         resizeTabs:true,
  96.         tabWidth:150,
  97.         minTabWidth: 120,
  98.         enableTabScroll: true,
  99.         plugins: new Ext.ux.TabCloseMenu(),
  100.         items: {
  101.             id:'main-view',
  102.             layout:'border',
  103.             title:'Loading...',
  104.             hideMode:'offsets',
  105.             items:[
  106.                 this.grid, {
  107.                 id:'bottom-preview',
  108.                 layout:'fit',
  109.                 items:this.preview,
  110.                 height: 250,
  111.                 split: true,
  112.                 border:false,
  113.                 region:'south'
  114.             }, {
  115.                 id:'right-preview',
  116.                 layout:'fit',
  117.                 border:false,
  118.                 region:'east',
  119.                 width:350,
  120.                 split: true,
  121.                 hidden:true
  122.             }]
  123.         }
  124.     });
  125.     this.gsm = this.grid.getSelectionModel();
  126.     this.gsm.on('rowselect', function(sm, index, record){
  127.         FeedViewer.getTemplate().overwrite(this.preview.body, record.data);
  128.         var items = this.preview.topToolbar.items;
  129.         items.get('tab').enable();
  130.         items.get('win').enable();
  131.     }, this, {buffer:250});
  132.     this.grid.store.on('beforeload', this.preview.clear, this.preview);
  133.     this.grid.store.on('load', this.gsm.selectFirstRow, this.gsm);
  134.     this.grid.on('rowdblclick', this.openTab, this);
  135. };
  136. Ext.extend(MainPanel, Ext.TabPanel, {
  137.     loadFeed : function(feed){
  138.         this.grid.loadFeed(feed.url);
  139.         Ext.getCmp('main-view').setTitle(feed.text);
  140.     },
  141.     movePreview : function(m, pressed){
  142.         if(!m){ // cycle if not a menu item click
  143.             var items = Ext.menu.MenuMgr.get('reading-menu').items.items;
  144.             var b = items[0], r = items[1], h = items[2];
  145.             if(b.checked){
  146.                 r.setChecked(true);
  147.             }else if(r.checked){
  148.                 h.setChecked(true);
  149.             }else if(h.checked){
  150.                 b.setChecked(true);
  151.             }
  152.             return;
  153.         }
  154.         if(pressed){
  155.             var preview = this.preview;
  156.             var right = Ext.getCmp('right-preview');
  157.             var bot = Ext.getCmp('bottom-preview');
  158.             var btn = this.grid.getTopToolbar().items.get(2);
  159.             switch(m.text){
  160.                 case 'Bottom':
  161.                     right.hide();
  162.                     bot.add(preview);
  163.                     bot.show();
  164.                     bot.ownerCt.doLayout();
  165.                     btn.setIconClass('preview-bottom');
  166.                     break;
  167.                 case 'Right':
  168.                     bot.hide();
  169.                     right.add(preview);
  170.                     right.show();
  171.                     right.ownerCt.doLayout();
  172.                     btn.setIconClass('preview-right');
  173.                     break;
  174.                 case 'Hide':
  175.                     preview.ownerCt.hide();
  176.                     preview.ownerCt.ownerCt.doLayout();
  177.                     btn.setIconClass('preview-hide');
  178.                     break;
  179.             }
  180.         }
  181.     },
  182.     openTab : function(record){
  183.         record = (record && record.data) ? record : this.gsm.getSelected();
  184.         var d = record.data;
  185.         var id = !d.link ? Ext.id() : d.link.replace(/[^A-Z0-9-_]/gi, '');
  186.         var tab;
  187.         if(!(tab = this.getItem(id))){
  188.             tab = new Ext.Panel({
  189.                 id: id,
  190.                 cls:'preview single-preview',
  191.                 title: d.title,
  192.                 tabTip: d.title,
  193.                 html: FeedViewer.getTemplate().apply(d),
  194.                 closable:true,
  195.                 listeners: FeedViewer.LinkInterceptor,
  196.                 autoScroll:true,
  197.                 border:true,
  198.                 tbar: [{
  199.                     text: 'Go to Post',
  200.                     iconCls: 'new-win',
  201.                     handler : function(){
  202.                         window.open(d.link);
  203.                     }
  204.                 }]
  205.             });
  206.             this.add(tab);
  207.         }
  208.         this.setActiveTab(tab);
  209.     },
  210.     openAll : function(){
  211.         this.beginUpdate();
  212.         this.grid.store.data.each(this.openTab, this);
  213.         this.endUpdate();
  214.     }
  215. });
  216. Ext.reg('appmainpanel', MainPanel);