
var teacherInfoStore;

TeacherInfoManager = function(node){

	//分页每页显示数量	 
	var pageSize = 10;
	//指定列参数
	var fields = ["teacherID","teacherName","teacherSex","postName",
	      "PID","teacherPassword"];
	
	teacherInfoStore = new Ext.data.Store({
		 
		 proxy:new Ext.data.HttpProxy({
                url:"DATA/TeacherInfo/TeacherInfo.aspx?cmd=getAllData",
                method:"POST"
           }),
           reader:new Ext.data.JsonReader({
				fields:fields,
                root:"data",
                id:"teacherID",
                totalProperty:"totalCount"
           })
	});
	//加载时参数
	teacherInfoStore.load({params:{start:0,limit:pageSize}}); 
    
	
	//--------------------------------------------------列选择模式
	var sm = new Ext.grid.CheckboxSelectionModel({
		dataIndex:"teacherID"
	});
	
	//--------------------------------------------------列头
	var cm = new Ext.grid.ColumnModel([
		sm,{
		header:"教师编号",
		dataIndex:"teacherID",
		tooltip:"教师唯一标识",
		//可以进行排序
        sortable:true
	},{
		header:"教师姓名",
		tooltip:"教师姓名",
		dataIndex:"teacherName",
        sortable:true,
        renderer:function(value)
        {
            return "<font color=#EE9572>"+value+"</font>";
        }
	},{
		header:"性别",
		width:80,
		tooltip:"性别",
		dataIndex:"teacherSex",
        sortable:true
	},{
		header:"职称",
		width:220,
		tooltip:"职称",
		dataIndex:"postName",
		//可以进行排序
        sortable:true
	},{
		header:"身份证号",
		tooltip:"教师身份证号",
		width:130,
		dataIndex:"PID",
        sortable:true,
        renderer:function(value)
        {
            return "<b>"+value+"</b>";
        }
	},{
		header:"密码",
		width:220,
		tooltip:"密码",
		dataIndex:"teacherPassword",
		//可以进行排序
        sortable:true
	}]);
	
   
    //----------------------------------------------------定义grid
	var teacherInfogrid = new Ext.grid.GridPanel({
	    id:"teacherInfogrid",
		store:teacherInfoStore,
		sm:sm,
		cm:cm,
		loadMask:true,
		//超过长度带自动滚动条
		autoScroll:true,
		border:false,
		viewConfig:{
			forceFit:true
		},
		//分页
		bbar:new Ext.PagingToolbar({
			store:teacherInfoStore,
			pageSize:pageSize
		
		}),
		tbar:[
		new Ext.Toolbar.Fill(),{
			text:"添加",
			//默认样式为按下
			//pressed:true,
			tooltip:"添加",
			iconCls:"addicon",
			handler:AddTeacherInfoFn
		}
		,"","-","",{
			text:"编辑",
			tooltip:"编辑",
			iconCls:"editicon",
			handler: EditTeacherInfoFn
		},"","-","",{
			text:"删除",
			tooltip:"删除",
			iconCls:"deleteicon",
			handler: DelTeacherInfoFn
		},"-"],listeners:{
            'contextmenu':function(e)
            {
                e.stopEvent();
            }
		}
	});
	
	//传入icon样式
	GridMain(node,teacherInfogrid,"guesticon");
}

//内容为Grid
GridMain=function(node,grid,icon){
    var center = Ext.getCmp("centerPanel");
    var tab = center.getItem(node.id);
    if(!tab){
	    tab = center.add({
	        id:node.id,
	        iconCls:icon,
	        xtype:"panel",
	        title:node.text,
	        closable:true,
	        layout:"fit",
	        items:[grid]
        });
	}
    center.setActiveTab(tab);
}

function EditTeacherInfoFn () {
    var row=Ext.getCmp("teacherInfogrid").getSelectionModel().getSelections();
    if(row.length==0) {
        Ext.Msg.alert("提示信息","您没有选中任何行!");
    } else if (row.length>1) {  
        Ext.Msg.alert("提示信息","对不起只能选择一个!");
    } else if (row.length==1) {
        EditTeacherInfo(row[0]);//传行一行记录直接加载
    } 
    
}

function AddTeacherInfoFn () {
        AddTeacherInfo();
}

function DelTeacherInfoFn() {
    var row=Ext.getCmp("teacherInfogrid").getSelectionModel().getSelections();
    if(row.length==0) {
        Ext.Msg.alert("提示信息","请您至少选择一个!");
    } else {  
            Ext.Msg.confirm("提示!","您确定要删除该客人信息吗?",function(btn){ 
            if (btn=="yes") {
               DelTeacherInfo(row);
            }
        })
    }  

}
