<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_production_emp_type')) {
    echo Forms::FloatingAddButton('4c0870', '#production_employee_type_modal', CommonLanguage::getMessage('add'), 'add_production_emp_type');} ?>
        </div>
        <div class="panel-body">
            <div class="table-responsive">
                <table class="table table-bordered  maintenance-table" id="tableWithSearch">
                    <thead>
                        <tr>
                            <th><?php print CommonLanguage::getMessage('type_name') ?></th>
                            <th><?php print CommonLanguage::getMessage('Action') ?></th>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="production_employee_type_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="add-label h-labels text-left bold hidden"><?php echo CommonLanguage::getMessage('add_production_emp_type'); ?></h5>
                <h5 class="edit-label h-labels text-left bold hidden"><?php echo CommonLanguage::getMessage('edit_production_emp_type'); ?></h5>
            </div>
            <div class="modal-body">
                <form id="production_emp_type_form" method="POST" onsubmit="return false">
                    <div class="row">
                        <?php echo Forms::AlertDiv('production_emp_type_alert'); ?>
                        <input type='hidden' name='type_id' id='type_id'/>
                    </div>
                    <div class="row form-group m-t-10">
                        <div class="col-md-12">
                            <label><?php print CommonLanguage::getMessage('type_name'); ?></label>
                            <input type="text" id="type_name" name="type_name" class="form-control " autocomplete="off" required>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close'); ?></button>
                <button style="color:white !important;" class="btn bg-success-dark text-white" id="submit_production_emp_type"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('production_emp_type_loader'); ?>
        </div>
    </div>
</div>
<script>
    $(function () {
        RebuildDataTable($('.panel-heading .panel-title').html(), [0], 'MaintenanceAjax/production_emp_type_list');
        $('#tableWithSearch').on('click', '.delete', function () {
            var entry_value = $(this).parents('div.Action').attr('data-id')
            IncludeDeleteModal(common_delete_modal, {type_id: entry_value}, function () {
                RebuildDataTable($('.panel-heading .panel-title').html(), [0], 'MaintenanceAjax/production_emp_type_list');
            }, "MaintenanceAjax/deleteProductionEmpType");
        });
        $(".add_production_emp_type").on("click", function () {
            $('#production_employee_type_modal .add-label').removeClass('hidden');
            $("#type_id").val(0);
        });
        $("#tableWithSearch").on("click", ".edit", function () {
            $('#production_employee_type_modal .edit-label').removeClass('hidden');
            var type_id = $(this).parents('div.Action').attr('data-id');
            $("#type_id").val(type_id);
            $("#type_name").val($(this).parents('tr').find('td:eq(0)').html());
        });
        $("#submit_production_emp_type").on("click", function () {
            if (!$("#production_emp_type_form").valid())
                return;
            $("#production_emp_type_loader").removeClass('hidden');
            var Data = new FormData(document.getElementById("production_emp_type_form"));
            $.ajax({
                url: "MaintenanceAjax/submitProductionEmployeeTypes",
                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], 'MaintenanceAjax/production_emp_type_list');
                            hideModalAlert('production_employee_type_modal', 'production_emp_type_alert');
                        }
                        AddAlert("#production_emp_type_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                    }
                    $("#production_emp_type_loader").addClass('hidden');
                }
            });
        });
    });
</script>