FeedGrid.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  */ FeedGrid = function(viewer, config) {
  2.     this.viewer = viewer;
  3.     Ext.apply(this, config);
  4.     this.store = new Ext.data.Store({
  5.         proxy: new Ext.data.HttpProxy({
  6.             url: 'feed-proxy.php'
  7.         }),
  8.         reader: new Ext.data.XmlReader(
  9.             {record: 'item'},
  10.             ['title', 'author', {name:'pubDate', type:'date'}, 'link', 'description', 'content']
  11.         )
  12.     });
  13.     this.store.setDefaultSort('pubDate', "DESC");
  14.     this.columns = [{
  15.         id: 'title',
  16.         header: "Title",
  17.         dataIndex: 'title',
  18.         sortable:true,
  19.         width: 420,
  20.         renderer: this.formatTitle
  21.       },{
  22.         header: "Author",
  23.         dataIndex: 'author',
  24.         width: 100,
  25.         hidden: true,
  26.         sortable:true
  27.       },{
  28.         id: 'last',
  29.         header: "Date",
  30.         dataIndex: 'pubDate',
  31.         width: 150,
  32.         renderer:  this.formatDate,
  33.         sortable:true
  34.     }];
  35.     FeedGrid.superclass.constructor.call(this, {
  36.         region: 'center',
  37.         id: 'topic-grid',
  38.         loadMask: {msg:'Loading Feed...'},
  39.         sm: new Ext.grid.RowSelectionModel({
  40.             singleSelect:true
  41.         }),
  42.         viewConfig: {
  43.             forceFit:true,
  44.             enableRowBody:true,
  45.             showPreview:true,
  46.             getRowClass : this.applyRowClass
  47.         }
  48.     });
  49.     this.on('rowcontextmenu', this.onContextClick, this);
  50. };
  51. Ext.extend(FeedGrid, Ext.grid.GridPanel, {
  52.     onContextClick : function(grid, index, e){
  53.         if(!this.menu){ // create context menu on first right click
  54.             this.menu = new Ext.menu.Menu({
  55.                 id:'grid-ctx',
  56.                 items: [{
  57.                     text: 'View in new tab',
  58.                     iconCls: 'new-tab',
  59.                     scope:this,
  60.                     handler: function(){
  61.                         this.viewer.openTab(this.ctxRecord);
  62.                     }
  63.                 },{
  64.                     iconCls: 'new-win',
  65.                     text: 'Go to Post',
  66.                     scope:this,
  67.                     handler: function(){
  68.                         window.open(this.ctxRecord.data.link);
  69.                     }
  70.                 },'-',{
  71.                     iconCls: 'refresh-icon',
  72.                     text:'Refresh',
  73.                     scope:this,
  74.                     handler: function(){
  75.                         this.ctxRow = null;
  76.                         this.store.reload();
  77.                     }
  78.                 }]
  79.             });
  80.             this.menu.on('hide', this.onContextHide, this);
  81.         }
  82.         e.stopEvent();
  83.         if(this.ctxRow){
  84.             Ext.fly(this.ctxRow).removeClass('x-node-ctx');
  85.             this.ctxRow = null;
  86.         }
  87.         this.ctxRow = this.view.getRow(index);
  88.         this.ctxRecord = this.store.getAt(index);
  89.         Ext.fly(this.ctxRow).addClass('x-node-ctx');
  90.         this.menu.showAt(e.getXY());
  91.     },
  92.     onContextHide : function(){
  93.         if(this.ctxRow){
  94.             Ext.fly(this.ctxRow).removeClass('x-node-ctx');
  95.             this.ctxRow = null;
  96.         }
  97.     },
  98.     loadFeed : function(url) {
  99.         this.store.baseParams = {
  100.             feed: url
  101.         };
  102.         this.store.load();
  103.     },
  104.     togglePreview : function(show){
  105.         this.view.showPreview = show;
  106.         this.view.refresh();
  107.     },
  108.     // within this function "this" is actually the GridView
  109.     applyRowClass: function(record, rowIndex, p, ds) {
  110.         if (this.showPreview) {
  111.             var xf = Ext.util.Format;
  112.             p.body = '<p>' + xf.ellipsis(xf.stripTags(record.data.description), 200) + '</p>';
  113.             return 'x-grid3-row-expanded';
  114.         }
  115.         return 'x-grid3-row-collapsed';
  116.     },
  117.     formatDate : function(date) {
  118.         if (!date) {
  119.             return '';
  120.         }
  121.         var now = new Date();
  122.         var d = now.clearTime(true);
  123.         var notime = date.clearTime(true).getTime();
  124.         if (notime == d.getTime()) {
  125.             return 'Today ' + date.dateFormat('g:i a');
  126.         }
  127.         d = d.add('d', -6);
  128.         if (d.getTime() <= notime) {
  129.             return date.dateFormat('D g:i a');
  130.         }
  131.         return date.dateFormat('n/j g:i a');
  132.     },
  133.     formatTitle: function(value, p, record) {
  134.         return String.format(
  135.                 '<div class="topic"><b>{0}</b><span class="author">{1}</span></div>',
  136.                 value, record.data.author, record.id, record.data.forumid
  137.                 );
  138.     }
  139. });
  140. Ext.reg('appfeedgrid', FeedGrid);