
// ========================
// Edit Subscription County
// ========================

$(document).ready(function () {

    var $application = $("#APPLICATION_MNEMONIC").val(), $sessionStorage = JSON.parse(sessionStorage.getItem($application) || "{}");

    // --------------
    // Select Picker.
    // --------------

    $(".search-dropdown").selectpicker({noneSelectedText: "",
        style: "",
        styleBase: "form-select form-select-sm",
        iconBase: "bi",
        virtualScroll: true,
        size: 10,
        selectOnTab: true,
        containter: "body",
        liveSearch: true});

    // -----------
    // Save Button
    // -----------

    $(".btnSave").on("click", function (e) {

        e.preventDefault();

        $("#editSubscriptionCounty").submit();

    });

    // --------------
    // Cancel Button.
    // --------------

    $(".btnCancel").on("click", function () {

        $sessionStorage.action = $sessionStorage.editSubscriptionCounty || "";

        sessionStorage.setItem($application, JSON.stringify($sessionStorage));

        formSubmit($sessionStorage);

    });

    // -------------
    // Delete Button
    // -------------

    $(".btnDelete").on("click", function () {

        $("#confirm-dialog").removeClass().addClass("modal confirm-delete-subscriptioncounty")
                .find(".modal-title").html("Confirm Delete Subscription County").end()
                .find(".modal-body").html("Are you sure you wish to delete this Subscriptions County?").end()
                .modal("show");

    });

    $("body").on("click", ".confirm-delete-subscriptioncounty .btnConfirmDialogConfirm", function () {

        $.post("./", {action: "Subscriptions.deleteSubscriptionCounty", subscriptioncounty_serial: $sessionStorage.subscriptioncounty_serial})
                .done(function () {
                    $sessionStorage.action = $sessionStorage.deleteSubscriptionCounty || "";
                    formSubmit($sessionStorage);
                });

    });

    // ---------------
    // Validate Inputs
    // ---------------

    $("#editSubscriptionCounty").submit(function (e) {

        var county_name = $("#county_serial");

        clearInputErrors();

        if ($("option:selected", county_name).val() === "") {
            createInputError(county_name, "Please select a county");
            return false;
        }

        e.preventDefault();

        $.post("./", $(this).serialize())

                .done(function () {

                    $sessionStorage.action = $sessionStorage.editSubscriptionCounty || "";

                    sessionStorage.setItem($application, JSON.stringify($sessionStorage));

                    formSubmit($sessionStorage);

                });

    });

});