fix rule js bug

pull/26/head
ibuler 9 years ago
parent 60166ac008
commit 0335bc26ca

@ -41,9 +41,9 @@
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="user" class="col-sm-2 control-label">用户<span class="red-fonts">*</span></label>
<label for="user" class="col-sm-2 control-label">用户</label>
<div class="col-sm-8">
<select name="user" data-placeholder="用户名" class="chosen-select form-control m-b" multiple tabindex="2">
<select name="user" id="user" data-placeholder="用户名" class="chosen-select form-control m-b" multiple tabindex="2">
{% for user in users %}
<option value="{{ user.name }}">{{ user.name }}</option>
{% endfor %}
@ -54,7 +54,7 @@
<div class="form-group">
<label for="usergroup" class="col-sm-2 control-label">用户组</label>
<div class="col-sm-8">
<select name="usergroup" data-placeholder="请选择用户组" class="chosen-select form-control m-b" multiple tabindex="2">
<select name="usergroup" id="usergroup" data-placeholder="请选择用户组" class="chosen-select form-control m-b" multiple tabindex="2">
{% for user_group in user_groups %}
<option value="{{ user_group.name }}">{{ user_group.name }}</option>
{% endfor %}
@ -63,9 +63,9 @@
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="asset" class="col-sm-2 control-label">资产<span class="red-fonts">*</span></label>
<label for="asset" class="col-sm-2 control-label">资产</label>
<div class="col-sm-8">
<select name="asset" data-placeholder="请选择资产" class="chosen-select form-control m-b" multiple tabindex="2">
<select name="asset" id="asset" data-placeholder="请选择资产" class="chosen-select form-control m-b" multiple tabindex="2">
{% for asset in assets %}
<option value="{{ asset.ip }}">{{ asset.ip }}</option>
{% endfor %}
@ -74,7 +74,7 @@
</div>
</div>
<div class="form-group">
<label for="assetgroup" class="col-sm-2 control-label">资产组</label>
<label for="assetgroup" id="assetgroup" class="col-sm-2 control-label">资产组</label>
<div class="col-sm-8">
<select name="assetgroup" data-placeholder="请选择资产组" class="chosen-select form-control m-b" multiple tabindex="2">
{% for asset_group in asset_groups %}
@ -118,37 +118,51 @@
{% endblock %}
{% block self_footer_js %}
<script>
$('#ruleForm').submit(function() {
var result = {};
var data = $(this).serializeArray();
$.each(data, function (i, field) {
result[field.name] = field.value;
});
if (result['user'] || result['usergroup'] || result['asset'] || result['assetgroup'] || result['rulename'] || result['role']) {
if (result['rulename'] === '') {
alert("请添加授权名称");
return false
}
if (!result['user'] && !result['usergroup']) {
alert("用户和用户组必选1个");
return false
$('#ruleForm').validator({
timely: 2,
theme: "yellow_right_effect",
rules: {
check_name: [/^\w{2,20}$/, '大小写字母数字和下划线,2-20位'],
check_user: function(){
return $('#user').val() == null
},
check_asset: function(){
return $('#asset').val() == null
}
if (!result['asset'] && !result['assetgroup']) {
alert("资产和资产组必选1个");
return false
},
fields: {
"rulename": {
rule: "required;check_name",
tip: "输入规则名称",
ok: "",
msg: {required: "规则名称必填"}
},
"usergroup": {
rule: "required(check_user)",
tip: "请选择用户组",
ok: "",
msg: {required: "用户和用户组必选一个!"}
},
"assetgroup": {
rule: "required(check_asset)",
tip: "输入资产组",
ok: "",
msg: {required: "资产和资产组必选一个!"}
},
"role": {
rule: "required",
tip: "请选择角色",
ok: "",
msg: {required: "必须选择角色"}
}
if (!result['role']) {
alert("请填写角色");
return false
},
valid: function(form) {
form.submit();
}
return true
} else {
alert("请填必选项");
return false;
}
});
$(document).ready(function(){
$("input.role").click(function(){
if($("input.role[value=GA]").is( ":checked" )){

Loading…
Cancel
Save