Commit d11520c9 by naan1993

添加角色页面增加表单验证

parent 5868c0b1
@layout("/common/_container.html"){ @layout("/common/_container.html"){
<div class="ibox float-e-margins"> <div class="ibox float-e-margins">
<div class="ibox-content"> <div class="ibox-content">
<div class="form-horizontal"> <div class="form-horizontal" id="validateForm">
<input type="hidden" id="id" value=""> <input type="hidden" id="id" value="">
......
...@@ -2,17 +2,40 @@ ...@@ -2,17 +2,40 @@
* 角色详情对话框(可用于添加和修改对话框) * 角色详情对话框(可用于添加和修改对话框)
*/ */
var RolInfoDlg = { var RolInfoDlg = {
roleInfoData : {}, roleInfoData: {},
deptZtree : null, deptZtree: null,
pNameZtree : null pNameZtree: null,
validateFields: {
name: {
validators: {
notEmpty: {
message: '用户名不能为空'
}
}
},
tips: {
validators: {
notEmpty: {
message: '别名不能为空'
}
}
},
pName: {
validators: {
notEmpty: {
message: '父级名称不能为空'
}
}
}
}
}; };
/** /**
* 清除数据 * 清除数据
*/ */
RolInfoDlg.clearData = function() { RolInfoDlg.clearData = function () {
this.roleInfoData = {}; this.roleInfoData = {};
} };
/** /**
* 设置对话框中的数据 * 设置对话框中的数据
...@@ -20,10 +43,10 @@ RolInfoDlg.clearData = function() { ...@@ -20,10 +43,10 @@ RolInfoDlg.clearData = function() {
* @param key 数据的名称 * @param key 数据的名称
* @param val 数据的具体值 * @param val 数据的具体值
*/ */
RolInfoDlg.set = function(key, val) { RolInfoDlg.set = function (key, val) {
this.roleInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value; this.roleInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
return this; return this;
} };
/** /**
* 设置对话框中的数据 * 设置对话框中的数据
...@@ -31,16 +54,16 @@ RolInfoDlg.set = function(key, val) { ...@@ -31,16 +54,16 @@ RolInfoDlg.set = function(key, val) {
* @param key 数据的名称 * @param key 数据的名称
* @param val 数据的具体值 * @param val 数据的具体值
*/ */
RolInfoDlg.get = function(key) { RolInfoDlg.get = function (key) {
return $("#" + key).val(); return $("#" + key).val();
} };
/** /**
* 关闭此对话框 * 关闭此对话框
*/ */
RolInfoDlg.close = function() { RolInfoDlg.close = function () {
parent.layer.close(window.parent.Role.layerIndex); parent.layer.close(window.parent.Role.layerIndex);
} };
/** /**
* 点击部门input框时 * 点击部门input框时
...@@ -50,10 +73,10 @@ RolInfoDlg.close = function() { ...@@ -50,10 +73,10 @@ RolInfoDlg.close = function() {
* @param treeNode * @param treeNode
* @returns * @returns
*/ */
RolInfoDlg.onClickDept = function(e, treeId, treeNode) { RolInfoDlg.onClickDept = function (e, treeId, treeNode) {
$("#deptName").attr("value", RolInfoDlg.deptZtree.getSelectedVal()); $("#deptName").attr("value", RolInfoDlg.deptZtree.getSelectedVal());
$("#deptid").attr("value", treeNode.id); $("#deptid").attr("value", treeNode.id);
} };
/** /**
* 点击父级菜单input框时 * 点击父级菜单input框时
...@@ -63,77 +86,91 @@ RolInfoDlg.onClickDept = function(e, treeId, treeNode) { ...@@ -63,77 +86,91 @@ RolInfoDlg.onClickDept = function(e, treeId, treeNode) {
* @param treeNode * @param treeNode
* @returns * @returns
*/ */
RolInfoDlg.onClickPName = function(e, treeId, treeNode) { RolInfoDlg.onClickPName = function (e, treeId, treeNode) {
$("#pName").attr("value", RolInfoDlg.pNameZtree.getSelectedVal()); $("#pName").attr("value", RolInfoDlg.pNameZtree.getSelectedVal());
$("#pid").attr("value", treeNode.id); $("#pid").attr("value", treeNode.id);
} };
/** /**
* 显示部门选择的树 * 显示部门选择的树
* *
* @returns * @returns
*/ */
RolInfoDlg.showDeptSelectTree = function() { RolInfoDlg.showDeptSelectTree = function () {
Feng.showInputTree("deptName","deptContent"); Feng.showInputTree("deptName", "deptContent");
} };
/** /**
* 显示父级菜单的树 * 显示父级菜单的树
* *
* @returns * @returns
*/ */
RolInfoDlg.showPNameSelectTree = function() { RolInfoDlg.showPNameSelectTree = function () {
Feng.showInputTree("pName","pNameContent"); Feng.showInputTree("pName", "pNameContent");
} };
/** /**
* 收集数据 * 收集数据
*/ */
RolInfoDlg.collectData = function() { RolInfoDlg.collectData = function () {
this.set('id').set('name').set('pid').set('deptid').set('tips').set('num'); this.set('id').set('name').set('pid').set('deptid').set('tips').set('num');
} };
/**
* 验证数据是否为空
*/
RolInfoDlg.validate = function () {
$('#validateForm').data("bootstrapValidator").resetForm();
$('#validateForm').bootstrapValidator('validate');
return $("#validateForm").data('bootstrapValidator').isValid();
};
/** /**
* 提交添加用户 * 提交添加用户
*/ */
RolInfoDlg.addSubmit = function() { RolInfoDlg.addSubmit = function () {
this.clearData(); this.clearData();
this.collectData(); this.collectData();
if (!this.validate()) {
return;
}
//提交信息 //提交信息
var ajax = new $ax(Feng.ctxPath + "/role/add", function(data){ var ajax = new $ax(Feng.ctxPath + "/role/add", function (data) {
Feng.success("添加成功!"); Feng.success("添加成功!");
window.parent.Role.table.refresh(); window.parent.Role.table.refresh();
RolInfoDlg.close(); RolInfoDlg.close();
},function(data){ }, function (data) {
Feng.error("添加失败!" + data.responseJSON.message + "!"); Feng.error("添加失败!" + data.responseJSON.message + "!");
}); });
ajax.set(this.roleInfoData); ajax.set(this.roleInfoData);
ajax.start(); ajax.start();
} };
/** /**
* 提交修改 * 提交修改
*/ */
RolInfoDlg.editSubmit = function() { RolInfoDlg.editSubmit = function () {
this.clearData(); this.clearData();
this.collectData(); this.collectData();
//提交信息 //提交信息
var ajax = new $ax(Feng.ctxPath + "/role/edit", function(data){ var ajax = new $ax(Feng.ctxPath + "/role/edit", function (data) {
Feng.success("修改成功!"); Feng.success("修改成功!");
window.parent.Role.table.refresh(); window.parent.Role.table.refresh();
RolInfoDlg.close(); RolInfoDlg.close();
},function(data){ }, function (data) {
Feng.error("修改失败!" + data.responseJSON.message + "!"); Feng.error("修改失败!" + data.responseJSON.message + "!");
}); });
ajax.set(this.roleInfoData); ajax.set(this.roleInfoData);
ajax.start(); ajax.start();
} };
$(function () {
Feng.initValidator("validateForm", RolInfoDlg.validateFields);
$(function() {
var deptTree = new $ZTree("deptTree", "/dept/tree"); var deptTree = new $ZTree("deptTree", "/dept/tree");
deptTree.bindOnClick(RolInfoDlg.onClickDept); deptTree.bindOnClick(RolInfoDlg.onClickDept);
deptTree.init(); deptTree.init();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment