jobgroup.index.1.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. $(function () {
  2. // remove
  3. $('.remove').on('click', function () {
  4. var id = $(this).attr('id');
  5. layer.confirm((I18n.system_ok + I18n.jobgroup_del + '?'), {
  6. icon: 3,
  7. title: I18n.system_tips,
  8. btn: [I18n.system_ok, I18n.system_cancel]
  9. }, function (index) {
  10. layer.close(index);
  11. $.ajax({
  12. type: 'POST',
  13. url: base_url + '/jobgroup/remove',
  14. data: {"id": id},
  15. dataType: "json",
  16. success: function (data) {
  17. if (data.code == 200) {
  18. layer.open({
  19. title: I18n.system_tips,
  20. btn: [I18n.system_ok],
  21. content: (I18n.jobgroup_del + I18n.system_success),
  22. icon: '1',
  23. end: function (layero, index) {
  24. window.location.reload();
  25. }
  26. });
  27. } else {
  28. layer.open({
  29. title: I18n.system_tips,
  30. btn: [I18n.system_ok],
  31. content: (data.msg || (I18n.jobgroup_del + I18n.system_fail)),
  32. icon: '2'
  33. });
  34. }
  35. },
  36. });
  37. });
  38. });
  39. // jquery.validate “low letters start, limit contants、 letters、numbers and line-through.”
  40. jQuery.validator.addMethod("myValid01", function (value, element) {
  41. var valid = /^[a-z][a-zA-Z0-9-]*$/;
  42. return this.optional(element) || valid.test(value);
  43. }, I18n.jobgroup_field_appName_limit);
  44. $('.add').on('click', function () {
  45. $('#addModal').modal({backdrop: false, keyboard: false}).modal('show');
  46. });
  47. var addModalValidate = $("#addModal .form").validate({
  48. errorElement: 'span',
  49. errorClass: 'help-block',
  50. focusInvalid: true,
  51. rules: {
  52. appName: {
  53. required: true,
  54. rangelength: [4, 64],
  55. myValid01: true
  56. },
  57. title: {
  58. required: true,
  59. rangelength: [4, 12]
  60. },
  61. order: {
  62. required: true,
  63. digits: true,
  64. range: [1, 1000]
  65. }
  66. },
  67. messages: {
  68. appName: {
  69. required: I18n.system_please_input + "AppName",
  70. rangelength: I18n.jobgroup_field_appName_length,
  71. myValid01: I18n.jobgroup_field_appName_limit
  72. },
  73. title: {
  74. required: I18n.system_please_input + I18n.jobgroup_field_title,
  75. rangelength: I18n.jobgroup_field_title_length
  76. },
  77. order: {
  78. required: I18n.system_please_input + I18n.jobgroup_field_order,
  79. digits: I18n.jobgroup_field_order_digits,
  80. range: I18n.jobgroup_field_orderrange
  81. }
  82. },
  83. highlight: function (element) {
  84. $(element).closest('.form-group').addClass('has-error');
  85. },
  86. success: function (label) {
  87. label.closest('.form-group').removeClass('has-error');
  88. label.remove();
  89. },
  90. errorPlacement: function (error, element) {
  91. element.parent('div').append(error);
  92. },
  93. submitHandler: function (form) {
  94. $.post(base_url + "/jobgroup/save", $("#addModal .form").serialize(), function (data, status) {
  95. if (data.code == "200") {
  96. $('#addModal').modal('hide');
  97. layer.open({
  98. title: I18n.system_tips,
  99. btn: [I18n.system_ok],
  100. content: I18n.system_add_suc,
  101. icon: '1',
  102. end: function (layero, index) {
  103. window.location.reload();
  104. }
  105. });
  106. } else {
  107. layer.open({
  108. title: I18n.system_tips,
  109. btn: [I18n.system_ok],
  110. content: (data.msg || I18n.system_add_fail),
  111. icon: '2'
  112. });
  113. }
  114. });
  115. }
  116. });
  117. $("#addModal").on('hide.bs.modal', function () {
  118. $("#addModal .form")[0].reset();
  119. addModalValidate.resetForm();
  120. $("#addModal .form .form-group").removeClass("has-error");
  121. });
  122. // addressType change
  123. $("#addModal input[name=addressType], #updateModal input[name=addressType]").click(function () {
  124. var addressType = $(this).val();
  125. var $addressList = $(this).parents("form").find("textarea[name=addressList]");
  126. if (addressType == 0) {
  127. $addressList.css("background-color", "#eee"); // 自动注册
  128. $addressList.attr("readonly", "readonly");
  129. $addressList.val("");
  130. } else {
  131. $addressList.css("background-color", "white");
  132. $addressList.removeAttr("readonly");
  133. }
  134. });
  135. // update
  136. $('.update').on('click', function () {
  137. $("#updateModal .form input[name='id']").val($(this).attr("id"));
  138. $("#updateModal .form input[name='appName']").val($(this).attr("appName"));
  139. $("#updateModal .form input[name='title']").val($(this).attr("title"));
  140. $("#updateModal .form input[name='order']").val($(this).attr("order"));
  141. // 注册方式
  142. var addressType = $(this).attr("addressType");
  143. $("#updateModal .form input[name='addressType']").removeAttr('checked');
  144. //$("#updateModal .form input[name='addressType'][value='"+ addressType +"']").attr('checked', 'true');
  145. $("#updateModal .form input[name='addressType'][value='" + addressType + "']").click();
  146. // 机器地址
  147. $("#updateModal .form textarea[name='addressList']").val($(this).attr("addressList"));
  148. $('#updateModal').modal({backdrop: false, keyboard: false}).modal('show');
  149. });
  150. var updateModalValidate = $("#updateModal .form").validate({
  151. errorElement: 'span',
  152. errorClass: 'help-block',
  153. focusInvalid: true,
  154. rules: {
  155. appName: {
  156. required: true,
  157. rangelength: [4, 64],
  158. myValid01: true
  159. },
  160. title: {
  161. required: true,
  162. rangelength: [4, 12]
  163. },
  164. order: {
  165. required: true,
  166. digits: true,
  167. range: [1, 1000]
  168. }
  169. },
  170. messages: {
  171. appName: {
  172. required: I18n.system_please_input + "AppName",
  173. rangelength: I18n.jobgroup_field_appName_length,
  174. myValid01: I18n.jobgroup_field_appName_limit
  175. },
  176. title: {
  177. required: I18n.system_please_input + I18n.jobgroup_field_title,
  178. rangelength: I18n.jobgroup_field_title_length
  179. },
  180. order: {
  181. required: I18n.system_please_input + I18n.jobgroup_field_order,
  182. digits: I18n.jobgroup_field_order_digits,
  183. range: I18n.jobgroup_field_orderrange
  184. }
  185. },
  186. highlight: function (element) {
  187. $(element).closest('.form-group').addClass('has-error');
  188. },
  189. success: function (label) {
  190. label.closest('.form-group').removeClass('has-error');
  191. label.remove();
  192. },
  193. errorPlacement: function (error, element) {
  194. element.parent('div').append(error);
  195. },
  196. submitHandler: function (form) {
  197. $.post(base_url + "/jobgroup/update", $("#updateModal .form").serialize(), function (data, status) {
  198. if (data.code == "200") {
  199. $('#addModal').modal('hide');
  200. layer.open({
  201. title: I18n.system_tips,
  202. btn: [I18n.system_ok],
  203. content: I18n.system_update_suc,
  204. icon: '1',
  205. end: function (layero, index) {
  206. window.location.reload();
  207. }
  208. });
  209. } else {
  210. layer.open({
  211. title: I18n.system_tips,
  212. btn: [I18n.system_ok],
  213. content: (data.msg || I18n.system_update_fail),
  214. icon: '2'
  215. });
  216. }
  217. });
  218. }
  219. });
  220. $("#updateModal").on('hide.bs.modal', function () {
  221. $("#updateModal .form")[0].reset();
  222. addModalValidate.resetForm();
  223. $("#updateModal .form .form-group").removeClass("has-error");
  224. });
  225. });