随笔-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 紫蝶∏飛揚↗ 阅读(1256) 评论(0)  编辑  收藏 所属分类: EXTJS

只有注册用户登录后才能发表评论。


网站导航: