common.1.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. $(function(){
  2. // logout
  3. $("#logoutBtn").click(function(){
  4. layer.confirm( I18n.logout_confirm , {
  5. icon: 3,
  6. title: I18n.system_tips ,
  7. btn: [ I18n.system_ok, I18n.system_cancel ]
  8. }, function(index){
  9. layer.close(index);
  10. $.post(base_url + "/logout", function(data, status) {
  11. if (data.code == "200") {
  12. layer.msg( I18n.logout_success );
  13. setTimeout(function(){
  14. window.location.href = base_url + "/";
  15. }, 500);
  16. } else {
  17. layer.open({
  18. title: I18n.system_tips ,
  19. btn: [ I18n.system_ok ],
  20. content: (data.msg || I18n.logout_fail),
  21. icon: '2'
  22. });
  23. }
  24. });
  25. });
  26. });
  27. // slideToTop
  28. var slideToTop = $("<div />");
  29. slideToTop.html('<i class="fa fa-chevron-up"></i>');
  30. slideToTop.css({
  31. position: 'fixed',
  32. bottom: '20px',
  33. right: '25px',
  34. width: '40px',
  35. height: '40px',
  36. color: '#eee',
  37. 'font-size': '',
  38. 'line-height': '40px',
  39. 'text-align': 'center',
  40. 'background-color': '#222d32',
  41. cursor: 'pointer',
  42. 'border-radius': '5px',
  43. 'z-index': '99999',
  44. opacity: '.7',
  45. 'display': 'none'
  46. });
  47. slideToTop.on('mouseenter', function () {
  48. $(this).css('opacity', '1');
  49. });
  50. slideToTop.on('mouseout', function () {
  51. $(this).css('opacity', '.7');
  52. });
  53. $('.wrapper').append(slideToTop);
  54. $(window).scroll(function () {
  55. if ($(window).scrollTop() >= 150) {
  56. if (!$(slideToTop).is(':visible')) {
  57. $(slideToTop).fadeIn(500);
  58. }
  59. } else {
  60. $(slideToTop).fadeOut(500);
  61. }
  62. });
  63. $(slideToTop).click(function () {
  64. $("html,body").animate({ // firefox ie not support body, chrome support body. but found that new version chrome not support body too.
  65. scrollTop: 0
  66. }, 100);
  67. });
  68. // left menu status v: js + server + cookie
  69. $('.sidebar-toggle').click(function(){
  70. var xxljob_adminlte_settings = $.cookie('xxljob_adminlte_settings'); // on=open,off=close
  71. if ('off' == xxljob_adminlte_settings) {
  72. xxljob_adminlte_settings = 'on';
  73. } else {
  74. xxljob_adminlte_settings = 'off';
  75. }
  76. $.cookie('xxljob_adminlte_settings', xxljob_adminlte_settings, { expires: 7 }); //$.cookie('the_cookie', '', { expires: -1 });
  77. });
  78. // left menu status v1: js + cookie
  79. /*
  80. var xxljob_adminlte_settings = $.cookie('xxljob_adminlte_settings');
  81. if (xxljob_adminlte_settings == 'off') {
  82. $('body').addClass('sidebar-collapse');
  83. }
  84. */
  85. // update pwd
  86. $('#updatePwd').on('click', function(){
  87. $('#updatePwdModal').modal({backdrop: false, keyboard: false}).modal('show');
  88. });
  89. var updatePwdModalValidate = $("#updatePwdModal .form").validate({
  90. errorElement : 'span',
  91. errorClass : 'help-block',
  92. focusInvalid : true,
  93. rules : {
  94. oldPassword : {
  95. required : true ,
  96. rangelength:[4,20]
  97. },
  98. password : {
  99. required : true ,
  100. rangelength:[4,20]
  101. }
  102. },
  103. messages : {
  104. oldPassword : {
  105. required : I18n.system_please_input +I18n.change_pwd_field_oldpwd,
  106. rangelength : "密码长度限制为4~20"
  107. },
  108. password : {
  109. required : I18n.system_please_input +I18n.change_pwd_field_newpwd,
  110. rangelength : "密码长度限制为4~20"
  111. }
  112. },
  113. highlight : function(element) {
  114. $(element).closest('.form-group').addClass('has-error');
  115. },
  116. success : function(label) {
  117. label.closest('.form-group').removeClass('has-error');
  118. label.remove();
  119. },
  120. errorPlacement : function(error, element) {
  121. element.parent('div').append(error);
  122. },
  123. submitHandler : function(form) {
  124. $.post(base_url + "/user/updatePwd", $("#updatePwdModal .form").serialize(), function(data, status) {
  125. if (data.code == 200) {
  126. $('#updatePwdModal').modal('hide');
  127. layer.msg( I18n.change_pwd_suc_to_logout );
  128. setTimeout(function(){
  129. $.post(base_url + "/logout", function(data, status) {
  130. if (data.code == 200) {
  131. window.location.href = base_url + "/";
  132. } else {
  133. layer.open({
  134. icon: '2',
  135. content: (data.msg|| I18n.logout_fail)
  136. });
  137. }
  138. });
  139. }, 500);
  140. } else {
  141. layer.open({
  142. icon: '2',
  143. content: (data.msg|| I18n.change_pwd + I18n.system_fail )
  144. });
  145. }
  146. });
  147. }
  148. });
  149. $("#updatePwdModal").on('hide.bs.modal', function () {
  150. $("#updatePwdModal .form")[0].reset();
  151. updatePwdModalValidate.resetForm();
  152. $("#updatePwdModal .form .form-group").removeClass("has-error");
  153. });
  154. });