Guest User

Untitled

a guest
Sep 19th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. $(function () {
  2.  
  3. var logout = $('#submit-logout');
  4. var loadPanel = $('#panel-content-inner');
  5. var panelWidget = $('.panel-widget');
  6. var panel = $('#panel');
  7. var panelButton = $('#panel-button');
  8. var login = $('#login-form');
  9. var loginDiv = $('#login');
  10. var userInfo = $('#userinfo');
  11. var error = $('.error');
  12. var state = true;
  13.  
  14. function updatePanel() {
  15. $.get('users/panel', function(data) {
  16. loadPanel.html(data);
  17. });
  18. }
  19.  
  20. updatePanel();
  21.  
  22. if(panelButton.empty()) {
  23. panelWidget.css('opacity', 1);
  24. panel.css('top', '-50px');
  25. panelButton.text('Show Admin Panel');
  26. }
  27.  
  28. function tooglePanel(state) {
  29. if(!state) {
  30. panel.animate({
  31. top: '0'
  32. }, 200 );
  33. panelButton.animate({
  34. top: '50px'
  35. }, 200 );
  36. } else {
  37. panel.animate({
  38. top: '-50px'
  39. }, 200 );
  40. panelButton.animate({
  41. top: '0'
  42. }, 200 );
  43. }
  44. }
  45.  
  46. panelButton.click(function() {
  47. if(state) {
  48. state = false;
  49. panelButton.text('Hide Admin Panel');
  50. } else {
  51. state = true;
  52. panelButton.text('Show Admin Panel');
  53. }
  54. tooglePanel(state);
  55. });
  56.  
  57. login.live('submit', function(e) {
  58. $.ajax({
  59. type: 'POST',
  60. url: 'users/validate',
  61. data: {
  62. username: $('#username').val(),
  63. password: $('#password').val()
  64. },
  65. beforeSend: function() {
  66. error.html('Logger dig ind…');
  67. },
  68. dataType: 'json',
  69. success: function(json) {
  70. if (json.success == true) {
  71. error.addClass('true');
  72. error.html('');
  73. error.html(json.message);
  74. setTimeout(function() {
  75. updatePanel();
  76. }, 800);
  77. } else {
  78. error.addClass('false');
  79. error.html('');
  80. error.html(json.message);
  81. }
  82. error.fadeIn(1000).delay(2000).fadeOut(1000);
  83. }
  84. });
  85. setTimeout(function() {
  86. error.removeClass('true false');
  87. }, 4000 );
  88. e.preventDefault();
  89. });
  90.  
  91. logout.live('click', function(e) {
  92. $.ajax({
  93. type: 'POST',
  94. url: 'users/logout',
  95. beforeSend: function() {
  96. error.html('Logging you out…').fadeIn('slow');
  97. },
  98. success: function() {
  99. error.html('');
  100. error.html('You are now logged out').fadeIn('slow');
  101. setTimeout(function() {
  102. updatePanel();
  103. }, 800);
  104. }
  105. });
  106. });
  107.  
  108. });
Add Comment
Please, Sign In to add comment