EXT编程实现人员信息的添加

以下是 模板的代码:
ViewGrid = Ext.extend(Ext.grid.GridPanel,{
insertWin:null,
constructor:function(){Java定时调度 Timer类和TimerTask类
insertWin = new InsertWindowInfo();
ViewGrid.superclass.constructor.call(this,{
title:'GridPanel',
  renderTo:Ext.getBody(),
  width:320,
  height:200,
  tbar:[{
  text:'添加人员',
  handler:function(){
  insertWin.show();
  } JavaScript
  },'-',{
  text:'修改人员'
  },'-',{
  text:'删除人员'
  }],
  colModel:new Ext.grid.ColumnModel([{
  header:'姓名'
  },{
  header:'性别'
  },{
  header:'年龄'
  }]),
  store:new Ext.data.JsonStore({
  autoLoad:true,
  data:[{name:'张翔',sex:'男',age:22},{name:'李慧敏',sex:'女',age:21}],
  fields:['name','sex','age']
    }),
  selModel:new Ext.grid.RowSelectionModel({
  singleSelect:true,
  listeners:{
  'rowselect':{
  fn:function(_sel,_index,_r){
  this.fireEvent('rowselect',_r);
  },
  scope:this
  }
  }
  })
});
this.addEvents('rowselect');
insertWin.on('submit',this.onInsertWinSubmit,this);
},
insertRecord:function(_r){
this.store.add(_r);
},
onInsertWinSubmit:function(_win,_r){
this.insertRecord(_r);
}
});

//---------------------------------------------------------------------------------------------------------
InsertFormInfo = new Ext.extend(Ext.form.FormPanel,{
constructor:function(){
InsertFormInfo.superclass.constructor.call(this,{
defaultType:'textfield',
labelWidth:35,
//baseCls:'x-plain',
defaults:{'anchor':'95%'},
plain:true,
items:[{
fieldLabel:'姓名',
name:'name'
},{
fieldLabel:'年龄',
vtype:'age',
name:'age'
},{
fieldLabel:'性别',
name:'sex',
readonly:true,
xtype:'combo',
displayField:'sex',
mode:'local',
triggerAction:'all',
value:'男',
store:new Ext.data.ArrayStore({
  fields:['sex'],
  data:[['男'],['女']]
  })
}]
});
},
getValues:function(){
if(this.getForm().isValid())
return new Ext.data.Record(this.getForm().getValues());
else
throw Error('没有通过验证');
},
setValues:function(_r){
this.getForm().loadRecord(_c);
},
reset:function(){
this.getForm().reset();
}
});

//-------------------------------------------------------------------------------------------------------------
InsertWindowInfo =Ext.extend(Ext.Window,{
form:null,
constructor:function(){
form = new InsertFormInfo();
InsertWindowInfo.superclass.constructor.call(this,{
width:300,
height:150,
plain:true,
items:form,
buttons:[{
text:'确定',
handler:this.onWindowSubmit,
scope:this
},{
text:'取消'
}]
});
this.addEvents("submit");
},
onWindowSubmit:function(){
try{
this.fireEvent('submit',this,form.getValues());
}catch(error){
return ;
}
this.hide();
},
onWindowCancel:function(){
form.reset();
this.hide();
}
});
posted @ 2011-07-11 10:11  sky7034  阅读(241)  评论(0编辑  收藏  举报
蘑菇街女装 货运专家