jobgroup.index.1.js 10 KB

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