<?php
if ($permissions->hasPermission('AddVehicle')) {
    include 'Views/Garage/EditVehicle.php';
}
?>
<div class="container-fluid container-fixed-lg bg-white" style="height:100%">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div id="vehicle_list_alert"></div>
            <div class="panel-title"> <?php print CommonLanguage::getMessage('vehicle_list'); ?></div>
            <?php
            echo Forms::FloatingAddButton('652d90', '#EditVehicle', CommonLanguage::getMessage('add'));
            ?> 
            <div class="clearfix"></div>
        </div>
        <div class="panel-body">
            <table class="table table-bordered garage" id="tableWithSearch" >
                <thead>
                    <tr>
                        <th class="text-center"><?php print CommonLanguage::getMessage('maker'); ?></th>
                        <th class="text-center"  ><?php print CommonLanguage::getMessage('Name'); ?></th>
                        <th class="text-center"  ><?php print CommonLanguage::getMessage('reg_nb'); ?></th>
                        <th class="text-center"  ><?php print CommonLanguage::getMessage('model'); ?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('driver'); ?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('oil_exchange'); ?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('mecanique'); ?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('syndicate'); ?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('status'); ?></th>
                        <th class="text-center no-print" ><?php print CommonLanguage::getMessage('Action'); ?></th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
<script>
    $(function () {
                            change_table()

        $("#tableWithSearch").on("click", ".enable_disable_vehicle", function () {
            var vehicle_id = $(this).parents('.Action').attr("data-id"),
                    status = $(this).attr("data-status");
            $.ajax({
                url: "GarageAjax/enable_disable_vehicle",
                data: {vehicle_id: vehicle_id, status: status},
                method: "POST",
                complete: function (jqXHR, textStatus) {
                    if (textStatus == "success") {
                        if (jqXHR.responseText == 'ok') {
                            $("#vehicle_list_alert").attr('class', 'alert alert-success').html('<?php echo CommonLanguage::getMessage('Submitted_Successfully') ?>')
                            change_table()
                            //                RebuildDataTable(title, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 'ScoreAjax/PatientList', {city_id: $('#patient_city').val()});
                        } else {
                            $("#vehicle_list_alert").attr('class', 'alert alert-danger').html('<?php echo CommonLanguage::getMessage('Failed_Submit') ?>')
                        }
                    } else {
                        $("#vehicle_list_alert").attr('class', 'alert alert-danger').html('<?php echo CommonLanguage::getMessage('Failed_Submit') ?>')
                    }
                    $(document.body).animate({scrollTop: 0}, 800)
                }
            })
        })
    });
    function change_table() {
        RebuildDataTable($('.panel-heading .panel-title').html(), [0, 1, 2, 3], 'GarageAjax/VehicleListRequest');

    }
</script>
