
<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_driver')) {
                echo Forms::FloatingAddButton('4c0870', '#add_driver', CommonLanguage::getMessage('add_driver'), 'add_driver_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('driver_name'); ?></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_driver" 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_driver'); ?></h5>
                <h5 class="edit-label bold hidden h-labels"><?php echo CommonLanguage::getMessage('edit_driver'); ?></h5>
            </div>
            <div class="modal-body">
                <form id="driver_form" method="POST" onsubmit="return false">
                    <input type='hidden' name='driver_id' id='driver_id'/>
                    <div class="row">
                        <?php echo Forms::AlertDiv('driver_alert'); ?>
                    </div>
                    <div class="row form-group">
                        <div class="col-md-12 m-t-10">
                            <label><?php echo CommonLanguage::getMessage('driver_name'); ?></label> 
                            <span class="red-star">*</span>
                            <input type="text"  placeholder="<?php print CommonLanguage::getMessage('driver_name'); ?>" id="driver_name" name="driver_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_driver"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('driver_loader'); ?>
        </div>
    </div>
</div>
<script>
    var title = <?php echo json_encode(CommonLanguage::getMessage('driver_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/driver_list");
        $('#tableWithSearch').on('click', '.delete_driver', function () {
            var driver_id = $(this).parents('div.Action').attr('data-id');
            IncludeDeleteModal(delete_modal, {entry_value: driver_id}, function () {
                RebuildDataTable($('.panel-heading .panel-title').html(), [0, 1], 'InventoryAjax/driver_list');
            }, "InventoryAjax/delete_driver");
        });
        $(".add_driver_btn").on("click", function () {
                $("#driver_id").val('');
                $('#add_driver .add-label').removeClass('hidden');
            });
            $("#tableWithSearch").on("click", ".edit_driver", function () {
                var driver_id = $(this).parents('div.Action').attr('data-id');
                $('#add_driver .edit-label').removeClass('hidden');
                $("#driver_id").val(driver_id);
                $("#driver_name").val($(this).parents('tr').find('td:eq(0)').html());
            });
            $("#submit_driver").on("click", function () {
                if (!$("#driver_form").valid())
                    return;
                $("#driver_loader").removeClass('hidden');
                var Data = new FormData(document.getElementById("driver_form"));
                $.ajax({
                    url: "InventoryAjax/submit_driver",
                    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/driver_list');
                                hideModalAlert('add_driver', 'driver_alert');
                            }
                            AddAlert("#driver_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                        }
                        $("#driver_loader").addClass('hidden');
                    }
                });
            });
    });
</script>