﻿ArticleListPanel=function(config){
    Ext.apply(this,config);
    
    this.ds=new Ext.data.Store({
        url:'ArticleList.aspx',
        reader: new Ext.data.JsonReader({
        root: 'rows',
        totalProperty: 'totalCount'
        }, [
            {name:'AR_ID',              type:'int'},
            {name:'AR_TITLE',            type:'string'},
            {name:'AR_DOCDATE',        type:'string'},
            {name:'AR_CHILDCOUNT',        type:'int'},
			{name:'U_ID',           type:'int'},
            {name:'U_NAME',        type:'string'},
            {name:'CA_ID',              type:'int'},
            {name:'AR_AWARD',              type:'string'},
            {name:'AR_AUTHOR',              type:'string'},
            {name:'AR_READCOUNT',              type:'int'},
            {name:'AR_PUBLISH',              type:'string'}
        ]),
        remoteSort: true
    }); 
    this.ds.setDefaultSort('AR_ID', 'desc');
    this.Filter=new Ext.form.TextField({
                fieldLabel: '',
                id:'TextFilter', 
		        size:50,
                name: 'FilterText',
                value: config.searchkey,
                emptyText: '输入要查找的关键字',
                listeners:{
				    specialkey:function(f, e){
                        if(e.getKey() == e.ENTER){
                            this.doQuery();
                        }
                    },
                    scope:this
                }
            }); 
    this.ds.on('beforeload', function() {
                    this.store.baseParams = {
                        filterTxt:this.Filter.getValue(),
                        caid:this.caid,
                        author:this.author
                    };
                },this);  
	
	this.nm = new Ext.grid.RowNumberer();
    this.cm = new Ext.grid.ColumnModel([this.nm,
        {header:"标题",dataIndex: 'AR_TITLE', renderer:this.renderArticle, width: 200,align:'left',sortable: false},
        {header:"作者",dataIndex: 'AR_AUTHOR', width: 60,align:'left',sortable: false},
        {header:"来源",dataIndex: 'AR_PUBLISH', width: 100,align:'left',sortable: false},
        {header:"关注度",dataIndex: 'AR_READCOUNT', width: 60,align:'left',sortable: false},
        {header:"发表时间",dataIndex: 'AR_DOCDATE', renderer:this.renderDate,width: 60, align:'left',sortable: false}
    ]);
    if(this.caid!=23){
        this.cm.setHidden(2, true);
        this.cm.setHidden(3, true);
    }
    ArticleListPanel.superclass.constructor.call(this,{
        //collapsible: false,
        //animCollapse: false,
		//closable:true,
        //width :"100%",
        //height:"100%",
        //iconCls: 'icon-grid',
        store: this.ds,
        cm: this.cm,
        trackMouseOver:true,
        loadMask: {msg:'正在加载数据，请稍侯……'},
        viewConfig: {
            forceFit:true,
            enableRowBody:true,
            getRowClass : function(record, rowIndex, p, ds){
                return 'x-grid3-row-collapsed';
            }
        },
        bbar:new Ext.PagingToolbar({
            pageSize: 25,
            store:this.ds,
            displayInfo: this.author=='',
            displayMsg: '当前显示 {0} - {1}条记录 /共 {2}条记录',
            emptyMsg: "无显示数据",
			items:['-',this.Filter,
            {
                text:'查询',
                tooltip:'搜索符合条件的文章',
                iconCls:'icon-query',
                scope:this, 
                handler:this.doQuery
            }
            ]
        })
    }); 
}

Ext.extend(ArticleListPanel,Ext.grid.GridPanel,{
    doQuery:function(){
        if(this.Filter.getValue()!=''){
			this.ds.load({params:{start:0, limit:25}});
		} 
    },
	renderArticle:function(value, p, record){
	    if(record.data.AR_AWARD!=""&&record.data.AR_AWARD!=null){
	        return String.format("<span onclick=\"openArticle1({0},'{2}','{3}')\"  style=\"cursor:pointer;\" qtip=\"{1}\">{1}</span>",record.data.AR_ID,value,value.replace("'","\'").replace("\"","\\\""),record.data.AR_AWARD);
	    }
	    else{
		    return String.format("<span onclick=\"openArticle({0},'{2}',{3})\"  style=\"cursor:pointer;\" qtip=\"{1}\">{1}</span>",record.data.AR_ID,value,value.replace("'","\'").replace("\"","\\\""),record.data.CA_ID);
		}
	},
	renderDate:function(value){
	    var exp = value.toString().replace(new RegExp('\\/Date\\((-?[0-9]+)\\)\\/', 'g'), "new Date($1)");
		var a=eval(exp);
		return a.getFullYear()+"-"+(a.getMonth()+1)+"-"+a.getDate();
	}
})
