1. 程式人生 > >彈出的程式碼樣例

彈出的程式碼樣例

/**
 * 編輯使用者
 */
mortgage.userManager.edit = function(dataStore,record,roleList) {

 var multiSelect = new Ext.form.MultiSelect({
  width: 140,
  fieldLabel : '下轄行所',
        editable: false,
        hidden : record.get('role') == "sales support"?false:true,
        id : 'befBranch1',
        store:  new Ext.data.JsonStore({
      fields : [ 'branchId', 'branchId', 'isCheck'],
      root:'userList',
      

url:getContextPath()+'/selectBranch.htm?befBranch=' + record.get('befBranch'),
      autoLoad:true
     }),
//     value : record.get('befBranch'),
     checkField : 'isCheck',
//        valueField: 'branchId',
        displayField: 'branchId',
        mode: 'local',
        triggerAction: 'all',
        allowBlank: false,
        hiddenName : 'befBranch',
        emptyText: '請選擇',
        id : 'befBranch1',
        maxHeight:200 //下拉框的最大高度  
 });
 
 /**
  * 編輯使用者基本資訊
  */
 var editForm = new Ext.FormPanel({
  
  url : getContextPath()+'/userManagerUpdate.htm',
  frame : true,
  layout : 'column',
  items : [{
     columnWidth : .5,
     
     layout : 'form',
     items : [
       {
        xtype : 'textfield',
        fieldLabel : '員工號',
        name : 'staffId',
        id : 'staffId',
        width : 140,
        value : record.get('staffId'),
        readOnly : false
       },       
       {        
        xtype : 'combo',
        fieldLabel : '行所',
        store : new Ext.data.JsonStore({
         
url:getContextPath()+'/selectBranch.htm'
,
            root:'userList',
            fields:['branchId','branchId'] ,
            autoLoad:true
        }),
        forceSelection : true,
        width : 140,
        emptyText : '請選擇',
        valueField : "branchId",
        displayField : "branchId",
        mode : 'remote',
        name : 'branch',
        value : record.get('branch'),
        hiddenName : 'branch',
        triggerAction : 'all'
      },
                  {
        xtype : 'textfield',
        fieldLabel : '手機',
        name : 'mobile',
        id : 'mobile',
        width : 140,
        hidden : false,
        value:record.get('mobile')
        
       },
       {
        xtype : 'combo',
        fieldLabel : '角色',
        store : roleList,
        forceSelection : true,
        width : 140,
        emptyText : '請選擇',
        valueField : "roleId",
        displayField : "roleName",
        mode : 'local',
        id : 'role1',
        name : 'role',
        value :record.get('role') ,
        hiddenName : 'role',
        triggerAction : 'all',
        listeners:{
         select:function(){
          if(this.getValue()=='2'){
           Ext.getCmp('befBranch1').allowBlank = false;
           Ext.getCmp('befBranch1').show();
           editForm.doLayout();
          }else{
           Ext.getCmp('befBranch1').allowBlank = true;
           Ext.getCmp('befBranch1').hide();
           editForm.doLayout();
          }
         }         
        }         
       }

     ]
    },
    {
     columnWidth : .5,
     layout : 'form',
     items : [
       {
        xtype : 'textfield',
        fieldLabel : '姓名',
        name : 'name',
        id : 'name',
        width : 140,
        hidden : false,
        value:record.get('name')
       },
       {
        xtype : 'combo',
        fieldLabel : '部門',
        store : new Ext.data.JsonStore({
         fields : [ 'name', 'value' ],
         baseParams:{typeId:'h'},
         root:'CodeBase',
         url:getContextPath()+'/CodeBase.htm',
         autoLoad:true
        }),
        forceSelection : true,
        width : 140,
        emptyText : '請選擇',
        valueField : 'value',
        displayField : 'name',
        mode : 'remote',
        name : 'dept',
        id:'dept1',
        value:record.get('dept'),
        hiddenName : 'dept',
        triggerAction : 'all'
        
       }, {
        xtype : 'textfield',
        fieldLabel : '座機',
        name : 'ext',
        id : 'ext',
        width : 140,
        hidden : false,
        value:record.get('ext')
       },multiSelect
//       {
//        xtype : 'multiSelect',
//           width: 140,
//        fieldLabel : '下轄行所',
//                    editable: false,
//                    hidden : record.get('role') == "sales support"?false:true,
//                    id : 'befBranch1',
//                    store:  new Ext.data.JsonStore({
//                  fields : [ 'branchId', 'branchId', 'isCheck'],
//                  root:'userList',
//                  url:getContextPath()+'/selectBranch.htm?befBranch=' + record.get('befBranch'),
//                  autoLoad:true
//                 }),
//                 checkField : 'isCheck',
//                    valueField: 'branchId',
//                    displayField: 'branchId',
//                    mode: 'local',
//                    triggerAction: 'all',
//                    allowBlank: false,
//                    hiddenName : 'befBranch',
//                    emptyText: '請選擇',
//                    id : 'befBranch1',
//                    maxHeight:200 //下拉框的最大高度        
//        
//       }

     ]
    }]
 });
 
//    $('#befBranch1').val(record.get('befBranch'));
//    $("input[name='befBranch']").val(record.get('befBranch'));
// alert(Ext.getCmp('befBranch1').getValue());
 /***************************************************************************
  * 定義新 window用來顯示編輯頁面
  **************************************************************************/
 var editWin = new Ext.Window({
  title : '編輯使用者基本資訊',
  width : 550,
  height : 220,
  autoScroll : true,
  bodyStyle : 'padding:5px;',
  buttonAlign : 'center',
  items : editForm,
  buttons : [ {
   text : '確定',
   handler : function() {
    var role = Ext.getCmp('role1').getValue();
    var dept= Ext.getCmp('dept1').getValue();
    if(record.get('role') == role){
     if(role == "sales support"){
      Ext.getCmp('role1').setValue('2');
     }
     if(role == "sales"){
      Ext.getCmp('role1').setValue('1');
     }
     if(role == "RCR admin"){
      Ext.getCmp('role1').setValue('4');
     }
     if(role == "RCR"){
      Ext.getCmp('role1').setValue('3');
     }
     if(role == "admin"){
      Ext.getCmp('role1').setValue('6');
     }
     if(role == "PCO"){
      Ext.getCmp('role1').setValue('5');
     }
    }
     if((record.get('role')==role&&role == "sales support")||role == "2"){
      Ext.getCmp('befBranch1').allowBlank = false; 
     }else{
      Ext.getCmp('befBranch1').allowBlank = true; 
     }
    
    if(record.get('dept') == dept){
     if(dept == "PBM"){
      Ext.getCmp('dept1').setValue('101h');
     }
     if(dept == "CSO"){
      Ext.getCmp('dept1').setValue('102h');
     }
     if(dept == "BDR"){
      Ext.getCmp('dept1').setValue('103h');
     }
     if(dept == "MS"){
      Ext.getCmp('dept1').setValue('104h');
     }     
    }
    
    if(editForm.getForm().isValid()){
    editForm.getForm().submit({
      timeout:60000,
         waitMsg:'正在儲存,請稍後...',
         failure:function(form,action){        
         Ext.Msg.alert("failure","儲存失敗!");
         },
         success:function(form,action){        
          if(!action.result.success){          
           Ext.Msg.alert('提示', '使用者已存在,插入失敗');
          }
                          Ext.Msg.alert('提示', '儲存成功');
       editWin.close();
       dataStore.load({
        params : {
         start : 0,
         limit : myPageSize
        }
       });
 
         }       
   });

    /*Ext.MessageBox.alert("提示", "修改失敗");
    Ext.getCmp('staffId').setDisabled(true);
    Ext.getCmp('branch').setDisabled(true);
    Ext.getCmp('mobile').setDisabled(true);
    Ext.getCmp('role').setDisabled(true);
    Ext.getCmp('name').setDisabled(true);
    Ext.getCmp('dept').setDisabled(true);
    Ext.getCmp('ext').setDisabled(true);
    Ext.getCmp('befBranch').setDisabled(true);*/
    } 
    else {
     Ext.MessageBox.alert('提示', '請輸入必輸項!');
    }
  
   }
  }, {
   text : '取消',
   handler : function() {
    editWin.close();
   }
  } ]
 });
 multiSelect.setValue(record.get('befBranch'));
 
 editWin.show();
 multiSelect.valueField = 'branchId';
};