jobgroup.index.1.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. });
  132. // opt_del
  133. $("#jobgroup_list").on('click', '.opt_del',function() {
  134. var id = $(this).parents('ul').attr("_id");
  135. layer.confirm( (I18n.system_ok + I18n.jobgroup_del + '?') , {
  136. icon: 3,
  137. title: I18n.system_tips ,
  138. btn: [ I18n.system_ok, I18n.system_cancel ]
  139. }, function(index){
  140. layer.close(index);
  141. $.ajax({
  142. type : 'POST',
  143. url : base_url + '/jobgroup/remove',
  144. data : {"id":id},
  145. dataType : "json",
  146. success : function(data){
  147. if (data.code == 200) {
  148. layer.open({
  149. title: I18n.system_tips ,
  150. btn: [ I18n.system_ok ],
  151. content: (I18n.jobgroup_del + I18n.system_success),
  152. icon: '1',
  153. end: function(layero, index){
  154. jobGroupTable.fnDraw();
  155. }
  156. });
  157. } else {
  158. layer.open({
  159. title: I18n.system_tips,
  160. btn: [ I18n.system_ok ],
  161. content: (data.msg || (I18n.jobgroup_del + I18n.system_fail)),
  162. icon: '2'
  163. });
  164. }
  165. },
  166. });
  167. });
  168. });
  169. // jquery.validate “low letters start, limit contants、 letters、numbers and line-through.”
  170. jQuery.validator.addMethod("myValid01", function(value, element) {
  171. var length = value.length;
  172. var valid = /^[a-z][a-zA-Z0-9-]*$/;
  173. return this.optional(element) || valid.test(value);
  174. }, I18n.jobgroup_field_appName_limit );
  175. $('.add').on('click', function(){
  176. $('#addModal').modal({backdrop: false, keyboard: false}).modal('show');
  177. });
  178. var addModalValidate = $("#addModal .form").validate({
  179. errorElement : 'span',
  180. errorClass : 'help-block',
  181. focusInvalid : true,
  182. rules : {
  183. appName : {
  184. required : true,
  185. rangelength:[4,64],
  186. myValid01 : true
  187. },
  188. title : {
  189. required : true,
  190. rangelength:[4, 12]
  191. }
  192. },
  193. messages : {
  194. appName : {
  195. required : I18n.system_please_input+"AppName",
  196. rangelength: I18n.jobgroup_field_appName_length ,
  197. myValid01: I18n.jobgroup_field_appName_limit
  198. },
  199. title : {
  200. required : I18n.system_please_input + I18n.jobgroup_field_title ,
  201. rangelength: I18n.jobgroup_field_title_length
  202. }
  203. },
  204. highlight : function(element) {
  205. $(element).closest('.form-group').addClass('has-error');
  206. },
  207. success : function(label) {
  208. label.closest('.form-group').removeClass('has-error');
  209. label.remove();
  210. },
  211. errorPlacement : function(error, element) {
  212. element.parent('div').append(error);
  213. },
  214. submitHandler : function(form) {
  215. $.post(base_url + "/jobgroup/save", $("#addModal .form").serialize(), function(data, status) {
  216. if (data.code == "200") {
  217. $('#addModal').modal('hide');
  218. layer.open({
  219. title: I18n.system_tips ,
  220. btn: [ I18n.system_ok ],
  221. content: I18n.system_add_suc ,
  222. icon: '1',
  223. end: function(layero, index){
  224. jobGroupTable.fnDraw();
  225. }
  226. });
  227. } else {
  228. layer.open({
  229. title: I18n.system_tips,
  230. btn: [ I18n.system_ok ],
  231. content: (data.msg || I18n.system_add_fail ),
  232. icon: '2'
  233. });
  234. }
  235. });
  236. }
  237. });
  238. $("#addModal").on('hide.bs.modal', function () {
  239. $("#addModal .form")[0].reset();
  240. addModalValidate.resetForm();
  241. $("#addModal .form .form-group").removeClass("has-error");
  242. });
  243. // addressType change
  244. $("#addModal input[name=addressType], #updateModal input[name=addressType]").click(function(){
  245. var addressType = $(this).val();
  246. var $addressList = $(this).parents("form").find("textarea[name=addressList]");
  247. if (addressType == 0) {
  248. $addressList.css("background-color", "#eee"); // 自动注册
  249. $addressList.attr("readonly","readonly");
  250. $addressList.val("");
  251. } else {
  252. $addressList.css("background-color", "white");
  253. $addressList.removeAttr("readonly");
  254. }
  255. });
  256. // opt_edit
  257. $("#jobgroup_list").on('click', '.opt_edit',function() {
  258. var id = $(this).parents('ul').attr("_id");
  259. var row = tableData['key'+id];
  260. $("#updateModal .form input[name='id']").val( row.id );
  261. $("#updateModal .form input[name='appName']").val( row.appName );
  262. $("#updateModal .form input[name='title']").val( row.title );
  263. // 注册方式
  264. $("#updateModal .form input[name='addressType']").removeAttr('checked');
  265. $("#updateModal .form input[name='addressType'][value='"+ row.addressType +"']").click();
  266. // 机器地址
  267. $("#updateModal .form textarea[name='addressList']").val( row.addressList );
  268. $('#updateModal').modal({backdrop: false, keyboard: false}).modal('show');
  269. });
  270. var updateModalValidate = $("#updateModal .form").validate({
  271. errorElement : 'span',
  272. errorClass : 'help-block',
  273. focusInvalid : true,
  274. rules : {
  275. appName : {
  276. required : true,
  277. rangelength:[4,64],
  278. myValid01 : true
  279. },
  280. title : {
  281. required : true,
  282. rangelength:[4, 12]
  283. }
  284. },
  285. messages : {
  286. appName : {
  287. required : I18n.system_please_input+"AppName",
  288. rangelength: I18n.jobgroup_field_appName_length ,
  289. myValid01: I18n.jobgroup_field_appName_limit
  290. },
  291. title : {
  292. required : I18n.system_please_input + I18n.jobgroup_field_title ,
  293. rangelength: I18n.jobgroup_field_title_length
  294. }
  295. },
  296. highlight : function(element) {
  297. $(element).closest('.form-group').addClass('has-error');
  298. },
  299. success : function(label) {
  300. label.closest('.form-group').removeClass('has-error');
  301. label.remove();
  302. },
  303. errorPlacement : function(error, element) {
  304. element.parent('div').append(error);
  305. },
  306. submitHandler : function(form) {
  307. $.post(base_url + "/jobgroup/update", $("#updateModal .form").serialize(), function(data, status) {
  308. if (data.code == "200") {
  309. $('#updateModal').modal('hide');
  310. layer.open({
  311. title: I18n.system_tips ,
  312. btn: [ I18n.system_ok ],
  313. content: I18n.system_update_suc ,
  314. icon: '1',
  315. end: function(layero, index){
  316. jobGroupTable.fnDraw();
  317. }
  318. });
  319. } else {
  320. layer.open({
  321. title: I18n.system_tips,
  322. btn: [ I18n.system_ok ],
  323. content: (data.msg || I18n.system_update_fail ),
  324. icon: '2'
  325. });
  326. }
  327. });
  328. }
  329. });
  330. $("#updateModal").on('hide.bs.modal', function () {
  331. $("#updateModal .form")[0].reset();
  332. addModalValidate.resetForm();
  333. $("#updateModal .form .form-group").removeClass("has-error");
  334. });
  335. });