当前位置: 代码迷 >> Web前端 >> Ext项目中使用_用户日志页
  详细解决方案

Ext项目中使用_用户日志页

热度:465   发布时间:2012-10-24 14:15:58.0
Ext项目中应用_用户日志页

function showLogDate(value){
Ext.getCmp('logDateHeard').setTitle('日期:'+value);
}

function changeButton(){
var yearPanels = Ext.getCmp('accordion').items.items;
var expend=false;
            Ext.each(yearPanels , function(yearPanel){            
           
            if(!yearPanel.collapsed){
            expend=true;
            var sublogs = yearPanel.getEl().query("div input[type='checkbox']");
            var falg=false;
            Ext.each(sublogs,function(_sublog){
                       if(_sublog.checked){
                       falg=true;                       
                       }

            });
            if(falg){
            Ext.getCmp('delbont').enable();
            }else{
            Ext.getCmp('delbont').disable();
            }
            }
           
           
            });
            if(!expend){
            Ext.getCmp('delbont').disable();
            }

}
Ext.onReady(function(){
Ext.BLANK_IMAGE_URL = './images/default/s.gif';


//提示按钮自动隐藏
function delayMsg(){
      var txt = Ext.Msg.getDialog().buttons[0].getText();  
var s = 3;  
Ext.TaskMgr.start({  
run:function(){  
if(s<=0){  
Ext.Msg.hide();  
return false;  
}else{  
Ext.Msg.getDialog().buttons[0].setText(txt+'('+s+')');  
s--;  
}  
},  
scope: this,  
interval: 1000 
});  
}


Ext.namespace("com.boco.syslog");
LogItem = com.boco.syslog.LogItem;
LogItem = function(_cfg){
LogItem.superclass.constructor.call(this, _cfg);
};

//继承面板
Ext.extend(LogItem,Ext.Panel,{data:"",id:'',autoScroll:true});

//日志单个项类
    LogsubItem = com.boco.syslog.LogsubItem;
    LogsubItem = function(_cfg){
        Ext.apply(this,_cfg);
}
  Ext.apply(LogsubItem.prototype,{
        text:'',
        url:''
});



//链接模板
var logtpl =new Ext.XTemplate(
                '<form name="pname"><tpl for="."><div id="{text}" class="x-combo-list-item">',
                '<img style="margin:5 0 0 25" src="./images/jt12.gif"/><a href={url} style="text-decoration: none" target="syslog" onclick="showLogDate(this.innerText)">{text}</a><input id={text} name="lognames" value="{text}" type="checkbox" onclick="changeButton()"/>',
                '<div class="x-clear"></div>',
                '</div></tpl><form>');

//日志年项列表
var logItems = new Array();

//日志列表数据
var defaultFeeds;


//每年
var yearItem; 
    var sub1;
   
    //请求后台获得导航栏数据
    var resData;
   
           
           
    //布局
var viewport = new Ext.Viewport({
    layout:'border',
  
    listeners:{    
    beforerender : function(_this){
    Ext.Ajax.request({
    url:"/bfk/basesyslogqueryNavigationAction.action",
    success:function(response,options){
    resData =Ext.util.JSON.decode(response.responseText);
    var accordion = Ext.getCmp('accordion');
    Ext.each(resData,function(_item){
   
defaultFeeds = new Array();
   
    yearItem = new LogItem();
   
yearItem.setTitle(_item.logYear);
yearItem.id=_item.logYear;

yearItem.on('collapse',function(){
changeButton();
});
yearItem.on('expand',function(){
changeButton();
});
    accordion.add(yearItem);
   
   

    //获得子数据
    var files = _item.logfile.split(',');
   
    Ext.each(files, function(_file){
    var f = _file.split('.')[1];
    //创建一个链接
    sub1 = new LogsubItem({url:_file, text:f});
defaultFeeds.push(sub1);

    });
    //强制重绘
    accordion.doLayout();
   
    logtpl.overwrite(yearItem.body, defaultFeeds);
    });
   
    accordion.doLayout();
    }
   
   });   
   
    }
    },
    items:[{
    region: 'north',
        html:'',
       
        height:60,
    baseCls:"x-plain"
    },{
    id:'logDateHeard',
    title:'日期:Today',
    tbar:new Ext.Toolbar({
    items:[{xtype: 'tbseparator'},'修改日志级别:',{
    width:90,
    xtype:'combo',
    triggerAction:'all',
    mode:'local',
    editable:false,
    //value:'1',
    store: new Ext.data.ArrayStore({
    id:0,
    fields:['id','displayText'],
    data:[['DEBUG', 'DEBUG'],['INFO', 'INFO'],['WARN', 'WARN'],['ERROR', 'ERROR'],['FATAL', 'FATAL']]
    }),
    valueField: 'id',
displayField: 'displayText',
currentLevel:'',
listeners:{
beforerender:function(combo){
//从服务器返回

Ext.Ajax.request({
url:'/bfk/basesyslogqueryLogLevelAction.action',

success: function(response , opriton){
combo.setValue(response.responseText);
combo.currentLevel = response.responseText;
}
});


},
select:function(combo, record, index){
//提交到服务器
var newLevel = combo.value;
if(newLevel != combo.currentLevel){
Ext.Ajax.request({
url:'/bfk/basesyslogupdateLogLevelAction.action',
params:{loglevel:newLevel},
success: function(response ,options){
var resText = Ext.util.JSON.decode(response.responseText);
if(resText.success){
Ext.Msg.alert('提示','修改成功');
delayMsg();
}else{
//从服务端返回描述
combo.setValue(combo.currentLevel);
Ext.Msg.alert('错误',resText.msg);
delayMsg();
}
},
failure : function(response,options){
Ext.Msg.alert('错误',"修改失败");
delayMsg();
}
});
}

combo.currentLevel = combo.value;
}
}
    },{xtype: 'tbseparator'},'修改日志文件生成周期:每',{
    xtype:'combo',
    mode:'local',
    editable:false,
    triggerAction:'all',
    width:90,
    store:new Ext.data.ArrayStore({
    fields:['id' , 'displayText'],
    data:[['DD','日'], ['MM','月']]
    }),
    valueField:'id',
    displayField:'displayText',
    currentDP:'',
    listeners:{
    beforerender:function(_combo){
   
    Ext.Ajax.request({
    url:'/bfk/basesyslogqueryLogPeriodicityAction.action',
    success:function(_response, options){
    var res=_response.responseText;
    for(i=0;i<_combo.getStore().getCount();i++){
    var itemId = _combo.getStore().getAt(i).get('id');
    if(res == itemId){
    _combo.setValue(_combo.getStore().getAt(i).get('displayText'));
    this.currentDP = itemId;
    }
    }
    }
    });
    },
    select:function(_combo, _record ,index){
    if(_record.get('id') != this.currentDP){
    Ext.Ajax.request({
url:'/bfk/basesyslogupdateLogPeriodicityAction.action',
params:{logPeriodicity:_record.get('id')},
success: function(response ,options){
var resText = Ext.util.JSON.decode(response.responseText);
if(resText.success){
Ext.Msg.alert('提示','修改成功');
delayMsg();
}else{
//从服务端返回描述
Ext.Msg.alert('错误',resText.msg);
delayMsg();
}
},
failure : function(response,options){
Ext.Msg.alert('错误',"修改失败");
delayMsg();
}
});
    }
    this.currentDP=_record.get('id');
    }
    }
   
    }]
   
    }),
    region: 'center',
    //layout:'fit',
    html:'<iframe id="syslog" src="syslog/SYSLOG" name="syslog" width="100%" height="100%"   frameborder=0></iframe>'
    },{
    title:'系统日志',
    layout:'fit',
    //autoScroll:true,
    region:'west',
    width:250,
    tbar: new Ext.Toolbar({
    id:'logallSelect',
    items:[{xtype: 'tbseparator'},
    new  Ext.form.Checkbox({
    boxLabel:'全选',
    listeners:{
    check:function(logcheckbox , checked){
    //alert(checked);
    var yearPanels = this.ownerCt.ownerCt.get('accordion').items.items;
            Ext.each(yearPanels , function(yearPanel){
            if(!yearPanel.collapsed){
            var sublogs = yearPanel.getEl().query("div input[type='checkbox']");
            Ext.each(sublogs,function(_sublog){
                       _sublog.checked=checked;

            });
            }
            });
            changeButton();
    }
    }
    }),
    {xtype: 'tbseparator'},
    {
    text: '删除',
    id: 'delbont',
            iconCls: 'silk-delete',
            xtype:'button',
            disabled:true,
            handler:function(_botn){
            Ext.MessageBox.confirm('确认', '您确定要删除日志文件?',function(result){
            if(result == 'yes'){
            //获取参数
            var lognames='';
            var yearPanels = Ext.getCmp('accordion').items.items;
            Ext.each(yearPanels , function(yearPanel){
            if(!yearPanel.collapsed){
            var sublogs = yearPanel.getEl().query("div input[type='checkbox']");
            Ext.each(sublogs,function(_sublog){
            if(_sublog.checked){
            lognames += _sublog.value+',';
           
           
            }
            });
            }
            });
            //
            //参数不为空提交
            if(lognames!=''){
            Ext.Ajax.request({
            url:'/bfk/basesyslogdeleteLogAction.action',
            params:{lognames:lognames},
            success: function(response ,options){
var resText = Ext.util.JSON.decode(response.responseText);
if(resText.success){
Ext.Msg.alert('提示',resText.msg);
var logs = lognames.split(',');
Ext.each(logs,function(_log){
Ext.get(logs).remove();
});
delayMsg();
}else{
//从服务端返回描述
Ext.Msg.alert('错误',resText.msg);
delayMsg();
}
},
failure : function(response,options){
Ext.Msg.alert('错误',"删除失败");
delayMsg();
}
});
           
            }
            //
            }
            });
            }
    },
    {xtype: 'tbseparator'},
    {
    //xtype:'calendarpicker'
   
    id:'seach',
    text:'查询',
    iconCls:'icon-seacch-date',
    handler:function(_seachbon){
   
    var p = new Ext.Panel({
   
    x: _seachbon.getEl().getX()+30,
    y:  _seachbon.getEl().getY(),
    renderTo: Ext.getBody(),//x,y,renderTo:Ext.getBody()初始化panel的位置
    floating: true,//true //面板浮动
    frame: true,//圆角边框,背景色
    width: 190,
    height: 215,
    items:[
    new Ext.DatePicker({
    format:"Y-m-d",
    handler:function(_dpker, date){
   
    var d = date.format("Y-m-d");
    if(d == (new Date()).format("Y-m-d")){
    Ext.getCmp('logDateHeard').setTitle('日期:Today');
    Ext.get('syslog').dom.src='/bfk/syslog/SYSLOG';
    //alert();
    _dpker.ownerCt.hide();
    return;
    }
    //匹配日如果没有日再匹配月
    var url='';
    var text='';
    var as = Ext.query("a");
    var c = new String(d);
            Ext.each(as,function(_a){
            if(_a.innerText==d){
            url=_a.href;
            Ext.get('syslog').dom.src=url;
            text = _a.innerText;
            }
            });
   
            if(url==''){
            Ext.each(as,function(_a){
            if(_a.innerText==c.substring(0,c.length-3)){
            url=_a.href;
            Ext.get('syslog').dom.src=url;
            text = c.substring(0,c.length-3);
            }
            });
            }
            if(url!=''){//set title value
            Ext.getCmp('logDateHeard').setTitle('日期:'+text);
            }
    _dpker.ownerCt.hide();
   
    }
    })
    ]
    }).show();
   
    }
   


    }
    ]
    }),
    split:true,
    items:[
new Ext.Panel({
     id:'accordion',
                autoScroll:true,
                margins:'5 0 5 5',
                fill:true,
                split:true,
                layout:'accordion'
            })
],
    collapsible:true
    },{
    title:'<br>',
    region:'south',
    height:0
    }]
});

});
  相关解决方案