Subversion Repositories SmartDukaan

Rev

Rev 24469 | Rev 24500 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(function() {

        $(".create-ticket-category").live('click', function() {
                console.log("create ticket category clicked......");
                loadCreateCategory("main-content");
        });
        $(".create-region").live('click', function() {
                loadCreateRegion("main-content");
        });

        $(".change-ticket-button")
                        .live(
                                        'click',
                                        function() {
                                                var ticketId = $("#ticketId").val();
                                                var subCategory = $("#subCategory").val();
                                                var authUserId = $("#authUser").val();
                                                console.log(ticketId);
                                                if (subCategory == null || subCategory == ""
                                                                || subCategory == undefined) {
                                                        alert("Choose appropriate subCategory");
                                                }
                                                if (confirm("Are you sure you want to change ticket!") == true) {
                                                        changeTicket(ticketId, subCategory, authUserId);
                                                }
                                        });
        $("#edit-ticket").live('click', function() {

                var ticketId = $(this).data('ticketid1');
                console.log(ticketId);
                loadEditTicket(ticketId);
        });
        $(".manager-ticket").live('click', function() {
                loadManagerTicket("main-content");
        });
        $(".ticketType").live('click', function() {
                loadCreateRegion("main-content");
        });
        $("#activities").live('click', function() {
                var ticketId = $(this).data('ticketid');
                var assignee = $(this).data('assignee');
                console.log(assignee);
                loadActivities(ticketId, assignee);
        });
        $(".my-ticket").live('click', function() {
                loadMyTicket("main-content");
        });
        $("#close-ticket").live('click', function() {
                var ticketId = $(this).data('ticketid');
                closeTicket(ticketId);
        });
        $(".submit-message-button").live('click', function() {
                var message = $("#activityMessage").val();
                if (message == "" || message == null || message == undefined) {
                        alert("message field can't be empty");
                }
                var ticketId = $("#ticketIdforactivity").val();
                var assignee = $("#assigneeUser").val();
                console.log(message, ticketId, assignee);
                createActivity(message, ticketId, assignee);
        });

        $("#tickets-paginated .next").live(
                        'click',
                        function() {
                                loadPaginatedNextItems('/cs/myticketPaginated', null,
                                                'tickets-paginated', 'my-ticket-table',
                                                'ticket-details-container');
                                $(this).blur();
                        });

        $("#manager-tickets-paginated .previous").live(
                        'click',
                        function() {
                                loadPaginatedPreviousItems('/cs/managerTicket-paginated', null,
                                                'manager-tickets-paginated', 'manager-ticket-table',
                                                'manager-ticket-details-container');
                                $(this).blur();
                        });
        $("#manager-tickets-paginated .next").live(
                        'click',
                        function() {
                                loadPaginatedNextItems('/cs/managerTicket-paginated', null,
                                                'manager-tickets-paginated', 'manager-ticket-table',
                                                'manager-ticket-details-container');
                                $(this).blur();
                        });

        $("#tickets-paginated .previous").live(
                        'click',
                        function() {
                                loadPaginatedPreviousItems('/cs/myticketPaginated', null,
                                                'tickets-paginated', 'my-ticket-table',
                                                'ticket-details-container');
                                $(this).blur();
                        });
        $("#positions-paginated .next").live(
                        'click',
                        function() {
                                loadPaginatedNextItems('/cs/position-paginated', null,
                                                'positions-paginated', 'position-table',
                                                'position-details-container');
                                $(this).blur();
                        });

        $("#positions-paginated .previous").live(
                        'click',
                        function() {
                                loadPaginatedPreviousItems('/cs/position-paginated', null,
                                                'positions-paginated', 'position-table',
                                                'position-details-container');
                                $(this).blur();
                        });

        $(".create-partner-region").live('click', function() {
                loadCreatePartnerRegion("main-content");
        });
        $(".create-ticket").live('click', function() {
                loadCreateTicket("main-content");
        });
        $(".create-ticket-button")
                        .live(
                                        'click',
                                        function() {
                                                var categoryId = $('#category').val();
                                                var subCategoryId = $('#subCategory').val();
                                                if (categoryId == "" || categoryId == null
                                                                || categoryId == undefined) {
                                                        alert("select appropriate category");
                                                        return false;
                                                }
                                                if (subCategoryId == "" || subCategoryId == null
                                                                || subCategoryId == undefined) {
                                                        alert("select appropriate subCategoryId");
                                                        return false;
                                                }
                                                var dialog = bootbox
                                                                .dialog({
                                                                        title : "Are you sure want to change create ticket!",
                                                                        message : "<div class=form-inline'>"
                                                                                        + "<label for='message'>Message:</label>"
                                                                                        + "<textarea class='form-control' rows='2' id='message'></textarea>"
                                                                                        + "</div>",
                                                                        buttons : {
                                                                                cancel : {
                                                                                        label : "cancel",
                                                                                        className : 'btn-danger',
                                                                                        callback : function() {
                                                                                                loadCreateTicket("main-content");
                                                                                        }
                                                                                },
                                                                                ok : {
                                                                                        label : "ok",
                                                                                        className : 'btn-info',
                                                                                        callback : function() {
                                                                                                message = $('#message').val();
                                                                                                console.log(message);
                                                                                                if (message == ""
                                                                                                                || message == null
                                                                                                                || message == undefined) {
                                                                                                        alert("message field can't be empty");
                                                                                                        return false;
                                                                                                }
                                                                                                var params = {
                                                                                                        "categoryId" : categoryId,
                                                                                                        "subCategoryId" : subCategoryId,
                                                                                                        "message" : message
                                                                                                }
                                                                                                doPostAjaxRequestWithParamsHandler(
                                                                                                                context
                                                                                                                                + "/cs/createTicket",
                                                                                                                params,
                                                                                                                function(response) {
                                                                                                                        if (response == "true") {
                                                                                                                                alert("successfully created");
                                                                                                                                loadCreateTicket("main-content");
                                                                                                                        }
                                                                                                                });

                                                                                        }
                                                                                }
                                                                        }
                                                                });

                                        });
        $(".create-position").live('click', function() {
                loadCreatePosition("main-content");
        });

        $("#category").live('change', function() {
                var categoryId = $("#category").val();
                loadSubCategories(categoryId);
        });
        $(".create-ticket-category-button")
                        .live(
                                        'click',
                                        function() {
                                                console
                                                                .log("create-ticket-category-button clicked......");
                                                var name = $("#categoryName").val();
                                                var description = $("#categorydescription").val();
                                                console.log(name, description);
                                                if (name == "" || name == null || name == undefined) {
                                                        alert("Name field can't be empty");
                                                        return false;
                                                }
                                                if (description == "" || description == null
                                                                || description == undefined) {
                                                        alert("Description field can't be empty");
                                                        return false;
                                                }
                                                if (confirm("Are you sure you want to create ticket category!") == true) {
                                                        createCategory("main-content", name, description);
                                                }
                                        });
        $(".create-region-button")
                        .live(
                                        'click',
                                        function() {
                                                var name = $("#regionName").val();
                                                var description = $("#regiondescription").val();
                                                if (name == "" || name == null || name == undefined) {
                                                        alert("Name field can't be empty");
                                                        return false;
                                                }
                                                if (description == "" || description == null
                                                                || description == undefined) {
                                                        alert("Description field can't be empty");
                                                        return false;
                                                }
                                                if (confirm("Are you sure you want to create region!") == true) {
                                                        createRegion("main-content", name, description);
                                                }
                                        });

        $(".create-partner-region-button")
                        .live(
                                        'click',
                                        function() {

                                                var regionId = $("#region").val();
                                                var fofoIds = $("#partner").val();
                                                console.log(regionId, fofoIds);
                                                if (regionId == "" || regionId == null
                                                                || regionId == undefined) {
                                                        alert("regionId field can't be empty");
                                                        return false;
                                                }
                                                if (fofoIds == "" || fofoIds == null
                                                                || fofoIds == undefined) {
                                                        alert("select appropriate partner");
                                                        return false;
                                                }
                                                if (confirm("Are you sure you want to create partner region!") == true) {
                                                        createPartnerRegion("main-content", regionId,
                                                                        fofoIds);
                                                }
                                        });
        $(".create-position-button")
                        .live(
                                        'click',
                                        function() {

                                                var authUser = $("#authUser").val();
                                                var ticketCategoryPosition = $(
                                                                "#ticketCategoryPosition").val();
                                                var escalationType = $("#escalationType").val();
                                                var regionPosition = $("#regionPosition").val();
                                                console.log(authUser, ticketCategoryPosition,
                                                                escalationType, regionPosition);
                                                if (authUser == "" || authUser == null
                                                                || authUser == undefined) {
                                                        alert("select appropriate authUser");
                                                        return false;
                                                }
                                                if (ticketCategoryPosition == ""
                                                                || ticketCategoryPosition == null
                                                                || ticketCategoryPosition == undefined) {
                                                        alert("select appropriate category");
                                                        return false;
                                                }
                                                if (escalationType == "" || escalationType == null
                                                                || escalationType == undefined) {
                                                        alert("select appropriate escalationType");
                                                        return false;
                                                }
                                                if (regionPosition == "" || regionPosition == null
                                                                || regionPosition == undefined) {
                                                        alert("select appropriate Region");
                                                        return false;
                                                }
                                                if (confirm("Are you sure you want to create Position!") == true) {
                                                        createPosition("main-content", authUser,
                                                                        ticketCategoryPosition, escalationType,
                                                                        regionPosition);
                                                }
                                        });

        $("#ticketCategory").live('change', function() {
                console.log("change ticket category clicked......");
                var ticketCategoryId = $(this).val();
                console.log(ticketCategoryId);
                loadticketSubCategoryById(ticketCategoryId);
        });
        $(".create-ticket-sub-category").live('click', function() {
                console.log("create ticket category clicked......");
                loadCreateSubCategory("main-content");
        });

        $(".create-ticket-sub-category-button")
                        .live(
                                        'click',
                                        function() {
                                                console
                                                                .log("create-ticket-category-button clicked......");
                                                var name = $("#subcategoryName").val();
                                                var description = $("#subcategorydescription").val();
                                                var ticketCategoryId = $("#ticketCategory").val();
                                                console.log(name, description);
                                                if (name == "" || name == null || name == undefined) {
                                                        alert("Name field can't be empty");
                                                        return false;
                                                }
                                                if (description == "" || description == null
                                                                || description == undefined) {
                                                        alert("Description field can't be empty");
                                                        return false;
                                                }
                                                if (ticketCategoryId == "" || ticketCategoryId == null
                                                                || ticketCategoryId == undefined) {
                                                        alert("select appropriate category name");
                                                        return false;
                                                }
                                                if (confirm("Are you sure you want to create ticket category!") == true) {
                                                        createSubCategory("main-content", name,
                                                                        description, ticketCategoryId);
                                                }
                                        });
        $(".remove-position").live('click', function() {
                var positionId = $(this).data('positionid');
                if (confirm("Are you sure you want to remove position!") == true) {
                removePosition(positionId);
                }
        });

});

function loadCreateCategory(domId) {
        doGetAjaxRequestHandler(context + "/cs/createCategory", function(response) {
                $('#' + domId).html(response);
        });
}
function removePosition(positionId)
{
        doDeleteAjaxRequestHandler(context + "/cs/removePosition?positionId="+positionId, function(response) {
                if (response == "true") {
                        alert("Position removed successfully");
                        loadCreatePosition("main-content");
                }
        });
}

function loadCreateRegion(domId) {
        doGetAjaxRequestHandler(context + "/cs/createRegion", function(response) {
                $('#' + domId).html(response);
        });
}
function loadMyTicket(domId) {
        doGetAjaxRequestHandler(context + "/cs/myticket", function(response) {
                $('#' + domId).html(response);
        });
}

function loadCreatePartnerRegion(domId) {
        doGetAjaxRequestHandler(context + "/cs/createPartnerRegion", function(
                        response) {
                $('#' + domId).html(response);
        });
}
function loadCreatePosition(domId) {
        doGetAjaxRequestHandler(context + "/cs/createPosition", function(response) {
                $('#' + domId).html(response);
        });
}
function loadSubCategories(categoryId) {
        doGetAjaxRequestHandler(context
                        + "/cs/getSubCategoriesByCategoryId?categoryId=" + categoryId,
                        function(response) {
                                $('#' + "create-ticket-sub-categories").html(response);
                        });
}
function createCategory(domId, name, description) {
        var params = {
                "name" : name,
                "description" : description
        }
        doPostAjaxRequestWithParamsHandler(context + "/cs/createCategory", params,
                        function(response) {
                                alert("Category created successfully");
                                loadCreateCategory(domId);
                        });
}
function changeTicket(ticketId, subCategoryId, authUserId) {
        var params = {
                "ticketId" : ticketId,
                "subCategoryId" : subCategoryId,
                "authUserId" : authUserId
        }
        doPostAjaxRequestWithParamsHandler(context + "/cs/edit-ticket", params,
                        function(response) {
                                if (response == "true") {
                                        alert("Ticket changed successfully");
                                        loadManagerTicket("main-content");
                                }
                        });
}
function createRegion(domId, name, description) {
        var params = {
                "name" : name,
                "description" : description
        }
        doPostAjaxRequestWithParamsHandler(context + "/cs/createRegion", params,
                        function(response) {
                                if (response == "true") {
                                        alert("Region created successfully");
                                        loadCreateRegion(domId);
                                }
                        });
}
function loadCreateSubCategory(domId) {
        doGetAjaxRequestHandler(context + "/cs/createSubCategory", function(
                        response) {
                $('#' + domId).html(response);
        });
}
function loadManagerTicket(domId) {
        doGetAjaxRequestHandler(context + "/cs/managerTicket", function(response) {
                $('#' + domId).html(response);
        });
}
function loadCreateTicket(domId) {
        doGetAjaxRequestHandler(context + "/cs/createTicket", function(response) {
                $('#' + domId).html(response);
        });
}
function loadticketSubCategoryById(ticketCategoryId) {
        doGetAjaxRequestHandler(context
                        + "/cs/getSubCategoryByCategoryId?ticketCategoryId="
                        + ticketCategoryId, function(response) {
                $(".ticket-sub-category-container").html(response);
        });
}
function createPartnerRegion(domId, regionId, fofoIds) {
        doPostAjaxRequestWithJsonHandler(context
                        + "/cs/createPartnerRegion?regionId=" + regionId, JSON
                        .stringify(fofoIds), function(response) {
                if (response == "true") {
                        alert("added region to partner successfully");
                        loadCreatePartnerRegion(domId);
                }
        });
}
function createSubCategory(domId, name, description, categoryId) {
        var params = {
                "categoryId" : categoryId,
                "name" : name,
                "description" : description
        }
        doPostAjaxRequestWithParamsHandler(context + "/cs/createSubCategory",
                        params, function(response) {
                                alert("Sub Category created successfully");
                                loadCreateSubCategory(domId);
                        });
}
function closeTicket(ticketId) {
        var dialog = bootbox
                        .dialog({
                                title : "Are you sure want to close ticket!",
                                message : "<div class=\"col-lg-6 form-group\">"
                                                + "<input placeholder=\"Happy Code\" id=\"happyCode\" name=\"happyCode\" type=\"text\"  class=\"form-control input-sm\">"
                                                + "</div>",
                                buttons : {
                                        cancel : {
                                                label : "cancel",
                                                className : 'btn-danger',
                                                callback : function() {
                                                        loadMyTicket("main-content");
                                                }
                                        },
                                        ok : {
                                                label : "ok",
                                                className : 'btn-info',
                                                callback : function() {
                                                        happyCode = $('#happyCode').val();
                                                        console.log(happyCode);
                                                        if (happyCode == "" || happyCode == null
                                                                        || happyCode == undefined) {
                                                                alert("happyCode field can't be empty");
                                                                return false;
                                                        }
                                                        var params = {
                                                                "ticketId" : ticketId,
                                                                "happyCode" : happyCode
                                                        }
                                                        doPostAjaxRequestWithParamsHandler(context
                                                                        + "/cs/closeTicket", params, function(
                                                                        response) {
                                                                alert("Ticket close successfully");
                                                                loadMyTicket("main-content");
                                                        });
                                                }
                                        }
                                }
                        });

}
function createPosition(domId, authUserId, categoryId, escalationType, regionId) {
        var params = {
                "authUserId" : authUserId,
                "categoryId" : categoryId,
                "escalationType" : escalationType,
                "regionId" : regionId
        }
        doPostAjaxRequestWithParamsHandler(context + "/cs/createPosition", params,
                        function(response) {
                                if (response == "true") {
                                        alert("Position created successfully");
                                        loadCreatePosition(domId);
                                }
                        });
}
function createActivity(message, ticketId, assigneeId) {
        var params = {
                "message" : message,
                "ticketId" : ticketId,
        }
        doPostAjaxRequestWithParamsHandler(context + "/cs/createActivity", params,
                        function(response) {
                                response = JSON.parse(response);
                                var assigneeName = response.firstName;
                                loadActivities(ticketId, assigneeName)
                        });
}
function loadEditTicket(ticketId) {
        doGetAjaxRequestHandler(context + "/cs/edit-ticket?ticketId=" + ticketId,
                        function(response) {
                                $(".modal-content").html(response);
                        });
}
function loadActivities(ticketId, assignee) {

        $(".activity-container .modal-body").empty();
        $("#activityMessage").val("");
        $("#ticketIdforactivity").val(ticketId);
        var assigned = "<div class=\"white_box\"><span>AssignedTo:-" + assignee
                        + "</span></div>";
        $(".activity-container .modal-body").append(assigned);
        console.log(ticketId);
        doGetAjaxRequestHandler(
                        context + "/cs/getActivities?ticketId=" + ticketId,
                        function(response) {
                                response = JSON.parse(response);
                                console.log(response);
                                for (var i = 0; i < response.length; i++) {
                                        if ((response[i].type == "OPENED" || response[i].type == "COMMUNICATION_IN")
                                                        && response[i].createdBy == 0) {

                                                var partnerMessage = "<div class=\"incoming_msg\">"
                                                                + "<div class=\"received_msg\">"
                                                                + "<div class=\"received_withd_msg\">" + "<p>"
                                                                + response[i].message + "</p>"
                                                                + "<span class=\"time_date\"> "
                                                                + response[i].createTimestamp.hour + ":"
                                                                + response[i].createTimestamp.minute + "|"
                                                                + response[i].createTimestamp.dayOfMonth + "/"
                                                                + response[i].createTimestamp.monthValue + "/"
                                                                + response[i].createTimestamp.year
                                                                + "</span></div>" + "</div>" + "</div>";
                                                $(".activity-container .modal-body").append(
                                                                partnerMessage);
                                        }
                                        if (response[i].type = "COMMUNICATION_OUT"
                                                        && response[i].createdBy > 0) {

                                                var assigneeMessage = "<div class=\"outgoing_msg\">"
                                                                + "<div class=\"sent_msg\">" + "<p>"
                                                                + response[i].message + "</p>"
                                                                + "<span class=\"time_date\">"
                                                                + response[i].createTimestamp.hour + ":"
                                                                + response[i].createTimestamp.minute + "|"
                                                                + response[i].createTimestamp.dayOfMonth + "/"
                                                                + response[i].createTimestamp.monthValue + "/"
                                                                + response[i].createTimestamp.year
                                                                + "</span> </div>" + "</div>";

                                                $(".activity-container .modal-body").append(
                                                                assigneeMessage);
                                        }
                                }
                        });
}