Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(function () {
- var logout = $('#submit-logout');
- var loadPanel = $('#panel-content-inner');
- var panelWidget = $('.panel-widget');
- var panel = $('#panel');
- var panelButton = $('#panel-button');
- var login = $('#login-form');
- var loginDiv = $('#login');
- var userInfo = $('#userinfo');
- var error = $('.error');
- var state = true;
- function updatePanel() {
- $.get('users/panel', function(data) {
- loadPanel.html(data);
- });
- }
- updatePanel();
- if(panelButton.empty()) {
- panelWidget.css('opacity', 1);
- panel.css('top', '-50px');
- panelButton.text('Show Admin Panel');
- }
- function tooglePanel(state) {
- if(!state) {
- panel.animate({
- top: '0'
- }, 200 );
- panelButton.animate({
- top: '50px'
- }, 200 );
- } else {
- panel.animate({
- top: '-50px'
- }, 200 );
- panelButton.animate({
- top: '0'
- }, 200 );
- }
- }
- panelButton.click(function() {
- if(state) {
- state = false;
- panelButton.text('Hide Admin Panel');
- } else {
- state = true;
- panelButton.text('Show Admin Panel');
- }
- tooglePanel(state);
- });
- login.live('submit', function(e) {
- $.ajax({
- type: 'POST',
- url: 'users/validate',
- data: {
- username: $('#username').val(),
- password: $('#password').val()
- },
- beforeSend: function() {
- error.html('Logger dig ind…');
- },
- dataType: 'json',
- success: function(json) {
- if (json.success == true) {
- error.addClass('true');
- error.html('');
- error.html(json.message);
- setTimeout(function() {
- updatePanel();
- }, 800);
- } else {
- error.addClass('false');
- error.html('');
- error.html(json.message);
- }
- error.fadeIn(1000).delay(2000).fadeOut(1000);
- }
- });
- setTimeout(function() {
- error.removeClass('true false');
- }, 4000 );
- e.preventDefault();
- });
- logout.live('click', function(e) {
- $.ajax({
- type: 'POST',
- url: 'users/logout',
- beforeSend: function() {
- error.html('Logging you out…').fadeIn('slow');
- },
- success: function() {
- error.html('');
- error.html('You are now logged out').fadeIn('slow');
- setTimeout(function() {
- updatePanel();
- }, 800);
- }
- });
- });
- });
Add Comment
Please, Sign In to add comment