Subversion Repositories SmartDukaan

Rev

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

var TEAM_ACTIVITY = [ "COMMUNICATION_OUT", "COMMUNICATION_INTERNAL",
                "ESCALATED", "ASSIGNED", "CATEGORY_CHANGED" ];
$(function() {

        $(".create-ticket-category").live('click', function() {
                console.log("create ticket category clicked......");
                loadCreateCategory("main-content");
        });
        $(".create-region").live('click', function() {
                loadCreateRegion("main-content");
        });
        $("#manager-ticket-search-by-partner-name").live(
                        'click',
                        function() {
                                var searchContent = $(this).data('id');
                                var searchValue = $("#typeaheadpartnername").val();
                                var searchType = $("#managersearchType").val();
                                var managerTicketStatus = $("#managerTicketStatus").val();
                                var managerTicketorderBy = $("#managerTicketorderBy").val();
                                if (typeof (searchContent) == "undefined" || !searchContent) {
                                        searchContent = "";
                                }

                                loadManagerTicket("main-content", managerTicketStatus,
                                                managerTicketorderBy, searchType, searchContent,
                                                searchValue);

                        });
        $("#retailer-details-search-button-by-ticketId").live(
                        'click',
                        function() {
                                var searchContent = $("#search-by-ticketId").val();
                                var searchType = $("#managersearchType").val();
                                var managerTicketStatus = $("#managerTicketStatus").val();
                                var managerTicketorderBy = $("#managerTicketorderBy").val();
                                if (typeof (searchContent) == "undefined" || !searchContent) {
                                        searchContent = "";
                                }
                                if (searchContent == "" || searchContent == undefined
                                                || searchContent == null) {
                                        alert("Input field can't be empty");
                                        return false;
                                }
                                loadManagerTicket("main-content", managerTicketStatus,
                                                managerTicketorderBy, searchType, searchContent, null);

                        });
        $("#assignee-ticket-search-by-partner-name").live(
                        'click',
                        function() {
                                var searchContent = $(this).data('id');
                                var searchValue = $("#typeaheadpartnernameforassignee").val();
                                var searchType = $("#assigneesearchType").val();
                                var ticketStatus = $("#ticketStatus").val();
                                var ticketorderBy = $("#orderBy").val();
                                console.log(ticketStatus);
                                console.log(ticketorderBy);
                                console.log(searchValue);
                                if (typeof (searchContent) == "undefined" || !searchContent) {
                                        searchContent = "";
                                }

                                loadMyTicket("main-content", ticketStatus, ticketorderBy,
                                                searchType, searchContent, searchValue);

                        });
        $("#assignee-retailer-details-search-button-by-ticketId").live(
                        'click',
                        function() {
                                var searchContent = $("#assignee-search-by-ticketId").val();
                                var searchType = $("#assigneesearchType").val();
                                var ticketStatus = $("#ticketStatus").val();
                                var ticketorderBy = $("#orderBy").val();
                                if (typeof (searchContent) == "undefined" || !searchContent) {
                                        searchContent = "";
                                }
                                if (searchContent == "" || searchContent == undefined
                                                || searchContent == null) {
                                        alert("Input field can't be empty");
                                        return false;
                                }
                                console.log(ticketStatus);
                                console.log(ticketorderBy);
                                loadMyTicket("main-content", ticketStatus, ticketorderBy,
                                                searchType, searchContent, null);

                        });

        $("#ticket-last-activity").live('click', function() {
                var ticketId = $(this).data('ticketid');
                var activity = $(this).data('activity');
                console.log(ticketId);
                console.log(activity);
                if (confirm("Are you sure!") == true) {
                        createLastActivity(ticketId, activity);
                }
        });

        $("#region").live('change', function() {
                var regionId = $("#region").val();
                console.log(regionId);
                loadPartnerForRegion(regionId);
        });

        $("#regionPosition").live('change', function() {
                var regionId = $("#regionPosition").val();
                console.log(regionId);
                loadPartnerForRegionId(regionId);
        });

        $("#managersearchType").live('change', function() {
                var searchType = $("#managersearchType").val();
                console.log(searchType);
                var html;
                if (searchType == "PARTNER_NAME") {
                        $('.byPartnerName').css('display', 'inline-block');
                        $('.byTicketId').css('display', 'none');
                        $("#search-by-ticketId").val("");
                } else {
                        $('.byPartnerName').css('display', 'none');
                        $('.byTicketId').css('display', 'inline-block');
                        $('#manager-ticket-search-by-partner-name').data('id', "");
                }

        });
        $("#assigneesearchType").live('change', function() {
                var searchType = $("#assigneesearchType").val();
                console.log(searchType);
                var html;
                if (searchType == "PARTNER_NAME") {
                        $('.assigneebyPartnerName').css('display', 'inline-block');
                        $('.assigneebyTicketId').css('display', 'none');
                        $("#assignee-search-by-ticketId").val("");
                } else {
                        $('.assigneebyPartnerName').css('display', 'none');
                        $('.assigneebyTicketId').css('display', 'inline-block');
                        $("#assignee-ticket-search-by-partner-name").data('id', '');
                }

        });

        $(".change-ticket-button")
                        .live(
                                        'click',
                                        function() {
                                                var ticketId = $("#ticketId").val();
                                                var subCategory = $("#subCategory").val();
                                                var authUserId = $("#authUser").val();
                                                var categoryId = $("#category").val();
                                                console.log(ticketId);
                                                if (subCategory == null || subCategory == ""
                                                                || subCategory == undefined) {
                                                        alert("Choose appropriate subCategory");
                                                        return false;
                                                }
                                                console.log(authUserId);
                                                if (confirm("Are you sure you want to change ticket!") == true) {
                                                        changeTicket(ticketId, subCategory, authUserId,
                                                                        categoryId);
                                                }
                                        });
        $("#edit-ticket").live('click', function() {
                var ticketId = $(this).data('ticketid1');
                loadEditTicket(ticketId);
        });
        $(".manager-ticket").live('click', function() {
                loadManagerTicket("main-content", null, null);
        });
        $(".access-management").live('click', function() {
                loadAccessManagement("main-content", null, null);
        });
        $(".ticketType").live('click', function() {
                console.log("create Region");
                loadCreateRegion("main-content");
        });
        $("#activities").live('click', function() {
                var ticketId = $(this).data('ticketid');
                var assignee = $(this).data('assignee');
                var internal = $(this).data('internal');
                var roleType = $(this).data('role');
                console.log(assignee);
                loadActivities(ticketId, assignee, internal, roleType);
        });
        $(".my-ticket").live('click', function() {
                loadMyTicket("main-content", null, null, null, null, null);
        });
        $("#close-ticket").live('click', function() {
                var ticketId = $(this).data('ticketid');
                closeTicket(ticketId);
        });
        var documentIds = [];
        var count = 0;

        $(".submit-message-button").live(
                        'click',
                        function() {
                                var message = $("#activityMessage").val();
                                var internal = $("#internalCommunication").prop("checked");
                                if (message == "" || message == null || message == undefined) {
                                        alert("message field can't be empty");
                                        return false;
                                }
                                var ticketId = $("#ticketIdforactivity").val();
                                var assignee = $("#assigneeUser").val();
                                var roleType = $("#role").val();
                                console.log(message, ticketId, assignee);
                                createActivity(message, ticketId, assignee, internal, roleType,
                                                documentIds);
                        });

        $(".uploadFile").live('click', function() {
                $("#file1").trigger('click');
        });

        $("input[name=file1]")
                        .live(
                                        'change',
                                        function(evt) {
                                                var output = [];
                                                var fileBundle = [];
                                                for (var i = 0, f; f = evt.target.files[i]; i++) {
                                                        count++;
                                                        console.log(count);
                                                        if (evt.target.files[i].size > 5000000) {
                                                                alert("Size should be less than 5MB");
                                                                return false;
                                                        }

                                                        if (count > "5") {
                                                                alert("five files send at a time");
                                                                var lilength = $('.fileList li').size();
                                                                console.log(lilength);
                                                                count = lilength;
                                                                console.log(lilength)
                                                                return false;
                                                        }

                                                        var file = evt.target.files[i];
                                                        fileBundle.push(file);
                                                        console.log(fileBundle);

                                                        var removeLink = "<a class=\"removeFile\" href=\"#\" data-fileid=\""
                                                                        + i + "\">Remove</a>";

                                                        output.push("<li><strong>", escape(file.name),
                                                                        "</strong> - ", "&nbsp; &nbsp; ",
                                                                        removeLink, "</li> ");

                                                }

                                                for (var j = 0; j < fileBundle.length; j++) {
                                                        console.log(fileBundle[j])
                                                        var url = context + '/document-upload';
                                                        doAjaxUploadRequestHandler(
                                                                        url,
                                                                        'POST',
                                                                        fileBundle[j],
                                                                        function(response) {
                                                                                console.log(response);
                                                                                var documentId = response.response.document_id;
                                                                                console.log("documentId : "
                                                                                                + documentId);
                                                                                documentIds.push(documentId);

                                                                        });

                                                }
                                                console.log(documentIds);
                                                $(".fileList").append(output.join(""));

                                        });

        $(".removeFile").live('click', function(e) {
                e.preventDefault();
                var fileId = $(this).parent().children("a").data("fileid");

                $(".fileList li").eq(fileId).remove();
                var lilength = $('.fileList li').size();
                console.log(lilength);
                count = lilength;
                console.log(lilength)
                documentIds.splice(fileId, 1);
                console.log(documentIds);

        });

        $("#tickets-paginated .next").live(
                        'click',
                        function() {
                                var searchType = $("#assigneesearchType").val();
                                var ticketStatus = $("#ticketStatus").val();
                                var ticketStatus = $("#ticketStatus").val();
                                var orderBy = $("#orderBy").val();
                                var params;
                                if (searchType == "" || searchType == undefined
                                                || searchType == null || searchType == "TICKET_ID") {
                                        params = {
                                                "ticketStatus" : ticketStatus,
                                                "orderby" : orderBy
                                        };
                                } else {
                                        var searchTerm = $("#assignee-partner-name-input").val();
                                        console.log(searchTerm);
                                        params = {
                                                "ticketStatus" : ticketStatus,
                                                "orderby" : orderBy,
                                                "ticketSearchType" : searchType,
                                                "searchTerm" : searchTerm
                                        };
                                }
                                loadPaginatedNextItems('/cs/myticketPaginated', params,
                                                'tickets-paginated', 'my-ticket-table',
                                                'ticket-details-container');
                                $(this).blur();
                        });

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

                                var ticketStatus = $("#managerTicketStatus").val();
                                var orderBy = $("#managerTicketorderBy").val();
                                var searchType = $("#managersearchType").val();
                                var params;
                                if (searchType == "" || searchType == undefined
                                                || searchType == null || searchType == "TICKET_ID") {
                                        params = {
                                                "ticketStatus" : ticketStatus,
                                                "orderby" : orderBy
                                        };
                                } else {
                                        var searchTerm = $("#partner-name-input").val();
                                        console.log(searchTerm);
                                        params = {
                                                "ticketStatus" : ticketStatus,
                                                "orderby" : orderBy,
                                                "ticketSearchType" : searchType,
                                                "searchTerm" : searchTerm
                                        };
                                }
                                loadPaginatedPreviousItems('/cs/managerTicket-paginated',
                                                params, 'manager-tickets-paginated',
                                                'manager-ticket-table',
                                                'manager-ticket-details-container');
                                $(this).blur();
                        });
        $("#manager-tickets-paginated .next").live(
                        'click',
                        function() {
                                var ticketStatus = $("#managerTicketStatus").val();
                                var orderBy = $("#managerTicketorderBy").val();
                                var searchType = $("#managersearchType").val();
                                var params;
                                if (searchType == "" || searchType == undefined
                                                || searchType == null || searchType == "TICKET_ID") {
                                        params = {
                                                "ticketStatus" : ticketStatus,
                                                "orderby" : orderBy
                                        };
                                } else {
                                        var searchTerm = $("#partner-name-input").val();
                                        console.log(searchTerm);
                                        params = {
                                                "ticketStatus" : ticketStatus,
                                                "orderby" : orderBy,
                                                "ticketSearchType" : searchType,
                                                "searchTerm" : searchTerm
                                        };
                                }

                                loadPaginatedNextItems('/cs/managerTicket-paginated', params,
                                                'manager-tickets-paginated', 'manager-ticket-table',
                                                'manager-ticket-details-container');
                                $(this).blur();
                        });

        $("#tickets-paginated .previous").live(
                        'click',
                        function() {
                                var searchType = $("#assigneesearchType").val();
                                var ticketStatus = $("#ticketStatus").val();
                                var ticketStatus = $("#ticketStatus").val();
                                var orderBy = $("#orderBy").val();
                                var params;
                                if (searchType == "" || searchType == undefined
                                                || searchType == null || searchType == "TICKET_ID") {
                                        params = {
                                                "ticketStatus" : ticketStatus,
                                                "orderby" : orderBy
                                        };
                                } else {
                                        var searchTerm = $("#assignee-partner-name-input").val();
                                        console.log(searchTerm);
                                        params = {
                                                "ticketStatus" : ticketStatus,
                                                "orderby" : orderBy,
                                                "ticketSearchType" : searchType,
                                                "searchTerm" : searchTerm
                                        };
                                }
                                loadPaginatedPreviousItems('/cs/myticketPaginated', params,
                                                '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");
                                                                                                                        } else {
                                                                                                                                alert("You have reached maximum number of tickets Resolved , pls click on Resolved for the resolved tickets to create new.");
                                                                                                                        }
                                                                                                                });

                                                                                        }
                                                                                }
                                                                        }
                                                                });

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

        $("#ticketStatus").live(
                        'change',
                        function() {
                                var ticketStatus = $("#ticketStatus").val();
                                var orderBy = $("#orderBy").val();
                                var searchType = $("#assigneesearchType").val();
                                if (searchType == "" || searchType == undefined
                                                || searchType == null) {
                                        loadMyTicket("main-content", ticketStatus, orderBy, null,
                                                        null, null);
                                } else {
                                        if (searchType == "PARTNER_NAME") {
                                                var searchTerm = $("#assignee-partner-name-input")
                                                                .val();
                                                var searchValue = $("#typeaheadpartnernameforassignee")
                                                                .val();
                                                loadMyTicket("main-content", ticketStatus, orderBy,
                                                                searchType, searchTerm, searchValue);
                                        } else {
                                                var searchTerm = $("#assignee-search-by-ticketId")
                                                                .val();
                                                loadMyTicket("main-content", ticketStatus, orderBy,
                                                                searchType, searchTerm, null);
                                        }
                                }
                        });
        $("#orderBy").live(
                        'change',
                        function() {
                                var ticketStatus = $("#ticketStatus").val();
                                var orderBy = $("#orderBy").val();
                                var searchType = $("#assigneesearchType").val();
                                if (searchType == "" || searchType == undefined
                                                || searchType == null) {
                                        loadMyTicket("main-content", ticketStatus, orderBy, null,
                                                        null, null);
                                } else {
                                        if (searchType == "PARTNER_NAME") {
                                                var searchTerm = $("#assignee-partner-name-input")
                                                                .val();
                                                var searchValue = $("#typeaheadpartnernameforassignee")
                                                                .val();
                                                loadMyTicket("main-content", ticketStatus, orderBy,
                                                                searchType, searchTerm, searchValue);
                                        } else {
                                                var searchTerm = $("#assignee-search-by-ticketId")
                                                                .val();
                                                loadMyTicket("main-content", ticketStatus, orderBy,
                                                                searchType, searchTerm, null);
                                        }
                                }
                        });
        $("#managerTicketStatus").live(
                        'change',
                        function() {
                                var ticketStatus = $("#managerTicketStatus").val();
                                var orderBy = $("#managerTicketorderBy").val();
                                var searchType = $("#managersearchType").val();
                                if (searchType == "" || searchType == undefined
                                                || searchType == null) {
                                        loadManagerTicket("main-content", ticketStatus, orderBy,
                                                        null, null, null);
                                } else {
                                        if (searchType == "PARTNER_NAME") {
                                                var searchTerm = $("#partner-name-input").val();
                                                var searchValue = $("#typeaheadpartnername").val();
                                                loadManagerTicket("main-content", ticketStatus,
                                                                orderBy, searchType, searchTerm, searchValue);
                                        } else {
                                                var searchTerm = $("#search-by-ticketId").val();
                                                loadManagerTicket("main-content", ticketStatus,
                                                                orderBy, searchType, searchTerm, null);
                                        }
                                }

                        });
        $("#managerTicketorderBy").live(
                        'change',
                        function() {
                                var ticketStatus = $("#managerTicketStatus").val();
                                var orderBy = $("#managerTicketorderBy").val();
                                var searchType = $("#managersearchType").val();
                                var searchType = $("#managersearchType").val();
                                if (searchType == "" || searchType == undefined
                                                || searchType == null) {
                                        loadManagerTicket("main-content", ticketStatus, orderBy,
                                                        null, null, null);
                                } else {
                                        if (searchType == "PARTNER_NAME") {
                                                var searchTerm = $("#partner-name-input").val();
                                                var searchValue = $("#typeaheadpartnername").val();
                                                loadManagerTicket("main-content", ticketStatus,
                                                                orderBy, searchType, searchTerm, searchValue);
                                        } else {
                                                var searchTerm = $("#search-by-ticketId").val();
                                                loadManagerTicket("main-content", ticketStatus,
                                                                orderBy, searchType, searchTerm, null);
                                        }
                                }

                        });
        $("#category").live('change', function() {
                var categoryId = $("#category").val();
                $("#auth-user-for-category").hide();
                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();
                                                var fofoIds = $("#partner").val();
                                                if (fofoIds.includes("0")) {
                                                        fofoIds = [ 0 ];
                                                        console.log(fofoIds);
                                                } else {
                                                        console.log(fofoIds);
                                                }
                                                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, fofoIds);
                                                }

                                        });

        $("#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);
                }
        });

        $(".update-position")
                        .live(
                                        'click',
                                        function() {
                                                var positionId = $(this).data('positionid');
                                                var regionId = $(this).data('regionid');

                                                var row = $(this);
                                                var selectedFofoIds = $(this).closest("tr").find(
                                                                '#partners ').val();
                                                if (selectedFofoIds.includes("0")) {
                                                        selectedFofoIds = [ 0 ];
                                                        console.log(selectedFofoIds);
                                                } else {
                                                        console.log(selectedFofoIds);
                                                }
                                                if (confirm("Are you sure you want to update the partners!") == true) {
                                                        doPostAjaxRequestWithJsonHandler(context
                                                                        + "/cs/updatePartnerPosition?regionId="
                                                                        + regionId + "&positionId=" + positionId,
                                                                        JSON.stringify(selectedFofoIds), function(
                                                                                        response) {
                                                                                if (response == "true") {
                                                                                        alert("Update successfully");
                                                                                        loadCreatePosition("main-content");
                                                                                }
                                                                        });
                                                }

                                        });

});

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, ticketStatus, sortOrder, ticketSearchType,
                searchTerm, searchValue) {

        if (ticketStatus == null && sortOrder == null) {
                doGetAjaxRequestHandler(context + "/cs/myticket", function(response) {
                        $('#' + domId).html(response);
                });
        } else if (ticketSearchType == null) {
                doGetAjaxRequestHandler(context + "/cs/myticket?ticketStatus="
                                + ticketStatus + "&orderby=" + sortOrder, function(response) {
                        $('#' + domId).html(response);
                });
        } else {
                doGetAjaxRequestHandler(context + "/cs/myticket?ticketStatus="
                                + ticketStatus + "&orderby=" + sortOrder + "&ticketSearchType="
                                + ticketSearchType + "&searchTerm=" + searchTerm, function(
                                response) {
                        $('#' + domId).html(response);
                        if (ticketSearchType == "PARTNER_NAME") {
                                $('.assigneebyPartnerName').css('display', 'inline-block');
                                $('.assingeebyTicketId').css('display', 'none');
                                $("#typeaheadpartnernameforassignee").val(searchValue);
                                $("#assignee-partner-name-input").val(searchTerm);
                        } else {
                                $('.assigneebyPartnerName').css('display', 'none');
                                $('.assigneebyTicketId').css('display', 'inline-block');
                                $("#assignee-search-by-ticketId").val(searchTerm);
                        }
                });
        }
}

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, categoryId) {
        var params = {
                "ticketId" : ticketId,
                "subCategoryId" : subCategoryId,
                "authUserId" : authUserId,
                "categoryId" : categoryId
        }
        doPostAjaxRequestWithParamsHandler(context + "/cs/edit-ticket", params,
                        function(response) {
                                if (response == "true") {
                                        alert("Ticket changed successfully");
                                        loadManagerTicket("main-content", null, null, null, null,
                                                        null);
                                }
                        });
}
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, ticketStatus, sortOrder, ticketSearchType,
                searchTerm, searchValue) {
        if (ticketStatus == null && sortOrder == null) {
                doGetAjaxRequestHandler(context + "/cs/managerTicket", function(
                                response) {
                        $('#' + domId).html(response);
                });
        } else if (ticketSearchType == null) {
                doGetAjaxRequestHandler(context + "/cs/managerTicket?ticketStatus="
                                + ticketStatus + "&orderby=" + sortOrder, function(response) {
                        $('#' + domId).html(response);
                });
        } else {
                doGetAjaxRequestHandler(context + "/cs/managerTicket?ticketStatus="
                                + ticketStatus + "&orderby=" + sortOrder + "&ticketSearchType="
                                + ticketSearchType + "&searchTerm=" + searchTerm, function(
                                response) {
                        $('#' + domId).html(response);
                        if (ticketSearchType == "PARTNER_NAME") {
                                $('.byPartnerName').css('display', 'inline-block');
                                $('.byTicketId').css('display', 'none');
                                $("#typeaheadpartnername").val(searchValue);
                                $("#partner-name-input").val(searchTerm);
                        } else {
                                $('.byPartnerName').css('display', 'none');
                                $('.byTicketId').css('display', 'inline-block');
                                $("#search-by-ticketId").val(searchTerm);
                        }
                });
        }
}
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 createLastActivity(ticketId, activity) {
        var params = {
                "ticketId" : ticketId,
                "lastactivity" : activity
        }
        doPostAjaxRequestWithParamsHandler(context + "/cs/create-last-activity",
                        params, function(response) {
                                if (response == "true") {
                                        alert("successfully mark last activity");
                                        loadMyTicket("main-content", null, null);
                                }
                        });
}

function createPosition(domId, authUserId, categoryId, escalationType,
                regionId, fofoIds) {

        var createPositionModel = {};
        createPositionModel['authUserId'] = authUserId;
        createPositionModel['categoryId'] = categoryId
        createPositionModel['escalationType'] = escalationType;
        createPositionModel['regionId'] = regionId,
                        createPositionModel['fofoIds'] = fofoIds

        console.log(createPositionModel);
        doPostAjaxRequestWithJsonHandler(context + "/cs/createPosition", JSON
                        .stringify(createPositionModel), function(response) {
                if (response == "true") {
                        alert("Position created successfully");
                        loadCreatePosition(domId);
                }
        });
}
function createActivity(message, ticketId, assigneeId, internal, roleType,
                documentIds) {

        var params = {
                "message" : message,
                "ticketId" : ticketId,
                "assigneeId" : assigneeId,
                "internal" : internal,
                "documentIds" : documentIds,
        }
        if (documentIds.includes("0")) {
                documentIds = [ 0 ];
                console.log(documentIds);
        } else {
                console.log(documentIds);
        }
        console.log(JSON.stringify(documentIds))
        doPostAjaxRequestWithJsonHandler(context + "/cs/createActivity?message="
                        + message + "&ticketId=" + ticketId + "&assigneeId=" + assigneeId
                        + "&internal=" + internal, JSON.stringify(documentIds), function(
                        response) {
                response = JSON.parse(response);

                documentIds.splice(0, documentIds.length);
                count = 0;
                console.log(documentIds)
                $(".fileList li").empty();
                var assigneeName = response.firstName;
                loadActivities(ticketId, assigneeName, internal, roleType)
        });
}
function loadEditTicket(ticketId) {
        doGetAjaxRequestHandler(context + "/cs/edit-ticket?ticketId=" + ticketId,
                        function(response) {
                                $("#theModal .modal-content").html(response);

                        });
}
function loadPartnerForRegion(regionId) {
        doGetAjaxRequestHandler(context + "/cs/getPartners?regionId=" + regionId,
                        function(response) {
                                $("#partner-region-container").html(response);
                        });
}

function loadPartnerForRegionId(regionId) {
        doGetAjaxRequestHandler(context + "/cs/getPartnersByRegion?regionId="
                        + regionId, function(response) {
                $("#partner-subregion-container").html(response);
        });
}

function loadAccessManagement(domId) {
        doGetAjaxRequestHandler(context + "/admin/access-management", function(
                        response) {
                $('#' + domId).html(response);
        });
}

function loadActivities(ticketId, assignee, internal, roleType) {

        $(".activity-container .modal-body").empty();
        $("#activityMessage").val("");
        $("#ticketIdforactivity").val(ticketId);
        $("#role").val(roleType);
        $(".activity-container .modal-title").html(
                        "Activity history for Ticket Id " + ticketId)
        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++) {
                                        console.log(response[i].activityAttachment.length);
                                        var activityAttachment = []
                                        var attachments = "";
                                        if (response[i].activityAttachment.length > 0) {
                                                for (var j = 0; j < response[i].activityAttachment.length; j++) {
                                                        var assigneeAttachment = "<div> <a href=\"javascript:void(0)\" style=\"color:#337ab7;float:right;\"onclick=\"downloadDocument("
                                                                        + response[i].activityAttachment[j].documentId
                                                                        + ",\`"
                                                                        + response[i].activityAttachment[j].documentName
                                                                        + "\`)\">"
                                                                        + response[i].activityAttachment[j].documentName
                                                                        + "&nbsp;<i class=\"fa fa-download\"></i>"
                                                                        + "</a> </div>"
                                                        activityAttachment.push(assigneeAttachment);
                                                }
                                                attachments = activityAttachment.join("");
                                                console.log(attachments);
                                        }
                                        if (response[i].type == "OPENED"
                                                        || response[i].type == "COMMUNICATION_IN") {

                                                var partnerMessage = "<div class=\"incoming_msg\">"
                                                                + "<div class=\"received_msg\">"
                                                                + "<div class=\"received_withd_msg\">" + "<p>"
                                                                + response[i].message + "</p>"
                                                                + `${attachments}`
                                                                + "<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);

                                        } else if (response[i].type == "COMMUNICATION_OUT") {
                                                var assigneeMessage = "<div class=\"outgoing_msg\">"
                                                                + "<div class=\"sent_msg\">"
                                                                + "<span style=color:green>"
                                                                + "~"
                                                                + (response[i].name ? response[i].name
                                                                                : "Support") + "<p>"
                                                                + response[i].message + "</span> </p>"
                                                                + `${attachments}`
                                                                + "<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);

                                        } else if (response[i].name
                                                        && response[i].type == "COMMUNICATION_INTERNAL") {
                                                var assigneeMessage = "<div class=\"outgoing_msg\">"
                                                                + "<div class=\"sent_msg\">"
                                                                + "<span style=color:green>"
                                                                + "~"
                                                                + response[i].name
                                                                + "<p style=\"color: white;background: #b75454;\">"
                                                                + response[i].message + "</span> </p>"
                                                                + `${attachments}`
                                                                + " <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);

                                        } else {
                                                var assigneeMessage = "<div class=\"outgoing_msg\">"
                                                                + "<div class=\"sent_msg\">" + "<p>"
                                                                + response[i].message + "</span> </p>"
                                                                + `${attachments}`
                                                                + "<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);

                                        }

                                }
                                if (roleType == "true" || roleType == true) {
                                        $('.internalCheckBox').css('display', 'block');
                                        if (internal == true || internal == "true") {
                                                $('#internalCommunication').prop('checked', true);
                                        } else {
                                                $('#internalCommunication').prop('checked', false);
                                        }

                                } else {
                                        $('.internalCheckBox').css('display', 'none');
                                }
                        });
}

function downloadDocument(documentId, documentName) {
        console.log(documentName)
        doAjaxGetDownload(context + "/download?documentId=" + documentId,
                        documentName);
}