
<script src="<?php echo THEME_PATH; ?>plugins/jquery-validation/js/jquery.validate.min.js"></script>
<style>
    .dropdown-menu>li>a {
        cursor:pointer;
    }
    .inputIcon{
        width:30px;}
</style>
<div class="modal fade stick-up " data-backdrop="static" id="addPricingClass" tabindex="-1" role="dialog" aria-hidden="true" style="width:30%;margin:0 auto">
    <div class="modal-dialog  width:5px;">
        <div class="modal-content width: 494px;">
            <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('pricing_class');?></span></h5>
                <div id="addPricingClassAlert"></div>
            </div>
            <div class="modal-body">
                <form id="AddPricingClassPostForm" method="POST" onsubmit="return false">
                    <div class="row">
                        <div class="col-md-12" >
                            <div class="col-md-8">
                                <div><label><?php print CommonLanguage::getMessage('pricing_class');?></label></div>
                                <div class="input-group required">
                                    <span class="input-group-addon bg-primary">
                                        <i class="fa fa-ship inputIcon" ></i>
                                    </span>
                                    <input type="text" placeholder="<?php print CommonLanguage::getMessage('pricing_class');?>" id="PricingClassID" name="PricingClassID" class="form-control "  style="width: 252px; " required>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer ">
                <div class="pull-right">
                    <button class="btn btn-default" id="ClosePricingCLass"   > <?php print CommonLanguage::getMessage('Close');?> </button>
                    <button class="btn btn-primary" id="SubmitPricingClass"  >   <?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(){
        // $("#AddProductPostForm").validate();
        $("#SubmitPricingClass").on("click",function(){
            $("#addPricingClassAlert").attr("class","").html("")
            $("#AddPricingClassPostForm").validate()
            if(!$("#AddPricingClassPostForm").find("input").blur().end().valid()){
                $("#addPricingClassAlert").attr("class","alert alert-danger").show().html(Required_Fields)
                return
            }
//            // $("#addPricingClassAlert").remove();
//            var IsValidated=true;
//            // AlertBox.insertAfter($("#addUOM").find(".modal-dialog .modal-header").find("h5"))
//            //            if(!ValidateForNewProductPhoto($("#NewProductUploadPhoto")[0]) == true || !$("#AddProductPostForm").valid()){
//            //                return
//            //            }
            $("#PricingClassIsBusy").remove();
            $("#addUOM").append('<div id="PricingClassIsBusy" 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>');
            $("#PricingClassIsBusy").animate({opacity:1});
            //            var uom=$("#PricingClassID").val();
            //                  $("#select2-chosen-3").html(uom);
           
            var Data = {
                PricingClass : $("#PricingClassID").val()
            }
            $.ajax({
                url:"InventoryAjax/addPricingClassAjax",
                method:"POST",
                data:Data,
                dataType:"JSON",
                complete:function(v1,v2){
                    if(v2 == 'success' && v1.responseJSON[0] =="OK"){
                        var newClass= "<option value='"+v1.responseJSON[1][0]['Class_ID']+"'>"+v1.responseJSON[1][0]['Class_Name']+"</option>";
                        $("#Class").append($(newClass))
                        $("#Class option[value = "+v1.responseJSON[1][0]['Class_ID']+"]").attr('selected','selected')
                            $("#Class").select2()
                        $("#PricingClassIsBusy").remove();
                        $("#addPricingClassAlert").addClass("alert alert-success").show().html(Submitted_Successfully);
                        setTimeout(function(){
                            $("#addPricingClass").modal('hide')
                        },1500)
                        setTimeout(function(){
                            $("#addPricingClassAlert").hide()
                        },1500)
                    }else{

                        $("#addPricingClassAlert").addClass("alert alert-danger").show().html(v1.responseJSON[1][0]);
                    }
                    $("#PricingClassIsBusy").remove();
                }
            })
        });
        $("#ClosePricingCLass").on("click",function(){
            $("#PricingClassID input").val('');
            $("#AddPricingClassPostForm").validate().resetForm();
            $("#addPricingClass").modal("hide");
        })
        $("#PricingClassID input").val('');
    });
</script>