<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"><?php echo $title; ?></div>
            <input type='hidden' name='class_type' id='class_type' value="<?php echo $class_type;?>"/>
            <?php if ($permissions->hasPermission("add_{$class_type}_class")) {
            echo Forms::FloatingAddButton('4c0870', '#class_modal', CommonLanguage::getMessage('add'), 'new_class_btn'); }?>
            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            <div class="table-responsive">
                <table class="table table-bordered inventory" id="tableWithSearch">
                    <thead>
                        <tr>
                            <th><?php print CommonLanguage::getMessage('class_name') ?></th>
                            <th><?php print CommonLanguage::getMessage('Action') ?></th>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="class_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 text-left">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="bold add-label h-labels hidden"><?php echo CommonLanguage::getMessage('add_class'); ?></h5>
                <h5 class="bold edit-label h-labels hidden"><?php echo CommonLanguage::getMessage('edit_class'); ?></h5>
            </div>
            <div class="modal-body">
                <div class="row"><?php echo Forms::AlertDiv('class_alert'); ?></div>
                <form id="class_form" method="POST" onsubmit="return false">
                    <input type='hidden' name='class_id' id='class_id'/>
                    <div class="row form-group">
                        <div class=" col-md-12  " >
                            <label class="labelText">
                                <?php print CommonLanguage::getMessage('class_name'); ?>
                                <span class="red-star">*</span>
                            </label>
                            <input type="text"  placeholder="<?php print CommonLanguage::getMessage('class_name'); ?>" id="class_name" name="class_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_class"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('class_loader'); ?>
        </div>
    </div>
</div>
<script>
    $(function () {
        RebuildDataTable($('.panel-heading .panel-title').html(), [0], 'InventoryAjax/class_list',{class_type:$('#class_type').val()});
        $('#tableWithSearch').on('click', '.delete', function () {
            var class_id = $(this).parents('div.Action').attr('data-id');
            IncludeDeleteModal(common_delete_modal, {class_id: class_id}, function () {
                RebuildDataTable($('.panel-heading .panel-title').html(), [0], 'InventoryAjax/class_list',{class_type:$('#class_type').val()});
            }, "InventoryAjax/deleteClass");
        });
        $(".new_class_btn").on("click", function () {
            $("#class_id").val(0);
            $('#class_modal .add-label').removeClass('hidden');
        });
        $("#tableWithSearch").on("click", ".edit", function () {
            var class_id = $(this).parents('div.Action').attr('data-id');
            $("#class_id").val(class_id);
            $('#class_modal .edit-label').removeClass('hidden');
            $("#class_name").val($(this).parents('tr').find('td:eq(0)').html());
        });
        $("#submit_class").on("click", function () {
            if (!$("#class_form").valid())
                return;
            $("#class_loader").removeClass('hidden');
            var Data = new FormData(document.getElementById("class_form"));
            Data.append('class_type',$('#class_type').val());
            $.ajax({
                url: "InventoryAjax/submitClass",
                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], 'InventoryAjax/class_list',{class_type:$('#class_type').val()});
                            hideModalAlert('class_modal', 'class_alert');
                        }
                        AddAlert("#class_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                    }
                    $("#class_loader").addClass('hidden');
                }
            });
        });
    });

</script>