Subversion Repositories SmartDukaan

Rev

Rev 24489 | Rev 25570 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(function() {
        $(".add-auth-user").live('click', function() {
                console.log("Add Auth User clicked......");
                loadAddAuthUser("main-content");
        });
        $(".change-auth-user-password").live('click', function() {
                console.log("change auth user password clicked......");
                loadChangeAuthUserPassword("main-content");
        });
        $(".mk_gmail_edit").live('click', function(){
                var $that = $(this);
                bootbox.prompt("New Gmail Id", function(result){
                        if(result && result.indexOf('@gmail.com') > 0) {
                                doGetAjaxRequestHandler(context + "/authuser/edit?emailId=" + $that.data("id") + "&gmailId=" + result, function(response) {
                                        if(response=="true") {
                                                bootbox.alert("Gmail Id updated successfully");
                                                $that.closest('td').find('span').html(result);
                                                $that.closest('td').find('button').html('Edit');
                                                return;
                                        }
                                });
                        } else {
                                bootbox.alert("Gmail id is required");
                        }
                });
        });

        $(".reset-password")
                        .live(
                                        'click',
                                        function() {
                                                console.log("reset-password clicked......");
                                                var emailId = $(this).data('id');
                                                console.log(emailId);
                                                if (confirm("Are you sure you want to reset password of Auth userEmail=!"
                                                                + emailId) == true) {
                                                        resetAuthUserPassword("main-content", emailId);
                                                }
                                        });
        $(".change-password")
                        .live(
                                        'click',
                                        function() {
                                                console.log("change-password button clicked......");
                                                var oldPassword = $("#currentPassword").val();
                                                var newPassword = $("#newPassword").val();
                                                var confirmPassword = $("#confirmPassword").val();
                                                if (oldPassword == "" || oldPassword == null
                                                                || oldPassword == undefined) {
                                                        alert("oldPassword cann't be blank");
                                                        return;
                                                }
                                                if (newPassword == "" || newPassword == null
                                                                || newPassword == undefined) {
                                                        alert("lastName cann't be blank");
                                                        return;
                                                }
                                                if (confirmPassword == "" || confirmPassword == null
                                                                || confirmPassword == undefined) {
                                                        alert("confirmPassword cann't be blank");
                                                        return;
                                                }
                                                if (confirmPassword == newPassword) {
                                                        if (confirm("Are you sure you want to change user password!") == true) {
                                                                changeAuthUserPassword(oldPassword, newPassword);
                                                        }
                                                } else {
                                                        alert("new Password and confirm Password must be match");
                                                }
                                        });
        $(".create-auth-user")
                        .live(
                                        'click',
                                        function() {
                                                console.log("Create Auth User button clicked......");
                                                var emailId = $("#authUserEmail").val();
                                                var firstName = $("#authUserFirstName").val();
                                                var lastName = $("#authUserLastName").val();
                                                var mobileNumber = $("#authUserMobileNumber").val();
                                                var gmailId = $("#authUserGmailId").val();

                                                if (emailId == "" || emailId == null
                                                                || emailId == undefined) {
                                                        alert("emailId cann't be blank");
                                                        return;
                                                }
                                                
                                                if (gmailId == "" || gmailId == null
                                                                || gmailId == undefined) {
                                                        gmailId=null;
                                                }
                                                validateEmail(emailId);
                                                if (firstName == "" || firstName == null
                                                                || firstName == undefined) {
                                                        alert("firstName can't be blank");
                                                        return;
                                                }
                                                if (lastName == "" || lastName == null
                                                                || lastName == undefined) {
                                                        alert("lastName can't be blank");
                                                        return;
                                                }
                                                if (mobileNumber == "" || mobileNumber == null
                                                                || mobileNumber == undefined) {
                                                        alert("mobileNumber can't be blank");
                                                        return;
                                                }
                                                if (mobileNumber.length != 10) {

                                                        alert("required 10 digits, match requested format!");
                                                        return;
                                                }
                                                if (confirm("Are you sure you want to create Auth user!") == true) {
                                                        addAuthUser(emailId, firstName, lastName,
                                                                        mobileNumber,gmailId);
                                                }
                                        });
        $("#authUsers-paginated .next").live(
                        'click',
                        function() {

                                loadPaginatedNextItems('/getPaginatedAuthUser', null,
                                                'authUsers-paginated', 'auth-user-table',
                                                'auth-user-details-container');
                                $(this).blur();
                        });

        $("#authUsers-paginated .previous").live(
                        'click',
                        function() {

                                loadPaginatedPreviousItems('/getPaginatedAuthUser', null,
                                                'authUsers-paginated', 'auth-user-table',
                                                'auth-user-details-container');
                                $(this).blur();
                        });

});

function loadChangeAuthUserPassword(domId) {
        doGetAjaxRequestHandler(context + "/changePassword", function(response) {
                $('#' + domId).html(response);
        });
}
function changeAuthUserPassword(oldPassword, newPassword) {
        var params = {
                "oldPassword" : oldPassword,
                "newPassword" : newPassword
        }
        doPostAjaxRequestWithParamsHandler(context + "/changePassword", params,
                        function(response) {
                                alert("Password changed successfully");
                                loadChangeAuthUserPassword("main-content");
                        });
}
function addAuthUser(emailId, firstName, lastName, mobileNumber,gmailId) {
        var params = {
                "emailId" : emailId,
                "firstName" : firstName,
                "lastName" : lastName,
                "mobileNumber" : mobileNumber,
                "gmailId":gmailId
        }
        doPostAjaxRequestWithParamsHandler(
                        context + "/createAuthUser",
                        params,
                        function(response) {
                                alert("User successfully added! Password sent to registered email="
                                                + emailId);
                                $('#' + "main-content").html(response);
                        });
}
function loadAddAuthUser(domId) {
        doGetAjaxRequestHandler(context + "/createAuthUser", function(response) {
                $('#' + domId).html(response);
        });
}
function resetAuthUserPassword(domId, emailId) {
        var params = {
                "emailId" : emailId
        }
        doAjaxRequestWithParamsHandler(context + "/forgetPassword", "POST", params,
                        function(response) {
                                if (response == "true") {
                                        alert("Password send to " + emailId + "  Successfully ");
                                        loadAddAuthUser(domId);
                                }

                        });
}
function validateEmail(emailField) {
        var reg = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if (reg.test(emailField) == false) {
                alert('Invalid Email Address');
                return false;
        }

        return true;

}