
<style>
    .dropdown-menu>li>a {
        cursor:pointer;
    }

    .inputIcon{
        width:30px;}

</style>

<div class="modal fade stick-up " data-backdrop="static" id="addDepotCategory" tabindex="-1" role="dialog" aria-hidden="true" style="width:30%;margin:0 auto">
    <div class="modal-dialog ">
        <div class="modal-content">
            <div class="modal-header clearfix text-left">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-14"></i></button>
                <h5><span class="semi-bold"><?php print CommonLanguage::getMessage('New_Depot_Category'); ?></span></h5>
                <div id="addDepotCategoryAlert"></div>
            </div>
            <div class="modal-body">
                <form id="AddDepotCategoryPostForm" method="POST" onsubmit="return false">
                    <div class="row">

                        <div class="col-md-8">
                            <div class="col-md-12" style="margin:15px;">


                                <div class="col-md-8">
                                    <div><label><?php print CommonLanguage::getMessage('Depot_Category'); ?></label></div>
                                    <div class="input-group required">
                                        <span class="input-group-addon bg-complete-darker">
                                            <i class="fa fa-ship inputIcon" ></i>
                                        </span>
                                        <input type="text" placeholder="Depot Category" id="Depot_Category" name="Depot_Category" class="form-control " style="width:255px;" required>
                                    </div>
                                </div>
                            </div>




                        </div>

                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <div class="pull-right">
                    <button class="btn btn-default" id="CloseDepotCategory"   > <?php print CommonLanguage::getMessage('Close'); ?> </button>
                    <button class="btn btn-bg-complete-darker" id="SubmitDepotCategory"  > <?php print CommonLanguage::getMessage('Save'); ?>   </button>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>;
    $(function () {

        $("#SubmitDepotCategory").on("click", function () {
            $("#addDepotCategoryAlert").attr("class", "").html("")
            $("#AddDepotCategoryPostForm").validate()
            if (!$("#AddDepotCategoryPostForm").find("input").blur().end().valid()) {
                $("#addDepotCategoryAlert").attr("class", "alert alert-danger").show().html(Required_Fields)
                return
            }

            var IsValidated = true;

            $("#DepotCatIsBusy").remove();
            $("#addDepotCategory").append('<div id="DepotCatIsBusy" style="position:absolute;left:0;right:0;top:0px;height:100%;background:rgba(255,255,255,0.9);z-index:9999;opacity:0"><img class="image-responsive-height demo-mw-50" src="img/demo/progress.svg" alt="Progress" style="position: absolute;left: 50%;top: 50%;margin: -25px 0 0 -25px;" /></div>');
            $("#DepotCatIsBusy").animate({opacity: 1});

            var Data = new FormData(document.getElementById("AddDepotCategoryPostForm"));

            $.ajax({
                url: "StockAjax/addDepotCategoryAjax",
                method: "POST",
                data: Data,
                dataType: "json",
                processData: false,
                contentType: false,
                complete: function (v1, v2) {
                    if (v2 == 'success') {
                        var response = v1.responseJSON, responseType = $.type(response);
                        console.log(responseType)
                        if (responseType == 'array') {
                            var newDepotCat = "<option value='" + v1.responseJSON[0]['Category_ID'] + "'>" + v1.responseJSON[0]['Category_Name'] + "</option>";
                            $("#Depot_Category_ID").append($(newDepotCat))
                            $("#Depot_Category_ID").val(v1.responseJSON[0]['Category_ID']).select2()
                            $("#DepotCatIsBusy").remove();
                            $("#addDepotCategoryAlert").addClass("alert alert-success").show().html(Submitted_Successfully);
                            setTimeout(function () {
                                $("#addDepotCategory").modal('hide');
                                $("#addDepotCategoryAlert").hide()
                            }, 1500);
                        } else {
                            $("#addDepotCategoryAlert").addClass("alert alert-danger").show().html(response);
                        }
                        setTimeout(function () {
                            $("#addDepotCategoryAlert").hide()
                        }, 1500);
                    } else {
                        $("#addDepotCategoryAlert").addClass("alert alert-danger").show().html(Failed_Submit);
                    }
                    $("#DepotCatIsBusy").remove();
                }


            })





        });
        $("#CloseDepotCategory").on("click", function () {
            $("#addDepotCategory input").val('');
            //$("#AddProductPostForm").validate().resetForm();
            $("#addDepotCategory").modal("hide");

        })
        $("#addDepotCategory input").val('');

    });


</script>