提交 | 用户 | 时间
|
722af2
|
1 |
$(function() { |
X |
2 |
|
|
3 |
// init date tables |
|
4 |
var jobGroupTable = $("#jobgroup_list").dataTable({ |
|
5 |
"deferRender": true, |
|
6 |
"processing" : true, |
|
7 |
"serverSide": true, |
|
8 |
"ajax": { |
|
9 |
url: base_url + "/jobgroup/pageList", |
|
10 |
type:"post", |
|
11 |
data : function ( d ) { |
|
12 |
var obj = {}; |
|
13 |
obj.appname = $('#appname').val(); |
|
14 |
obj.title = $('#title').val(); |
|
15 |
obj.start = d.start; |
|
16 |
obj.length = d.length; |
|
17 |
return obj; |
|
18 |
} |
|
19 |
}, |
|
20 |
"searching": false, |
|
21 |
"ordering": false, |
|
22 |
//"scrollX": true, // scroll x,close self-adaption |
|
23 |
"columns": [ |
|
24 |
{ |
|
25 |
"data": 'id', |
|
26 |
"visible" : false |
|
27 |
}, |
|
28 |
{ |
|
29 |
"data": 'appname', |
|
30 |
"visible" : true, |
|
31 |
"width":'30%' |
|
32 |
}, |
|
33 |
{ |
|
34 |
"data": 'title', |
|
35 |
"visible" : true, |
|
36 |
"width":'30%' |
|
37 |
}, |
|
38 |
{ |
|
39 |
"data": 'addressType', |
|
40 |
"width":'10%', |
|
41 |
"visible" : true, |
|
42 |
"render": function ( data, type, row ) { |
|
43 |
if (row.addressType == 0) { |
|
44 |
return I18n.jobgroup_field_addressType_0; |
|
45 |
} else { |
|
46 |
return I18n.jobgroup_field_addressType_1; |
|
47 |
} |
|
48 |
} |
|
49 |
}, |
|
50 |
{ |
|
51 |
"data": 'registryList', |
|
52 |
"width":'15%', |
|
53 |
"visible" : true, |
|
54 |
"render": function ( data, type, row ) { |
|
55 |
return row.registryList |
|
56 |
?'<a class="show_registryList" href="javascript:;" _id="'+ row.id +'" >' |
|
57 |
+ I18n.system_show +' ( ' + row.registryList.length+ ' )</a>' |
|
58 |
:I18n.system_empty; |
|
59 |
} |
|
60 |
}, |
|
61 |
{ |
|
62 |
"data": I18n.system_opt , |
|
63 |
"width":'15%', |
|
64 |
"render": function ( data, type, row ) { |
|
65 |
return function(){ |
|
66 |
// data |
|
67 |
tableData['key'+row.id] = row; |
|
68 |
|
|
69 |
// opt |
|
70 |
var html = '<div class="btn-group">\n' + |
|
71 |
' <button type="button" class="btn btn-primary btn-sm">'+ I18n.system_opt +'</button>\n' + |
|
72 |
' <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">\n' + |
|
73 |
' <span class="caret"></span>\n' + |
|
74 |
' <span class="sr-only">Toggle Dropdown</span>\n' + |
|
75 |
' </button>\n' + |
|
76 |
' <ul class="dropdown-menu" role="menu" _id="'+ row.id +'" >\n' + |
|
77 |
' <li><a href="javascript:void(0);" class="opt_edit" >'+ I18n.system_opt_edit +'</a></li>\n' + |
|
78 |
' <li><a href="javascript:void(0);" class="opt_del" >'+ I18n.system_opt_del +'</a></li>\n' + |
|
79 |
' </ul>\n' + |
|
80 |
' </div>'; |
|
81 |
|
|
82 |
return html; |
|
83 |
}; |
|
84 |
} |
|
85 |
} |
|
86 |
], |
|
87 |
"language" : { |
|
88 |
"sProcessing" : I18n.dataTable_sProcessing , |
|
89 |
"sLengthMenu" : I18n.dataTable_sLengthMenu , |
|
90 |
"sZeroRecords" : I18n.dataTable_sZeroRecords , |
|
91 |
"sInfo" : I18n.dataTable_sInfo , |
|
92 |
"sInfoEmpty" : I18n.dataTable_sInfoEmpty , |
|
93 |
"sInfoFiltered" : I18n.dataTable_sInfoFiltered , |
|
94 |
"sInfoPostFix" : "", |
|
95 |
"sSearch" : I18n.dataTable_sSearch , |
|
96 |
"sUrl" : "", |
|
97 |
"sEmptyTable" : I18n.dataTable_sEmptyTable , |
|
98 |
"sLoadingRecords" : I18n.dataTable_sLoadingRecords , |
|
99 |
"sInfoThousands" : ",", |
|
100 |
"oPaginate" : { |
|
101 |
"sFirst" : I18n.dataTable_sFirst , |
|
102 |
"sPrevious" : I18n.dataTable_sPrevious , |
|
103 |
"sNext" : I18n.dataTable_sNext , |
|
104 |
"sLast" : I18n.dataTable_sLast |
|
105 |
}, |
|
106 |
"oAria" : { |
|
107 |
"sSortAscending" : I18n.dataTable_sSortAscending , |
|
108 |
"sSortDescending" : I18n.dataTable_sSortDescending |
|
109 |
} |
|
110 |
} |
|
111 |
}); |
|
112 |
|
|
113 |
// table data |
|
114 |
var tableData = {}; |
|
115 |
|
|
116 |
// search btn |
|
117 |
$('#searchBtn').on('click', function(){ |
|
118 |
jobGroupTable.fnDraw(); |
|
119 |
}); |
|
120 |
|
|
121 |
// job registryinfo |
|
122 |
$("#jobgroup_list").on('click', '.show_registryList',function() { |
|
123 |
var id = $(this).attr("_id"); |
|
124 |
var row = tableData['key'+id]; |
|
125 |
|
|
126 |
var html = '<div>'; |
|
127 |
if (row.registryList) { |
|
128 |
for (var index in row.registryList) { |
|
129 |
html += (parseInt(index)+1) + '. <span class="badge bg-green" >' + row.registryList[index] + '</span><br>'; |
|
130 |
} |
|
131 |
} |
|
132 |
html += '</div>'; |
|
133 |
|
|
134 |
layer.open({ |
|
135 |
title: I18n.jobinfo_opt_registryinfo , |
|
136 |
btn: [ I18n.system_ok ], |
|
137 |
content: html |
|
138 |
}); |
|
139 |
|
|
140 |
}); |
|
141 |
|
|
142 |
|
|
143 |
// opt_del |
|
144 |
$("#jobgroup_list").on('click', '.opt_del',function() { |
|
145 |
var id = $(this).parents('ul').attr("_id"); |
|
146 |
|
|
147 |
layer.confirm( (I18n.system_ok + I18n.jobgroup_del + '?') , { |
|
148 |
icon: 3, |
|
149 |
title: I18n.system_tips , |
|
150 |
btn: [ I18n.system_ok, I18n.system_cancel ] |
|
151 |
}, function(index){ |
|
152 |
layer.close(index); |
|
153 |
|
|
154 |
$.ajax({ |
|
155 |
type : 'POST', |
|
156 |
url : base_url + '/jobgroup/remove', |
|
157 |
data : {"id":id}, |
|
158 |
dataType : "json", |
|
159 |
success : function(data){ |
|
160 |
if (data.code == 200) { |
|
161 |
layer.open({ |
|
162 |
title: I18n.system_tips , |
|
163 |
btn: [ I18n.system_ok ], |
|
164 |
content: (I18n.jobgroup_del + I18n.system_success), |
|
165 |
icon: '1', |
|
166 |
end: function(layero, index){ |
|
167 |
jobGroupTable.fnDraw(); |
|
168 |
} |
|
169 |
}); |
|
170 |
} else { |
|
171 |
layer.open({ |
|
172 |
title: I18n.system_tips, |
|
173 |
btn: [ I18n.system_ok ], |
|
174 |
content: (data.msg || (I18n.jobgroup_del + I18n.system_fail)), |
|
175 |
icon: '2' |
|
176 |
}); |
|
177 |
} |
|
178 |
}, |
|
179 |
}); |
|
180 |
}); |
|
181 |
}); |
|
182 |
|
|
183 |
|
|
184 |
// jquery.validate “low letters start, limit contants、 letters、numbers and line-through.” |
|
185 |
jQuery.validator.addMethod("myValid01", function(value, element) { |
|
186 |
var length = value.length; |
|
187 |
var valid = /^[a-z][a-zA-Z0-9-]*$/; |
|
188 |
return this.optional(element) || valid.test(value); |
|
189 |
}, I18n.jobgroup_field_appname_limit ); |
|
190 |
|
|
191 |
$('.add').on('click', function(){ |
|
192 |
$('#addModal').modal({backdrop: false, keyboard: false}).modal('show'); |
|
193 |
}); |
|
194 |
var addModalValidate = $("#addModal .form").validate({ |
|
195 |
errorElement : 'span', |
|
196 |
errorClass : 'help-block', |
|
197 |
focusInvalid : true, |
|
198 |
rules : { |
|
199 |
appname : { |
|
200 |
required : true, |
|
201 |
rangelength:[4,64], |
|
202 |
myValid01 : true |
|
203 |
}, |
|
204 |
title : { |
|
205 |
required : true, |
|
206 |
rangelength:[4, 12] |
|
207 |
} |
|
208 |
}, |
|
209 |
messages : { |
|
210 |
appname : { |
|
211 |
required : I18n.system_please_input+"AppName", |
|
212 |
rangelength: I18n.jobgroup_field_appname_length , |
|
213 |
myValid01: I18n.jobgroup_field_appname_limit |
|
214 |
}, |
|
215 |
title : { |
|
216 |
required : I18n.system_please_input + I18n.jobgroup_field_title , |
|
217 |
rangelength: I18n.jobgroup_field_title_length |
|
218 |
} |
|
219 |
}, |
|
220 |
highlight : function(element) { |
|
221 |
$(element).closest('.form-group').addClass('has-error'); |
|
222 |
}, |
|
223 |
success : function(label) { |
|
224 |
label.closest('.form-group').removeClass('has-error'); |
|
225 |
label.remove(); |
|
226 |
}, |
|
227 |
errorPlacement : function(error, element) { |
|
228 |
element.parent('div').append(error); |
|
229 |
}, |
|
230 |
submitHandler : function(form) { |
|
231 |
$.post(base_url + "/jobgroup/save", $("#addModal .form").serialize(), function(data, status) { |
|
232 |
if (data.code == "200") { |
|
233 |
$('#addModal').modal('hide'); |
|
234 |
layer.open({ |
|
235 |
title: I18n.system_tips , |
|
236 |
btn: [ I18n.system_ok ], |
|
237 |
content: I18n.system_add_suc , |
|
238 |
icon: '1', |
|
239 |
end: function(layero, index){ |
|
240 |
jobGroupTable.fnDraw(); |
|
241 |
} |
|
242 |
}); |
|
243 |
} else { |
|
244 |
layer.open({ |
|
245 |
title: I18n.system_tips, |
|
246 |
btn: [ I18n.system_ok ], |
|
247 |
content: (data.msg || I18n.system_add_fail ), |
|
248 |
icon: '2' |
|
249 |
}); |
|
250 |
} |
|
251 |
}); |
|
252 |
} |
|
253 |
}); |
|
254 |
$("#addModal").on('hide.bs.modal', function () { |
|
255 |
$("#addModal .form")[0].reset(); |
|
256 |
addModalValidate.resetForm(); |
|
257 |
$("#addModal .form .form-group").removeClass("has-error"); |
|
258 |
}); |
|
259 |
|
|
260 |
// addressType change |
|
261 |
$("#addModal input[name=addressType], #updateModal input[name=addressType]").click(function(){ |
|
262 |
var addressType = $(this).val(); |
|
263 |
var $addressList = $(this).parents("form").find("textarea[name=addressList]"); |
|
264 |
if (addressType == 0) { |
|
265 |
$addressList.css("background-color", "#eee"); // 自动注册 |
|
266 |
$addressList.attr("readonly","readonly"); |
|
267 |
$addressList.val(""); |
|
268 |
} else { |
|
269 |
$addressList.css("background-color", "white"); |
|
270 |
$addressList.removeAttr("readonly"); |
|
271 |
} |
|
272 |
}); |
|
273 |
|
|
274 |
// opt_edit |
|
275 |
$("#jobgroup_list").on('click', '.opt_edit',function() { |
|
276 |
var id = $(this).parents('ul').attr("_id"); |
|
277 |
var row = tableData['key'+id]; |
|
278 |
|
|
279 |
$("#updateModal .form input[name='id']").val( row.id ); |
|
280 |
$("#updateModal .form input[name='appname']").val( row.appname ); |
|
281 |
$("#updateModal .form input[name='title']").val( row.title ); |
|
282 |
|
|
283 |
// 注册方式 |
|
284 |
$("#updateModal .form input[name='addressType']").removeAttr('checked'); |
|
285 |
$("#updateModal .form input[name='addressType'][value='"+ row.addressType +"']").click(); |
|
286 |
// 机器地址 |
|
287 |
$("#updateModal .form textarea[name='addressList']").val( row.addressList ); |
|
288 |
|
|
289 |
$('#updateModal').modal({backdrop: false, keyboard: false}).modal('show'); |
|
290 |
}); |
|
291 |
var updateModalValidate = $("#updateModal .form").validate({ |
|
292 |
errorElement : 'span', |
|
293 |
errorClass : 'help-block', |
|
294 |
focusInvalid : true, |
|
295 |
rules : { |
|
296 |
appname : { |
|
297 |
required : true, |
|
298 |
rangelength:[4,64], |
|
299 |
myValid01 : true |
|
300 |
}, |
|
301 |
title : { |
|
302 |
required : true, |
|
303 |
rangelength:[4, 12] |
|
304 |
} |
|
305 |
}, |
|
306 |
messages : { |
|
307 |
appname : { |
|
308 |
required : I18n.system_please_input+"AppName", |
|
309 |
rangelength: I18n.jobgroup_field_appname_length , |
|
310 |
myValid01: I18n.jobgroup_field_appname_limit |
|
311 |
}, |
|
312 |
title : { |
|
313 |
required : I18n.system_please_input + I18n.jobgroup_field_title , |
|
314 |
rangelength: I18n.jobgroup_field_title_length |
|
315 |
} |
|
316 |
}, |
|
317 |
highlight : function(element) { |
|
318 |
$(element).closest('.form-group').addClass('has-error'); |
|
319 |
}, |
|
320 |
success : function(label) { |
|
321 |
label.closest('.form-group').removeClass('has-error'); |
|
322 |
label.remove(); |
|
323 |
}, |
|
324 |
errorPlacement : function(error, element) { |
|
325 |
element.parent('div').append(error); |
|
326 |
}, |
|
327 |
submitHandler : function(form) { |
|
328 |
$.post(base_url + "/jobgroup/update", $("#updateModal .form").serialize(), function(data, status) { |
|
329 |
if (data.code == "200") { |
|
330 |
$('#updateModal').modal('hide'); |
|
331 |
|
|
332 |
layer.open({ |
|
333 |
title: I18n.system_tips , |
|
334 |
btn: [ I18n.system_ok ], |
|
335 |
content: I18n.system_update_suc , |
|
336 |
icon: '1', |
|
337 |
end: function(layero, index){ |
|
338 |
jobGroupTable.fnDraw(); |
|
339 |
} |
|
340 |
}); |
|
341 |
} else { |
|
342 |
layer.open({ |
|
343 |
title: I18n.system_tips, |
|
344 |
btn: [ I18n.system_ok ], |
|
345 |
content: (data.msg || I18n.system_update_fail ), |
|
346 |
icon: '2' |
|
347 |
}); |
|
348 |
} |
|
349 |
}); |
|
350 |
} |
|
351 |
}); |
|
352 |
$("#updateModal").on('hide.bs.modal', function () { |
|
353 |
$("#updateModal .form")[0].reset(); |
|
354 |
addModalValidate.resetForm(); |
|
355 |
$("#updateModal .form .form-group").removeClass("has-error"); |
|
356 |
}); |
|
357 |
|
|
358 |
|
|
359 |
}); |