jobgroup.index.1.js 6.9 KB

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