
<script src="<?php echo THEME_PATH; ?>plugins/jquery-validation/js/jquery.validate.min.js"></script>
<div class="modal fade" id="addDelivery" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header text-left">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="add-label bold hidden h-labels"><?php echo CommonLanguage::getMessage('add_delivery'); ?></h5>
                <h5 class="edit-label bold hidden h-labels"><?php echo CommonLanguage::getMessage('edit_delivery'); ?></h5>
            </div>
            <div class="modal-body">
                <form id="add_delivery_form" method="POST" onsubmit="return false">
                    <input type='hidden' name='delivery_flag' id='delivery_flag'/>
                    <input type='hidden' name='delivery_id' id='delivery_id'/>
                    <div class="row">
                        <?php echo Forms::AlertDiv('add_delivery_alert'); ?>
                    </div>
                    <div class="row">
                        <div class="col-md-12 m-t-10">
                            <label><?php echo CommonLanguage::getMessage('delivery_fees_amount'); ?></label> 
                            <span class="red-star">*</span>
                            <input type="number"  placeholder="<?php print CommonLanguage::getMessage('delivery_fees_amount'); ?>" id="delivery_fees_amount" name="delivery_fees_amount" class="form-control " required>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-12 m-t-10">
                            <label><?php echo CommonLanguage::getMessage('delivery_text'); ?></label> 
                            <span class="red-star">*</span>
                            <input type="text"  placeholder="<?php print CommonLanguage::getMessage('delivery_text'); ?>" id="delivery_fees_view" name="delivery_fees_view" class="form-control " required>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close'); ?></button>
                <button class="btn btn-primary" id="submit_delivery"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('addDeliveryLoader'); ?>
        </div>
    </div>
</div>
<script>
    $(function () {
        $(".add_delivery_btn").on("click", function () {
            $("#delivery_flag").val(0);
            $("#delivery_id").val('');
            $('#addDelivery .add-label').removeClass('hidden');
        });
        $("#tableWithSearch").on("click", ".edit_delivery", function () {
            var delivery_id = $(this).parents('div.Action').attr('data-id');
            $('#addDelivery .edit-label').removeClass('hidden');
            $("#delivery_flag").val(1);
            $("#delivery_id").val(delivery_id);
            $("#delivery_fees_amount").val($(this).parents('tr').find('td:eq(0)').html());
            $("#delivery_fees_view").val($(this).parents('tr').find('td:eq(1)').html());
        });
        $("#submit_delivery").on("click", function () {
            if (!$("#add_delivery_form").valid()){
                return;
            }
            $("#addDeliveryLoader").removeClass('hidden');
            var Data = new FormData(document.getElementById("add_delivery_form"));
            $.ajax({
                url: "InventoryAjax/submitDelivery",
                method: "POST",
                data: Data,
                processData: false,
                contentType: false,
                dataType: "JSON",
                complete: function (jqXHR, status) {
                    if (status == 'success') {
                        if (jqXHR.responseJSON[1] == "success") {
                            RebuildDataTable($('.panel-heading .panel-title').html(), [0, 1], 'InventoryAjax/listDeliveryRequest');
                            hideModalAlert('addDelivery', 'add_delivery_alert');
                        }
                        AddAlert("#add_delivery_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                    }
                    $("#addDeliveryLoader").addClass('hidden');
                }
            });
        });
    });
</script>