Skip to content

Instantly share code, notes, and snippets.

@YeomanYe
Created December 23, 2016 14:33
Show Gist options
  • Save YeomanYe/ffd069ebcdc63376c6acf270c312d68e to your computer and use it in GitHub Desktop.
Save YeomanYe/ffd069ebcdc63376c6acf270c312d68e to your computer and use it in GitHub Desktop.
EasyUI:addDialog
/**
* easyui-addDialog
* @param {string/object} arg 可以是url,也可以是参数设置对象
* @param {string} dialogId 会话框Id
* @param {function} callback 回调函数
*/
function addDialog(arg,dialogId,callback){
/*默认参数设置*/
var option = {
//宽度
width: arg.width ? arg.width : 800,
//高度
height: arg.height ? arg.height : 300,
//有无遮罩层,默认有
modal: arg.unmodal ? false : true,
//ur
url: arg.url ? arg.url : arg,
//弹出框的标题
caption: arg.caption ? arg.caption : "添加",
//弹出框的ID
dialogId: arg.dialogId ? arg.dialogId : dialogId,
//表单的ID
formId: arg.formId ? arg.formId : "addForm",
//取消按钮的文本
cancelBtnText: arg.cancelBtnText ? arg.cancelBtnText : "取消",
//确认按钮的文本
okBtnText: arg.okBtnText ? arg.okBtnText : "保存",
//保存成功后将ID添加到隐藏表单,再次提交则为更行
savedId: arg.savedId ? arg.savedId : "savedId",
//datagrid的ID
datagridId: arg.datagridId ? arg.datagridId : "datagrid",
//确认按钮的图标类
okBtnIconCls: arg.saveBtnIconCls ? arg.saveBtnIconCls : "icon-save",
//取消按钮的图标类
cancelBtnIconCls: arg.cancelBtnIconCls ? arg.cancelBtnIconCls : "icon-cancel",
//保存id的对象名称,默认值保存在id属性中
jsonObjName: arg.jsonObjName ? arg.jsonObjName : null,
//回调函数
callback: arg.callback ? arg.callback : callback,
//标志后端采取更新操作还是添加操作的ID
backEndFlagId: arg.backEndFlagId ? arg.backEndFlagId : "backEndFlagId",
};
$("#"+option.dialogId).dialog({
width:option.width,
height:option.height,
title:option.caption,
modal:option.modal,
closed:true,
/*不能是可关闭的否则输入框的值不会被清空*/
closable:false,
//content:"<div id='seaUsedBTabs' class='easyui-tabs'></div>",
buttons:[{
text:option.okBtnText,
iconCls:option.okBtnIconCls,
handler:function(){
$.ajax({
type: "POST",
url:option.url,
data:$("#"+option.formId).serialize(),
beforeSend:function(){
$.messager.progress({text:"正在保存中..."});
},
success:function(data){
$.messager.progress('close');
if (data.flag=="success") {
//设置保存的ID以便更新
if(option.jsonObjName){
$("#"+option.savedId).val(data[option.jsonObjName].id);
}else{
$("#"+option.savedId).val(data.id);
}
//提示保存成功,并刷新网格
$.messager.alert("提示!","保存成功!","info",function(){
/*刷新数据网格*/
$("#"+option.datagridId).datagrid('reload');
});
//通过设置标志位更改下一次操作为更新
$("#"+option.backEndFlagId).val("update");
if(typeof option.callback === "function"){
option.callback();
}
} else {
$.messager.alert("提示!","未知错误,请重试!","warning");
}
}
});
}
},{
text:option.cancelBtnText,
iconCls:option.cancelBtnIconCls,
handler:function(){
$("#"+option.dialogId).dialog("close");
$("#"+option.formId).form("reset");
$("#"+option.savedId).val("");
$("#"+option.backEndFlagId).val("add");
}
}]
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment