隨筆-9  評論-168  文章-266  trackbacks-0

           

          function author_crud(rs, mode) {// rs:綁定選擇的記錄,可直接操作影響STORE

              
          if (mode == "del"{//單獨判斷del
                  Ext.Msg.confirm("record""是否刪除!", function(btn) {
                              
          if (btn == "yes"{
                                  rs.set(
          "webname""author_del");
                                  Ext.Ajax.request(
          {
                                              params : rs.data,
                                              url : 
          "author_json.faces",
                                              success : function() 
          {
                                                  author_store.remove(rs);
                                                  Ext.Msg.alert(
          "record","success!")
                                                  
          //return;
                                              }
          ,
                                              failure : function() 
          {
                                                  Ext.Msg.alert(
          "record","failure!")
                                              }

                                          }
          );
                              }
           
                          }
          )
              }
           else //聯合判斷add/alter
                  if (mode == "alter"||mode == "add")
                  
          {
                  var win 
          = new Ext.Window({
                      title : 
          "讀者資料",
                      layout : 
          "fit",
                      items : [
          new Ext.FormPanel({
                          
          // id:"author_form",
                          frame : true,
                          labelWidth : 
          60,
                          autoHeight : 
          true,
                          autoWidth : 
          true,
                          waitMsgTarget : 
          true// true:等待狀態信息框顯示在formpanel內(推薦).false:以進度條信息框方式顯示在外.
                          buttons : [{
                              text : 
          "確定",
                              handler : function() 
          {
                                  var f 
          = this.ownerCt;
                                  
          // var record = new Ext.data.Record({});
                                  
          // var t=f.findBy(function(){return
                                  
          // true});//查找所有子組件.函數必須返回true
                                  if (f.getForm().isValid()) {
                                      var webnam;
                                      
          if (mode == "add"{// ***********添加**************
                                          webnam = "author_add";
                                      }
           else if (mode == "alter"{// ********修改*************
                                          webnam = "author_alter";
                                          var t 
          = f.items.items[2].items.items[0]
                                                  .isDirty();
          // radio組件判斷修改
                                          if (f.getForm().isDirty() == false
                                                  
          && t == false{// 沒有組件修改過則直接退出.
                                              f.ownerCt.close();
                                              Ext.Msg.alert(
          "record""No Alter!");
                                              
          return;
                                          }

                                      }

                                      f.getForm().submit(
          {
                                          params : 
          {
                                              webname : webnam
                                          }
          ,
                                          url : 
          "author_json.faces",
                                          waitMsg : 
          '保存中,請稍后',
                                          success : function(re, v) 
          {
                                              var t 
          = rs;
                                              var record 
          = f.getForm().getValues(); // 返回Form提交值,json對象,需在提交后調用.
                                              rs.set("author_num", record.author_num);
                                              rs.set(
          "author_nam", record.author_nam);
                                              rs.set(
          "author_sex", record.author_sex);
                                              rs.set(
          "author_department",
                                                      record.author_department);
                                              rs.set(
          "author_level", record.author_level);
                                              
          if (mode == "add")
                                                  author_store.insert(
          0, rs);
                                              f.ownerCt.close();
                                              Ext.Msg.alert(
          "record""success!");
                                              
          // 重新加載author tab內容.
                                              
          // author_store.load({params:{webname:"findall"}});
                                          }
          ,
                                          failure : function() 
          {
                                              Ext.Msg.alert(
          "record""failure!");
                                          }

                                      }
          )
                                  }

                              }

                          }
          {
                              text : 
          "取消",
                              handler : function() 
          {
                                  win.close();
                              }

                          }
          ],
                          items : [
          new Ext.form.TextField({
                                              fieldLabel : 
          "編號",
                                              name : 
          "author_num",
                                              allowBlank : 
          false,
                                              value : rs.data 
          ? rs.data.author_num : ""
                                          }
          ), new Ext.form.TextField({
                                              fieldLabel : 
          "姓名",
                                              name : 
          "author_nam",
                                              regex : 
          /[\u4e00-\u9fa5]/// 正則表達式
                                              regexText : "只能輸入中文!"// 正則表達式錯誤提示
                                              value : rs.data ? rs.data.author_nam : "",
                                              allowBlank : 
          false
                                          }
          ), new Ext.form.RadioGroup({
                                              fieldLabel : 
          "性別",
                                              items : [
          new Ext.form.Radio({
                                                          boxLabel : 
          "",
                                                          checked : rs.data
                                                                  
          ? rs.data.author_sex == "m"
                                                                          
          ? true
                                                                          : 
          false
                                                                  : 
          false,
                                                          name : 
          "author_sex",
                                                          inputValue : 
          "m"
                                                      }
          ), new Ext.form.Radio({
                                                          checked : rs.data
                                                                  
          ? rs.data.author_sex == "w"
                                                                          
          ? true
                                                                          : 
          false
                                                                  : 
          false,
                                                          boxLabel : 
          "",
                                                          name : 
          "author_sex",
                                                          inputValue : 
          "w"
                                                      }
          )]
                                          }
          ), new Ext.form.ComboBox({
                                      fieldLabel : 
          "部門",
                                      readOnly : 
          true,
                                      name : 
          "author_department",
                                      triggerAction : 
          "all",
                                      store : 
          new Ext.data.SimpleStore({
                                                  fields : [
          "text""value"],
                                                  data : webbook.author.comboBox.department
                                              }
          ),
                                      displayField : 
          "text",
                                      valueField : 
          "value",
                                      value : rs.data 
          ? rs.data.author_department : "",
                                      mode : 
          "local",
                                      allowBlank : 
          false,
                                      emptyText : 
          "請選擇"
                                  }
          ), new Ext.form.ComboBox({
                                              readOnly : 
          true,
                                              name : 
          "author_level",
                                              fieldLabel : 
          "等級",
                                              triggerAction : 
          "all",
                                              displayField : 
          "text",
                                              valueField : 
          "value",
                                              mode : 
          "local",
                                              value : rs.data 
          ? rs.data.author_level : "",
                                              allowBlank : 
          false,
                                              emptyText : 
          "請選擇",
                                              
          // value:"普通會員",
                                              store : new Ext.data.SimpleStore({
                                                          fields : [
          "text""value"],
                                                          
          // states.js 中定義.
                                                          data : webbook.author.comboBox.level
                                                      }
          )
                                          }
          )]
                      }
          )]
                  }
          );
                  win.show(
          "author_add");
              }

          }
          ;
          var author_sm 
          = new Ext.grid.CheckboxSelectionModel();
          var author_cm 
          = new Ext.grid.ColumnModel([author_sm, {
                      header : 
          "編號",
                      dataIndex : 
          "author_num"
                  }
          {
                      header : 
          "姓名",
                      dataIndex : 
          "author_nam"
                  }
          {
                      header : 
          "性別",
                      dataIndex : 
          "author_sex",
                      renderer : function(v) 
          {
                          
          return v == "w" ? "" : ""
                      }

                  }
          {
                      header : 
          "等級",
                      dataIndex : 
          "author_level"
                  }
          {
                      header : 
          "部門",
                      dataIndex : 
          "author_department"
                  }
          ]);
          var author_f 
          = new Ext.data.Record.create(["author_num""author_nam",
                  
          "author_sex""author_level""author_department"]);
          var author_store 
          = new Ext.data.JsonStore({
              fields : author_f,
              url : 
          "author_json.faces",
              root : 
          "author"// ,
                  
          // baseParams:{webnam:"author"}
              }
          );
          posted on 2009-04-10 10:55 紫蝶∏飛揚↗ 閱讀(1269) 評論(0)  編輯  收藏 所屬分類: EXTJS
          主站蜘蛛池模板: 长垣县| 石首市| 临桂县| 荥阳市| 滨海县| 兰州市| 平原县| 米泉市| 阿荣旗| 锡林浩特市| 昂仁县| 牡丹江市| 绍兴市| 巴彦淖尔市| 平陆县| 固安县| 原平市| 曲松县| 类乌齐县| 辰溪县| 鹤壁市| 和龙市| 古交市| 贵阳市| 九台市| 剑川县| 凌源市| 遂宁市| 昌黎县| 定远县| 武宣县| 丰镇市| 潍坊市| 炉霍县| 麦盖提县| 奈曼旗| 山西省| 桦川县| 托克托县| 东阳市| 集安市|