
<script src="<?php echo THEME_PATH; ?>plugins/jquery-validation/js/jquery.validate.min.js"></script>
<div class="modal fade" id="add_ons_modal" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"> <?php echo CommonLanguage::getMessage('add_ons'); ?></h5>
            </div>
            <div class="modal-body">
                <form id="add_ons_form" method="POST" onsubmit="return false">
                    <div class="row">
                        <?php echo Forms::AlertDiv('add_ons_alert'); ?>
                        <input type='hidden' name='add_ons_flag' id='add_ons_flag'/>
                        <input type='hidden' name='add_ons_id' id='add_ons_id'/>
                        <div class="col-md-12 m-t-10">
                            <h4>
                                <?php echo CommonLanguage::getMessage('add_ons_title'); ?>
                                <span class="red-star">*</span>
                            </h4> 
                            <input type="text"  placeholder="<?php print CommonLanguage::getMessage('add_ons_title'); ?>" id="add_ons_title" name="add_ons_title" 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_add_ons"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('addOnsLoader'); ?>
        </div>
    </div>
</div>
<script>
    $(function () {
        $(".add_ons_btn").on("click", function () {
            $("#add_ons_flag").val(0);
        });
        $("#tableWithSearch").on("click", ".edit_add_ons", function () {
            var add_ons_id = $(this).parents('div.Action').attr('data-id');
            $("#add_ons_flag").val(1);
            $("#add_ons_id").val(add_ons_id);
            $("#add_ons_title").val($(this).parents('tr').find('td:eq(0)').html());
        });
        $("#submit_add_ons").on("click", function () {
            if (!$("#add_ons_form").valid())
                return;
            $("#addOnsLoader").removeClass('hidden');
            var Data = new FormData(document.getElementById("add_ons_form"));
            $.ajax({
                url: "RestaurantAjax/submitAddOns",
                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], 'RestaurantAjax/addOnsList');
                            hideModalAlert('add_ons_modal', 'add_ons_alert');
                        }
                        AddAlert("#add_ons_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                    }
                    $("#addOnsLoader").addClass('hidden');
                }
            });
        });
    });
</script>