
<script src="<?php echo THEME_PATH; ?>plugins/jquery-validation/js/jquery.validate.min.js"></script>
<div class="modal fade" id="addBrand" 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_brand');?></h5>
                <h5 class="edit-label bold hidden h-labels"><?php echo CommonLanguage::getMessage('edit_brand');?></h5>
            </div>
            <div class="modal-body">
                <form id="add_brand_form" method="POST" onsubmit="return false">
                    <input type='hidden' name='brand_flag' id='brand_flag'/>
                    <input type='hidden' name='brand_id' id='brand_id'/>
                    <div class="row">
                        <?php echo Forms::AlertDiv('add_brand_alert'); ?>
                    </div>
                    <div class="row">
                        <div class="col-md-12 m-t-10">
                            <label><?php echo CommonLanguage::getMessage('brand_name'); ?></label> 
                            <span class="red-star">*</span>
                            <input type="text"  placeholder="<?php print CommonLanguage::getMessage('brand_name'); ?>" id="brand_name" name="brand_name" class="form-control " required>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-12 m-t-10">
                            <label><?php echo CommonLanguage::getMessage('sort_order'); ?></label> 
                            <input type="number"  placeholder="<?php print CommonLanguage::getMessage('sort_order'); ?>" id="order_nb" name="order_nb" class="form-control " >
                        </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_brand"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('addBrandLoader'); ?>
        </div>
    </div>
</div>
<script>
        $(function () {
            $(".add_brand_btn").on("click", function () {
                $("#brand_flag").val(0);
                $("#brand_id").val('');
                $('#addBrand .add-label').removeClass('hidden');
            });
            $("#tableWithSearch").on("click", ".edit_brand", function () {
                var brand_id = $(this).parents('div.Action').attr('data-id');
                $('#addBrand .edit-label').removeClass('hidden');
                $("#brand_flag").val(1);
                $("#brand_id").val(brand_id);
                $("#brand_name").val($(this).parents('tr').find('td:eq(0)').html());
                $("#order_nb").val($(this).parents('tr').find('td:eq(1)').html());
            });
            $("#submit_brand").on("click", function () {
                if (!$("#add_brand_form").valid())
                    return;
                $("#addBrandLoader").removeClass('hidden');
                var Data = new FormData(document.getElementById("add_brand_form"));
                $.ajax({
                    url: "InventoryAjax/submitBrand",
                    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/listBrandRequest');
                                hideModalAlert('addBrand', 'add_brand_alert');
                            }
                            AddAlert("#add_brand_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                        }
                        $("#addBrandLoader").addClass('hidden');
                    }
                });
            });
        });
</script>