Subversion Repositories SmartDukaan

Rev

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

$(function () {
        $(document).on('click', ".create-service", function () {
                loadService("main-content");
        });

        $(document).on('click', ".add-brand", function () {
                loadaddBrandToService("main-content");
        });

        $(document).on('click', ".notApplicableBrandService",
                function () {
                        naCommentService = $(this).data('nacommentservice');
                        console.log(naCommentService);
                        var dialog = bootbox.dialog({
                                message: "<h4 style='color:red'>NOTAPPLICABLE</h4><p>"
                                        + naCommentService + "</p>",
                                closeButton: true
                        });
                        dialog.modal('show');

                });
        $(document).on('click', ".add-brand", function () {
                loadaddBrandToService("main-content");
        });
        $(document).on('click', ".activate-brand-service-modal", function () {
                console.log("activate-brand-service-modal clicked");
                serviceId = $(this).data('serviceid');
                fofoId = $("#partnerName").val();
                serviceBrandId = $(this).data('servicebrandid');
                console.log(fofoId);
                console.log(serviceId);
                console.log(serviceBrandId);
                var params = {
                        "serviceId": serviceId,
                        "fofoId": fofoId,
                        "serviceBrandId": serviceBrandId

                }
                doPostAjaxRequestWithParamsHandler(context
                        + "/activatePartnerbrandServiceModal", params, function (response) {

                        $('#myServiceActivateBrand').html(response);

                });


        });

        $(document).on('click', ".submit-brand-not-available", function () {

                console.log("submit-brand-not-available");
                serviceId = $(this).data('serviceid');
                fofoId = $("#partnerName").val();
                serviceBrandId = $(this).data('servicebrandid');
                na_comment = $('input[name="reasonBrandNotAvailable"]').val();
                active = false;
                partnerStatus = "NOTWORKING";
                applicableType = "NO";

                if (na_comment == "" || na_comment == undefined) {
                        alert("Na_comment can't be empty");
                        return;
                }

                addPartnerServiceBrandDetails(fofoId, serviceId,
                        serviceBrandId, applicableType, active,
                        partnerStatus, na_comment);
                $('#myServiceActivateBrand').modal('hide');
                $('.modal-backdrop').remove();

        });

        $(document).on('click', ".reason-brand-service-not-activates", function () {

                console.log("reason-brand-service-not-activates clicked");
                serviceId = $(this).data('serviceid');
                fofoId = $("#partnerName").val();
                serviceBrandId = $(this).data('servicebrandid');
                var serviceBrandComment = $('input[name="reasonBrandServiceNotActivate"]').val();
                console.log(fofoId);
                console.log(serviceId);
                console.log(serviceBrandId);
                console.log(serviceBrandComment);
                reasonPartnerbrandServiceNotActivate(fofoId, serviceId, serviceBrandId, serviceBrandComment);

        });


        $(document).on('click', ".service-comment", function () {
                serviceId = $(this).data('serviceid');
                fofoId = $(this).data('fofoid');
                var row = $(this).closest("tr");

                bootbox.dialog({
                        title: "Comment!",
                        message: "<div class=form-inline'>"
                                + "<label for='code'>comment :</label>"
                                + "<input class='form-control' type='text' id='naTextComment'/>"
                                + "</div>",
                        buttons: {
                                cancel: {
                                        label: "CANCEL",
                                        className: 'btn-danger',
                                        callback: function () {
                                                return;
                                        }
                                },
                                ok: {
                                        label: "OK",
                                        className: 'btn-info',
                                        callback: function () {
                                                naText = $('#naTextComment').val();
                                                if (naText == "" || naText == undefined || naText == null) {
                                                        alert("Comment text can't be empty");
                                                        return;
                                                }
                                                var params = {
                                                        "serviceId": serviceId,
                                                        "fofoId": fofoId,
                                                        "naText": naText
                                                }
                                                doPostAjaxRequestWithJsonHandler(context + "/addPartnerServiceGenComment",
                                                        JSON.stringify(params), function (response) {
                                                                alert("Successfully Submitted");
                                                                row.html(response);

                                                        });
                                        }
                                }
                        }
                });
        });


        $(document).on('click', ".follow-up-date", function () {
                serviceId = $(this).data('serviceid');
                fofoId = $(this).data('fofoid');
                gencomment = $(this).data('gencomment');
                console.log("fofoId" + fofoId);
                var row = $(this).closest("tr");

                bootbox.dialog({
                        title: "Follow Up Date",
                        message: "<div class=form-inline'>"
                                + "<label for='followUpDate'>Follow Up Date:</label>"
                                + "<input class='form-control' type='date' id='followUpDate'/>"
                                + "</div>",
                        buttons: {
                                cancel: {
                                        label: "CANCEL",
                                        className: 'btn-danger',
                                        callback: function () {
                                                return;
                                        }
                                },
                                ok: {
                                        label: "OK",
                                        className: 'btn-info',
                                        callback: function () {
                                                followUpDate = $('#followUpDate').val();


                                                var params = {
                                                        "serviceId": serviceId,
                                                        "fofoId": fofoId,
                                                        "naText": gencomment,
                                                        "followUpDate": followUpDate

                                                }


                                                doPostAjaxRequestWithJsonHandler(context + "/addPartnerServiceFollowupDate",
                                                        JSON.stringify(params), function (response) {
                                                                alert("Successfully Submit");
                                                                row.html(response);

                                                        });
                                        }
                                }
                        }
                });
        });

        $(document).on('click', ".service-mark-not-active", function () {
                serviceId = $(this).data('serviceid');
                fofoId = $(this).data('fofoid');
                var row = $(this).closest("tr");

                bootbox.dialog({
                        title: "Mark Not Applicable!",
                        message: "<div class=form-inline'>"
                                + "<label for='code'>Not Applicable Reason:</label>"
                                + "<input class='form-control' type='text' id='naText'/>"
                                + "</div>",
                        buttons: {
                                cancel: {
                                        label: "CANCEL",
                                        className: 'btn-danger',
                                        callback: function () {
                                                return;
                                        }
                                },
                                ok: {
                                        label: "OK",
                                        className: 'btn-info',
                                        callback: function () {
                                                naText = $('#naText').val();
                                                if (naText == "" || naText == undefined || naText == null) {
                                                        alert("NA text can't be empty");
                                                        return;
                                                }
                                                var params = {
                                                        "serviceId": serviceId,
                                                        "fofoId": fofoId,
                                                        "naText": naText
                                                }
                                                doPostAjaxRequestWithJsonHandler(context + "/addPartnerServiceNotavailable",
                                                        JSON.stringify(params), function (response) {
                                                                alert("Successfully Marked NA");
                                                                row.html(response);

                                                        });
                                        }
                                }
                        }
                });
        });

        $(document).on('click', ".markNA", function () {
                let fofoId = $('#partnerName').val();
                let serviceId = $(this).data("serviceid");
                bootbox.dialog({
                        title: "Mark Not Applicable!",
                        message: "<div class=form-inline'>"
                                + "<label for='code'>Not Applicable Reason:</label>"
                                + "<input class='form-control' type='text' id='naText'/>"
                                + "</div>",
                        buttons: {
                                cancel: {
                                        label: "CANCEL",
                                        className: 'btn-danger',
                                        callback: function () {
                                                return;
                                        }
                                },
                                ok: {
                                        label: "OK",
                                        className: 'btn-info',
                                        callback: function () {
                                                naText = $('#naText').val();
                                                if (naText == "" || naText == undefined || naText == null) {
                                                        alert("NA text can't be empty");
                                                        return;
                                                }
                                                var params = {
                                                        "serviceId": serviceId,
                                                        "fofoId": fofoId,
                                                        "naText": naText
                                                }
                                                doPostAjaxRequestWithJsonHandler(context + "/partnerservice/applicable",
                                                        JSON.stringify(params), function (response) {
                                                                alert("Successfully Marked NA");
                                                                loadAdminPartnerService("main-content", fofoId);
                                                        });
                                        }
                                }
                        }
                });
        });
        $(document).on('click', ".markApplicable", function () {
                let serviceId = $(this).data("serviceid");
                if (confirm("Confirm?")) {
                        let fofoId = $('#partnerName').val();
                        var params = {
                                "serviceId": serviceId,
                                "fofoId": fofoId,
                                "naText": null
                        }
                        doPostAjaxRequestWithJsonHandler(context + "/partnerservice/applicable", JSON.stringify(params), function (response) {
                                alert("successfully Marked Applicable");
                                loadAdminPartnerService("main-content", fofoId);
                        });

                }
        });

        $(document).on('click', ".add-service-details-for-partner",
                function () {
                        fofoId = $("#partnerName").val();
                        serviceId = $("#serviceName").val();
                        applicableType = $("#applicableService").val();
                        code = $("#code").val();
                        partnerStatus = $("#partnerStatusTypeServices").val();
                        na_comment = $("#na_comment_services").val();
                        partnerCommentStatus = $("#partner_comment_status").val();
                        if (applicableType == "" || applicableType == null
                                || applicableType == undefined) {
                                alert("select appropriate applicableType");
                        } else if (applicableType == 'NO') {
                                if (na_comment == "" || na_comment == undefined) {
                                        alert("Na_comment can't be empty");
                                        return;
                                }
                                if (fofoId == "" || fofoId == null || fofoId == undefined) {
                                        alert("select appropriate partnerName");
                                        return;
                                }
                                if (serviceId == "" || serviceId == null
                                        || serviceId == undefined) {
                                        alert("select appropriate serviceName");
                                        return;
                                }
                        } else {
                                if (fofoId == "" || fofoId == null || fofoId == undefined) {
                                        alert("select appropriate partnerName");
                                        return;
                                }
                                if (serviceId == "" || serviceId == null
                                        || serviceId == undefined) {
                                        alert("select appropriate serviceName");
                                        return;
                                }
                                if (code == "" || code == null
                                        || code == undefined) {
                                        alert("enter appropriate code")
                                        return;
                                }
                        }
                        console.log(fofoId, serviceId, applicableType, code,
                                partnerStatus);
                        addPartnerServiceDetails(fofoId, serviceId, applicableType,
                                code, partnerStatus, na_comment,
                                partnerCommentStatus);

                });
        $(document).on('click', ".add-brand-service-details-for-partner",
                function () {
                        fofoId = $("#partnerName").val();
                        serviceId = $("#serviceName").val();
                        serviceBrandId = $("#serviceBrandName").val();
                        applicableType = $("#applicableService").val();
                        active = $("#activeServiceBrand").val();
                        partnerStatus = $("#partnerStatusTypeServices").val();
                        na_comment = $("#na_comment_services").val();
                        partnerCommentStatus = $("#partner_comment_status").val();
                        if (applicableType == "NO") {
                                if (na_comment == "" || na_comment == undefined) {
                                        alert("Na_comment can't be empty");
                                        return;
                                }
                        }
                        if (fofoId == "" || fofoId == null || fofoId == undefined) {
                                alert("select appropriate partnerName");
                                return;
                        } else if (serviceBrandId == "" || serviceBrandId == null
                                || serviceBrandId == undefined) {
                                alert("select appropriate serviceBrandId");
                                return;
                        } else if (applicableType == "" || applicableType == null
                                || applicableType == undefined) {
                                alert("select appropriate applicableType");
                        } else if (active == "" || active == null
                                || active == undefined) {
                                alert("select appropriate active")
                        } else if (partnerStatus == "" || partnerStatus == null
                                || partnerStatus == undefined) {
                                alert("select appropriate partnerStatus");
                        } else {
                                console.log(fofoId, serviceBrandId, applicableType, active,
                                        partnerStatus);
                                addPartnerServiceBrandDetails(fofoId, serviceId,
                                        serviceBrandId, applicableType, active,
                                        partnerStatus, na_comment, partnerCommentStatus);
                        }
                });
        $(document).on('click', ".partner-service", function () {
                loadpartnerService("main-content");
        });
        $(document).on('click', ".admin-partner-service", function () {
                loadAdminPartnerService("main-content", 0);
        });

        $(document).on('click', ".partner-finance-services", function () {
                showFinanceServices("main-content");

        });

        $(document).on('click', ".add-partner-service-details", function () {
                loadaddPartnerServiceDetails("main-content");
        });
        $(document).on('click', ".add-partner-brand-service-details", function () {
                loadaddPartnerBrandServiceDetails("main-content");
        });
        $(document).on('click', ".service-mark-active", function () {
                serviceId = $(this).data('serviceid');
                fofoId = $(this).data('fofoid');
                var row = $(this).closest("tr");
                console.log(fofoId);
                console.log(serviceId);
                console.log(row);
                activateFinanceServices(fofoId, serviceId, row);
        });


        $(document).on('click', ".activate-service", function () {
                serviceId = $(this).data('serviceid');
                fofoId = $("#partnerName").val();
                console.log(fofoId);
                console.log(serviceId);
                activatePartnerService(fofoId, serviceId);
        });
        $(document).on('click', ".deactivate-service", function () {
                serviceId = $(this).data('serviceid');
                fofoId = $("#partnerName").val();
                console.log(fofoId);
                console.log(serviceId);
                deActivatePartnerService(fofoId, serviceId);
        });
        $(document).on('click', ".activate-brand-service", function () {
                console.log("activate-brand-servicel clicked");
                serviceId = $(this).data('serviceid');
                fofoId = $("#partnerName").val();
                serviceBrandId = $(this).data('servicebrandid');
                console.log(fofoId);
                console.log(serviceId);
                console.log(serviceBrandId);
                activatePartnerBrandService(fofoId, serviceId, serviceBrandId);

        });
        $(document).on('click', ".deactivate-brand-service", function () {
                console.log("activate-brand-service clicked");
                serviceId = $(this).data('serviceid');
                fofoId = $("#partnerName").val();
                var serviceBrandComment = $('input[name="reasonBrandServiceNotActivate"]').val();
                serviceBrandId = $(this).data('servicebrandid');
                console.log(fofoId);
                console.log(serviceId);
                console.log(serviceBrandId);
                console.log(serviceBrandComment);
                deActivatePartnerBrandService(fofoId, serviceId, serviceBrandId, serviceBrandComment);

        });
        $(document).on('click', ".partner-not-interested-service", function () {

                serviceId = $(this).data('serviceid');
                fofoId = $("#partnerName").val();
                var partnerNotInterestedComment = $('input[name="reasonPartnerNotInterested"]').val();

                console.log(fofoId);
                console.log(serviceId);
                console.log(partnerNotInterestedComment);

                if (partnerNotInterestedComment == "" || partnerNotInterestedComment == undefined) {
                        alert("Comment Should Be Filled");
                        return;
                }


                deActivatePartnerServiceByPartner(fofoId, serviceId, partnerNotInterestedComment);

        });


        $(document).on('click', ".service-mark-pni", function () {

                serviceId = $(this).data('serviceid');
                fofoId = $(this).data('fofoid');
                var partnerNotInterestedComment = "Partner Not Interested"
                var row = $(this).closest("tr");
                console.log(fofoId);
                console.log(serviceId);
                console.log(row);


                deActivateFinanceServicePartnerNotInterested(fofoId, serviceId, partnerNotInterestedComment, row);

        });

        $(document).on('click', ".action-on-brand", function () {
                serviceId = $(this).data('serviceid');
                fofoId = $(this).data('fofoid');
                brandid = $(this).data('brandid');
                var row = $(this).closest("tr");

                console.log(fofoId);
                console.log(serviceId);
                console.log(brandid);
                actionFinanceBrandService(fofoId, serviceId, brandid, row);

        });


        $(document).on('click', ".deactivate-brand-service-modal", function () {
                console.log("activate-brand-service clicked");
                serviceId = $(this).data('serviceid');
                fofoId = $("#partnerName").val();
                serviceBrandId = $(this).data('servicebrandid');
                console.log(fofoId);
                console.log(serviceId);
                console.log(serviceBrandId);
                var params = {
                        "serviceId": serviceId,
                        "fofoId": fofoId,
                        "serviceBrandId": serviceBrandId

                }
                doPostAjaxRequestWithParamsHandler(context
                        + "/deactivatePartnerbrandServiceModal", params, function (response) {

                        $('#myServiceDeActivateBrand').html(response);

                });
        });

        $(document).on('click', ".notApplicableByPartner", function () {
                console.log("notApplicableByPartner");

                serviceId = $(this).data('serviceid');
                fofoId = $("#partnerName").val();

                console.log(fofoId);
                console.log(serviceId);

                var params = {
                        "serviceId": serviceId,
                        "fofoId": fofoId,

                }
                doPostAjaxRequestWithParamsHandler(context
                        + "/deactivatePartnerbrandServiceModal", params, function (response) {

                        $('#serviceDeactivateByPartnerModal').html(response);

                });
        });


        $(document).on('click', ".create-service-button",
                function () {
                        console.log("create-service-button clicked");
                        var serviceName = $('#createserviceName').val();
                        if (serviceName === "" || serviceName === undefined
                                || serviceName == null) {
                                alert("Input field can't be empty");
                                return;
                        }
                        if (confirm("Are you sure you want to create Service!") == true) {
                                createService("main-content", serviceName);
                        }
                });
        $(document).on('click', ".partner-service-search-button",
                function () {
                        var fofoId = $('#partnerName').val();
                        if (fofoId === "" || fofoId === undefined || fofoId == null) {
                                alert("select appropriate partner");
                                return;
                        }
                        doGetAjaxRequestHandler(context + "/getPartnerServices?fofoId="
                                + fofoId, function (response) {
                                $('#' + "partnerServicesByID").html(response);
                        });
                });
        $(document).on('click', "#remove-added-brand-button",
                function () {
                        var serviceId = $(this).data('id');
                        var brand = $(this).data('brand');
                        console.log(serviceId);
                        console.log(brand)
                        if (confirm("Are you sure you want to remove brand from Service!") == true) {
                                removeBrandFromService("main-content", serviceId,
                                        brand);
                        }
                });
        $(document).on('click', ".service-brand-button", function () {
                var brands = $('#tag-listing-brands').val();
                var serviceId = $('#serviceName').val();
                console.log(brands);
                console.log(serviceId);
                if (serviceId === "" || serviceId === undefined) {
                        alert("service not selected");
                        return;
                }
                if (!brands) {
                        alert("select brand");
                        return;
                }
                if (confirm("Are you sure you want to add brand!") == true) {
                        addBrandToService("main-content", brands, serviceId);
                }
        });
        $(document).on('change', '#serviceName', function () {
                // $('#tag-listing-brand-value').text($(this).text());
                loadBrandsByServiceId("service-container", $(this).val());
                loadaddedBrandsbyserviceId("added-brand-to-service", $(this).val())
        });
});

function addPartnerServiceDetails(fofoId, serviceId, applicableType, code,
                                                                  partnerStatus, na_comment, partnerCommentStatus) {
        if (confirm("Are you sure you want to add services details!") == true) {
                var params = {
                        "serviceId": serviceId,
                        "fofoId": fofoId,
                        "applicableType": applicableType,
                        "partnerStatus": partnerStatus,
                        "na_comment": na_comment,
                        "partnerCommentStatus": partnerCommentStatus,
                        "code": code
                }
                doPostAjaxRequestWithParamsHandler(context
                        + "/addPartnerServicesDetails", params, function (response) {
                        if (response == "true") {
                                alert("successfully added partner Service Details");
                                loadaddPartnerServiceDetails("main-content");
                        }
                });
        }
}

function reasonPartnerbrandServiceNotActivate(fofoId, serviceId, serviceBrandId, serviceBrandComment) {
        if (confirm("Are you sure you want to activate brand service!") == true) {
                var params = {
                        "serviceId": serviceId,
                        "fofoId": fofoId,
                        "serviceBrandId": serviceBrandId,
                        "serviceBrandComment": serviceBrandComment

                }
                doPostAjaxRequestWithParamsHandler(context
                        + "/reasonPartnerbrandServiceNotActivate", params, function (response) {
                        if (response == "true") {
                                alert("successfully set your Comment for brand service not activated");
                                $('#myServiceActivateBrand').modal('hide');
                                $('.modal-backdrop').remove();
                                loadAdminPartnerService("main-content", fofoId);
                        }
                });
        }
}

function addPartnerServiceBrandDetails(fofoId, serviceId, serviceBrandId,
                                                                           applicableType, active, partnerStatus, na_comment,
                                                                           partnerCommentStatus, code) {
        if (confirm("Are you sure you want to add service brand details!") == true) {
                var params = {
                        "serviceId": serviceId,
                        "serviceBrandId": serviceBrandId,
                        "fofoId": fofoId,
                        "applicableType": applicableType,
                        "active": active,
                        "partnerStatus": partnerStatus,
                        "na_comment": na_comment,
                        "partnerCommentStatus": partnerCommentStatus,

                }
                console.log("params" + params);
                doPostAjaxRequestWithParamsHandler(context
                        + "/addPartnerServiceBrandDetails", params, function (response) {
                        if (response == "true") {
                                alert("successfully added partner Service Brand Details");
                                loadaddPartnerBrandServiceDetails("main-content");
                        }
                });
        }
}

function configureBrandsDropDown() {
        $('#tag-listing-brands').multiselect({
                includeSelectAllOption: true,
                multiple: true,
                maxHeight: 200,
                buttonWidth: '180px',
                numberDisplayed: 1,
                nonSelectedText: 'Brands',
                nSelectedText: ' - Brands Selected',
                allSelectedText: 'All Brands Selected',
                enableFiltering: true,
                enableCaseInsensitiveFiltering: true
        });
}

function loadService(domId) {
        doGetAjaxRequestHandler(context + "/getcreateService", function (response) {
                $('#' + domId).html(response);
        });
}

function loadaddedBrandsbyserviceId(domId, serviceId) {
        doGetAjaxRequestHandler(context + "/getAddedbrands?serviceId=" + serviceId,
                function (response) {
                        $('#' + domId).html(response);
                });
}

function loadBrandsByServiceId(domId, serviceId) {
        doGetAjaxRequestHandler(context + "/getbrands?serviceId=" + serviceId,
                function (response) {
                        $('#' + domId).html(response);
                        configureBrandsDropDown();
                });

}

function createService(domId, serviceName) {
        console.log(serviceName);
        doPostAjaxRequestHandler(context + "/createService?serviceName="
                + serviceName, function (response) {
                alert("Service Successfully Created");
                $('#' + domId).html(response);
        });
}

function loadaddBrandToService(domId) {
        doGetAjaxRequestHandler(context + "/addBrandsToService",
                function (response) {
                        $('#' + domId).html(response);
                });
}

function addBrandToService(domId, brands, serviceId) {
        doPostAjaxRequestWithJsonHandler(context + "/addBrandsService?serviceId="
                + serviceId, JSON.stringify(brands), function (response) {
                alert("Brands added successfully");
                loadBrandsByServiceId("service-container", serviceId);
                loadaddedBrandsbyserviceId("added-brand-to-service", serviceId)
                $('#' + domId).html(response);
        });
}

function removeBrandFromService(domId, serviceId, brand) {

        doDeleteAjaxRequestHandler(context + "/removeBrandfromService?serviceId="
                + serviceId + "&brand=" + brand, function (response) {
                alert("Brand removed from service successfully");
                loadBrandsByServiceId("service-container", serviceId);
                loadaddedBrandsbyserviceId("added-brand-to-service", serviceId)
                $('#' + domId).html(response);
        });
}

function showFinanceServices(domId) {
        doGetAjaxRequestHandler(context + "/getFinanceServicesAllPartner", function (response) {

                $('#' + domId).html(response);
        });
}


function changeServices(partnerServiceId) {
        var serviceId = partnerServiceId.value;
        var fofoId = $("#partnerName").val();
        console.log(fofoId);
        console.log(serviceId);
        if (fofoId == "" || fofoId == 0 || fofoId == undefined) {
                var dialog = bootbox
                        .dialog({
                                title: "Are you sure want to change state of service!",
                                message: "<div class=form-inline'>"
                                        + "<label for='reason'>Reason:</label>"
                                        + "<textarea class='form-control' rows='1' id='reason'></textarea>"
                                        + "</div>",
                                buttons: {
                                        cancel: {
                                                label: "cancel",
                                                className: 'btn-danger',
                                                callback: function () {
                                                        loadpartnerService("main-content");
                                                }
                                        },
                                        ok: {
                                                label: "ok",
                                                className: 'btn-info',
                                                callback: function () {
                                                        partnerStatusComment = $('#reason').val();
                                                        console.log(partnerStatusComment);
                                                        var params = {
                                                                "serviceId": serviceId,
                                                                "partnerStatusComment": partnerStatusComment
                                                        }
                                                        doPostAjaxRequestWithParamsHandler(
                                                                context + "/changeStatePartnerService",
                                                                params,
                                                                function (response) {
                                                                        if (response == "true") {
                                                                                alert("successfully changed");
                                                                                loadpartnerService("main-content");
                                                                        }
                                                                });

                                                }
                                        }
                                }
                        });

        } else {
                if (confirm("Are you sure you want to change!") == true) {
                        var params = {
                                "serviceId": serviceId,
                                "fofoId": fofoId

                        }
                        doPostAjaxRequestWithParamsHandler(context
                                + "/changeStatePartnerService", params, function (response) {
                                if (response == "true") {
                                        alert("successfully changed");
                                        loadAdminPartnerService("main-content", fofoId);
                                }
                        });
                } else {
                        loadAdminPartnerService("main-content", fofoId);
                }
        }
}

function changeServiceNameForServiceBrand() {

        serviceId = $("#serviceName").val();
        console.log(serviceId);
        doGetAjaxRequestHandler(context + "/selectAddedbrands?serviceId="
                + serviceId, function (response) {
                $('#' + "serviceBrandNameContainer").html(response);
        });
}

function configureAllPartnerName() {
        $(document).ready(function () {
                $('#partnerName').multiselect({
                        includeSelectAllOption: true,
                        maxHeight: 200,
                        buttonWidth: '200px',
                        numberDisplayed: 1,
                        nonSelectedText: 'Partners',
                        nSelectedText: ' - Partners Selected',
                        allSelectedText: 'All Partners Selected',
                        enableFiltering: true,
                        enableCaseInsensitiveFiltering: true

                });
        });
}


function onChangeStateServiceBrand(partnerServiceBrandId, partnerServiceId, brand) {


        console.log(brand);

        var brandServiceId = partnerServiceBrandId.value;
        var fofoId = $("#partnerName").val();
        console.log(brandServiceId, partnerServiceId);
        if (fofoId == "" || fofoId == 0 || fofoId == undefined) {
                var dialog = bootbox
                        .dialog({
                                title: "Are you sure want to change state of service!",
                                message: "<div class=form-inline'>"
                                        + "<label for='reason'>Reason:</label>"
                                        + "<textarea class='form-control' rows='1' id='reason'></textarea>"
                                        + "</div>",
                                buttons: {
                                        cancel: {
                                                label: "cancel",
                                                className: 'btn-danger',
                                                callback: function () {
                                                        loadpartnerService("main-content");
                                                }
                                        },
                                        ok: {
                                                label: "ok",
                                                className: 'btn-info',
                                                callback: function () {
                                                        partnerStatusComment = $('#reason').val();
                                                        console.log(partnerStatusComment);
                                                        var params = {
                                                                "brand": brand,
                                                                "brandServiceId": brandServiceId,
                                                                "serviceId": partnerServiceId,
                                                                "partnerStatusComment": partnerStatusComment
                                                        }
                                                        doPostAjaxRequestWithParamsHandler(
                                                                context
                                                                + "/changeStatePartnerServiceBrand",
                                                                params,
                                                                function (response) {
                                                                        if (response == "true") {
                                                                                alert("successfully changed");
                                                                                loadpartnerService("main-content");
                                                                        }

                                                                });

                                                }
                                        }
                                }
                        });
        } else {
                if (confirm("Are you sure you want to change!") == true) {

                        var params = {
                                "brandServiceId": brandServiceId,
                                "brand": brand,
                                "serviceId": partnerServiceId,
                                "fofoId": fofoId

                        }
                        doPostAjaxRequestWithParamsHandler(context
                                + "/changeStatePartnerServiceBrand", params, function (
                                response) {
                                if (response == "true") {
                                        alert("successfully changed");
                                        loadAdminPartnerService("main-content", fofoId);
                                }
                        });

                } else {

                        loadAdminPartnerService("main-content", fofoId);
                }
        }
}

function loadpartnerService(domId) {
        doGetAjaxRequestHandler(context + "/getPartnerServices",
                function (response) {
                        $('#' + domId).html(response);
                });

}

function loadAdminPartnerService(domId, fofoId) {
        doGetAjaxRequestHandler(context
                + "/getAdminPanelForPartnerServices?fofoId=" + fofoId, function (
                response) {
                $('#' + domId).html(response);
                if (fofoId != 0 || fofoId) {
                        doGetAjaxRequestHandler(context + "/getPartnerServices?fofoId="
                                + fofoId, function (response) {
                                $('#' + "partnerServicesByID").html(response);
                        });
                }

        });
}

function activatePartnerService(fofoId, serviceId) {
        console.log(fofoId);
        bootbox.dialog({
                title: "Are you sure you want to activate services!",
                message: "<div class=form-inline'>"
                        + "<label for='code'>Code:</label>"
                        + "<input class='form-control' type='text' id='code'/>"
                        + "</div>",
                buttons: {
                        cancel: {
                                label: "cancel",
                                className: 'btn-danger',
                                callback: function () {
                                        return;
                                }
                        },
                        ok: {
                                label: "ok",
                                className: 'btn-info',
                                callback: function () {
                                        code = $('#code').val();
                                        //console.log(partnerStatusComment);
                                        if (code == "" || code == undefined || code == null) {
                                                alert("code can't be empty");
                                                activatePartnerService(fofoId, serviceId);
                                                return;
                                        }
                                        var params = {
                                                "serviceId": serviceId,
                                                "fofoId": fofoId,
                                                "code": code
                                        }
                                        doPostAjaxRequestWithParamsHandler(context + "/activatePartnerService",
                                                params, function (response) {
                                                        if (response == "true") {
                                                                alert("successfully activate");
                                                                loadAdminPartnerService("main-content", fofoId);
                                                        }
                                                });
                                }
                        }
                }
        });
}

function activateFinanceServices(fofoId, serviceId, row) {
        console.log(fofoId);

        console.log(row);
        bootbox.dialog({
                title: "Are you sure you want to activate services!",
                message: "<div class=form-inline'>"
                        + "<label for='code'>Code:</label>"
                        + "<input class='form-control' type='text' id='code'/>"
                        + "</div>",
                buttons: {
                        cancel: {
                                label: "cancel",
                                className: 'btn-danger',
                                callback: function () {
                                        return;
                                }
                        },
                        ok: {
                                label: "ok",
                                className: 'btn-info',
                                callback: function () {
                                        code = $('#code').val();
                                        //console.log(partnerStatusComment);
                                        if (code == "" || code == undefined || code == null) {
                                                alert("code can't be empty");
                                                activatePartnerService(fofoId, serviceId);
                                                return;
                                        }
                                        var params = {
                                                "serviceId": serviceId,
                                                "fofoId": fofoId,
                                                "code": code
                                        }
                                        doPostAjaxRequestWithParamsHandler(context + "/activateFinanceServices",
                                                params, function (response) {

                                                        row.html(response);
                                                        alert("successfully submit");

                                                });
                                }
                        }
                }
        });
}

function deActivatePartnerService(fofoId, serviceId) {
        if (confirm("Are you sure you want to deactivate services!") == true) {
                var params = {
                        "serviceId": serviceId,
                        "fofoId": fofoId

                }
                doPostAjaxRequestWithParamsHandler(context
                        + "/deActivatePartnerService", params, function (response) {
                        if (response == "true") {
                                alert("successfully deactivate");
                                loadAdminPartnerService("main-content", fofoId);
                        }
                });
        }
}

function activatePartnerBrandService(fofoId, serviceId, serviceBrandId) {
        if (confirm("Are you sure you want to activate brand service!") == true) {
                var params = {
                        "serviceId": serviceId,
                        "fofoId": fofoId,
                        "serviceBrandId": serviceBrandId

                }
                doPostAjaxRequestWithParamsHandler(context
                        + "/activatePartnerbrandService", params, function (response) {
                        if (response == "true") {
                                alert("successfully activate");
                                $('#myServiceActivateBrand').modal('hide');
                                $('.modal-backdrop').remove();
                                loadAdminPartnerService("main-content", fofoId);
                        }
                });
        }
}

function actionFinanceBrandService(fofoId, serviceId, brandId, row) {
        if (confirm("Are you sure you want to activate or deactivate brand service!") == true) {
                var params = {
                        "serviceId": serviceId,
                        "fofoId": fofoId,
                        "serviceBrandId": brandId

                }
                doPostAjaxRequestWithParamsHandler(context
                        + "/actionFinanceBrandService", params, function (response) {

                        alert("successfully activate");
                        row.html(response);
                });
        }
}


function deActivateFinanceServicePartnerNotInterested(fofoId, serviceId, partnerNotInterestedComment, row) {
        console.log(row);
        if (confirm("Are you sure you want to Deactivate service!") == true) {
                var params = {
                        "serviceId": serviceId,
                        "fofoId": fofoId,
                        "partnerNotInterestedComment": partnerNotInterestedComment

                }
                doPostAjaxRequestWithParamsHandler(context
                        + "/deActivateFinanceServicePartnerNotInterested", params, function (response) {

                        console.log(row);
                        alert("successfully submit");
                        row.html(response);

                });
        }
}

function deActivatePartnerServiceByPartner(fofoId, serviceId, partnerNotInterestedComment) {
        if (confirm("Are you sure you want to Deactivate service!") == true) {
                var params = {
                        "serviceId": serviceId,
                        "fofoId": fofoId,
                        "partnerNotInterestedComment": partnerNotInterestedComment

                }
                doPostAjaxRequestWithParamsHandler(context
                        + "/deActivatePartnerBrandServiceByPartner", params, function (response) {
                        if (response == "true") {
                                alert("successfully activate");
                                $('#serviceDeactivateByPartnerModal').modal('hide');
                                $('.modal-backdrop').remove();
                                loadAdminPartnerService("main-content", fofoId);
                        }
                });
        }
}

function deActivatePartnerBrandService(fofoId, serviceId, serviceBrandId, serviceBrandComment) {
        if (confirm("Are you sure you want to deactivate brand service!") == true) {
                var params = {
                        "serviceId": serviceId,
                        "fofoId": fofoId,
                        "serviceBrandId": serviceBrandId,
                        "serviceBrandComment": serviceBrandComment
                }
                doPostAjaxRequestWithParamsHandler(context
                        + "/deActivatePartnerbrandService", params, function (response) {
                        if (response == "true") {
                                alert("successfully deactivate");
                                $('#myServiceDeActivateBrand').modal('hide');
                                $('.modal-backdrop').remove();
                                loadAdminPartnerService("main-content", fofoId);
                        }
                });
        }
}

function loadaddPartnerServiceDetails(domId) {
        doGetAjaxRequestHandler(context + "/getAddPartnerServicesDetails",
                function (response) {
                        $('#' + domId).html(response);
                });
}

function loadaddPartnerBrandServiceDetails(domId) {
        doGetAjaxRequestHandler(context + "/getAddPartnerBrandServiceDetails",
                function (response) {
                        $('#' + domId).html(response);
                });
}