add.html
4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<div class="page-head">
<div class="page-title">
<h1>Add</h1>
</div>
</div>
<ul class="page-breadcrumb breadcrumb">
<li><a href="/pages/home.html" data-pjax>Home page</a> <i class="fa fa-circle"></i></li>
<li><span class="active">Authorization management</span> <i class="fa fa-circle"></i></li>
<li><a href="list.html" data-pjax>Dictionary</a> <i class="fa fa-circle"></i></li>
<li><span class="active">Add</span></li>
</ul>
<div class="portlet light bordered">
<div class="portlet-title">
<div class="caption">
<i class="icon-equalizer font-red-sunglo"></i> <span
class="caption-subject font-red-sunglo bold uppercase">表单</span>
</div>
</div>
<div class="portlet-body form">
<form action="/resource" class="form-horizontal" id="dict_add_form" >
<div class="alert alert-danger display-hide">
<button class="close" data-close="alert"></button>
Your input is incorrect, please check the input items below
</div>
<div class="form-body">
<div class="form-group">
<label class="col-md-3 control-label">Group</label>
<div class="col-md-4">
<select name="dGroup" class="form-control" id="dGroupSelect"></select>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Text</label>
<div class="col-md-4">
<input type="text" class="form-control" name="dName" id="dNameInput">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Code</label>
<div class="col-md-4">
<input type="text" class="form-control" name="dCode" id="dCodeInput" >
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">说明</label>
<div class="col-md-4">
<textarea class="form-control" rows="3" name="descriptions"></textarea>
</div>
</div>
</div>
<div class="form-actions">
<div class="row">
<div class="col-md-offset-3 col-md-4">
<button type="submit" class="btn green" ><i class="fa fa-check"></i> Submit</button>
<a type="button" class="btn default" href="list.html" data-pjax><i class="fa fa-times"></i> Cancel</a>
</div>
</div>
</div>
</form>
<!-- END FORM-->
</div>
</div>
<script>
$(function(){
$get('/dictionary/all', {dGroup_eq: 0}, function(array){
var options = '<option value="0">新建分组</option>';
$.each(array, function(i,d){
options += '<option value="'+d.dCode+'">'+( d.dName + ' -' + d.dCode)+'</option>';
});
$('#dGroupSelect').html(options)
.on('change', setPinYin);
});
//输入名称,自动生成代码
$('#dNameInput').on('keyup', setPinYin);
function setPinYin(){
var val = $('#dNameInput').val();
if($('#dGroupSelect').val() == 0)
$('#dCodeInput').val(pinyin.getFullChars(val));
else
$('#dCodeInput').val(pinyin.getCamelChars(val));
}
var form = $('#dict_add_form');
var error = $('.alert-danger', form);
//form validate
form.validate({
errorElement : 'span',
errorClass : 'help-block help-block-error',
focusInvalid : false,
rules : {
'dGroup' : {
required : true
},
'dName' : {
required : true
},
'dCode': {
required : true
}
},
invalidHandler : function(event, validator) {
error.show();
App.scrollTo(error, -200);
},
highlight : function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight : function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
success : function(label) {
label.closest('.form-group').removeClass('has-error');
},
submitHandler : function(f) {
var params = form.serializeJSON();
error.hide();
//查询代码的顺延号
$get('/dictionary/all', {dCode_eq: params.dCode, dGroup_eq: params.dGroup},function(dicts){
var suff = '', len = dicts.length;
if(len > 0){
alert('Dictionary code ['+ params.dCode +'] is already exists');
}
else{
submit();
}
});
function submit(){
$post('/dictionary', params, function() {
layer.msg('Operation success...');
//刷新页面
loadPage('add.html');
});
}
}
});
});
</script>