web/ldt/media/js/login_ajax/jquery.login.js
author wakimd
Sun, 14 Nov 2010 20:25:22 +0100
changeset 1 3a30d255c235
permissions -rw-r--r--
First version of API with tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     1
$(document).ready(function() {
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     2
     $('#password').keypress(function(e) {
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     3
            if(e.which == 13) {
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     4
                jQuery('#submit').focus().click();
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     5
            }
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     6
        });
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     7
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     8
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
     9
    $("#submit").click(function() {
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    10
        var username=$("#username").val();
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    11
        var password=$("#password").val();
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    12
        var data = {'username': username, 'password': password, 'reload': reload};
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    13
        if(username=="" && password=="")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    14
        {
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    15
            $("#login_form_username_error").show();
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    16
            $("#login_form_password_error").show();
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    17
            $("#username").addClass("ajaxform_invalid");
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    18
            $("#password").addClass("ajaxform_invalid");
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    19
        }
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    20
        else if(username=="" && password!="")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    21
        {
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    22
            $("#login_form_username_error").show();
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    23
            $("#username").addClass("ajaxform_invalid");
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    24
        }
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    25
        else if(password=="" && username!="")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    26
        {
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    27
            $("#login_form_password_error").show();
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    28
            $("#password").addClass("ajaxform_invalid");
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    29
        }
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    30
        else{
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    31
    
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    32
        $.ajax({
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    33
        type: "POST",  
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    34
        url : url_login_ajax,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    35
        dataType:'json',
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    36
        data: data,
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    37
        error: function (){
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    38
            $("#msg").html("fail to connect");
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    39
            },
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    40
        success: function(data, reload){ //if success, refrash un bout de page pour afficher le nom de utilisateur et déconnecter.
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    41
                            if (data.message!="successful")
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    42
                            {
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    43
                                $("#msg").html(data.message).show();
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    44
                            }
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    45
                            else{
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    46
                            // $("#floatdialog_mask_loginform").hide();
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    47
                            //window.location.reload();
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    48
                                if (data.reload=='true'){
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    49
                                    window.location.reload();
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    50
                                }
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    51
                                else{
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    52
                                    //$("#loginstate").html('<a href ="'+url_userspace+'">'+data.username+'</a> | <a href="'+url_logout+'">déconnection</a>');
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    53
                                    //$("#loginstate").html('<ul class="usertool"><li id="user">'+data.username+'</li><li><a href ="'+url_userprofile+'">Profiles</a></li><li><a href ="'+url_userspace+'">Space</a></li><li><a href="'+url_logout+'">déconnection</a></li></ul>');
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    54
                                    var $DOMWindowOverlay = $('#DOMWindowOverlay');
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    55
                                    var $DOMWindow = $('#DOMWindow');
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    56
                                    $DOMWindowOverlay.fadeOut('fast',function(){
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    57
                                        $DOMWindowOverlay.trigger('unload').unbind().remove();																	  
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    58
                                    });
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    59
                                    $DOMWindow.fadeOut('fast',function(){
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    60
                                        if($.fn.draggable){
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    61
                                            $DOMWindow.draggable("destroy").trigger("unload").remove();
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    62
                                        }else{
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    63
                                            $DOMWindow.trigger("unload").remove();
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    64
                                        }
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    65
                                    });
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    66
                                    $("#loginstate").html(data.html);
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    67
                                }
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    68
                            }
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    69
                         
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    70
                           
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    71
                }  
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    72
        });
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    73
        }
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    74
    });
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    75
})
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    76
3a30d255c235 First version of API with tests
wakimd
parents:
diff changeset
    77