
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"> <?php print $title; ?></div>
            <?php
            if ($permissions->hasPermission('add_pur_cat')) {
                echo Forms::FloatingAddButton('4c0870', '#add_pur_cat', CommonLanguage::getMessage('add_pur_cat'), 'add_cat_btn');
            }
            ?>
        </div>
        <div class="panel-body">
            <div class=" row   ">
                <div class="col-md-12 table-responsive">
                    <table class="table table-bordered  inventory" id="tableWithSearch" >
                        <thead>
                            <tr>
                                <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('pur_cat'); ?></th>
                                <th class="text-center no-print" style="width:15%"><?php print CommonLanguage::getMessage('Action'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="add_pur_cat" 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_pur_cat'); ?></h5>
                <h5 class="edit-label bold hidden h-labels"><?php echo CommonLanguage::getMessage('edit_pur_cat'); ?></h5>
            </div>
            <div class="modal-body">
                <form id="pur_cat_form" method="POST" onsubmit="return false">
                    <input type='hidden' name='pur_cat_id' id='pur_cat_id'/>
                    <div class="row">
                        <?php echo Forms::AlertDiv('pur_cat_alert'); ?>
                    </div>
                    <div class="row form-group">
                        <div class="col-md-12 m-t-10">
                            <label><?php echo CommonLanguage::getMessage('category_name'); ?></label> 
                            <span class="red-star">*</span>
                            <input type="text"  placeholder="<?php print CommonLanguage::getMessage('category_name'); ?>" id="pur_cat_name" name="pur_cat_name" 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_cat"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('add_cat_loader'); ?>
        </div>
    </div>
</div>
<script>
    var title = <?php echo json_encode(CommonLanguage::getMessage('brand_list')) ?>;
    var delete_modal = <?php
            echo json_encode([CommonLanguage::getMessage('Confirm_Delete'),
                CommonLanguage::getMessage('About_To_Delete'),
                CommonLanguage::getMessage('Proceed_Delete'),
                CommonLanguage::getMessage('Close'),
                CommonLanguage::getMessage('delete'),
                CommonLanguage::getMessage('Deleted_Successfully')
            ]);
            ?>;
    $(function () {
        RebuildDataTable(title, [0, 1], "InventoryAjax/purchase_cat_list");
        $('#tableWithSearch').on('click', '.delete_cat', function () {
            var pur_cat_id = $(this).parents('div.Action').attr('data-id');
            IncludeDeleteModal(delete_modal, {entry_value: pur_cat_id}, function () {
                RebuildDataTable($('.panel-heading .panel-title').html(), [0, 1], 'InventoryAjax/purchase_cat_list');
            }, "InventoryAjax/delete_pur_cat");
        });
        $(".add_cat_btn").on("click", function () {
                $("#pur_cat_id").val('');
                $('#add_pur_cat .add-label').removeClass('hidden');
            });
            $("#tableWithSearch").on("click", ".edit_cat", function () {
                var pur_cat_id = $(this).parents('div.Action').attr('data-id');
                $('#add_pur_cat .edit-label').removeClass('hidden');
                $("#pur_cat_id").val(pur_cat_id);
                $("#pur_cat_name").val($(this).parents('tr').find('td:eq(0)').html());
            });
            $("#submit_cat").on("click", function () {
                if (!$("#pur_cat_form").valid())
                    return;
                $("#add_cat_loader").removeClass('hidden');
                var Data = new FormData(document.getElementById("pur_cat_form"));
                $.ajax({
                    url: "InventoryAjax/submit_pur_cat",
                    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/purchase_cat_list');
                                hideModalAlert('add_pur_cat', 'pur_cat_alert');
                            }
                            AddAlert("#pur_cat_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                        }
                        $("#add_cat_loader").addClass('hidden');
                    }
                });
            });
    });
</script>