vehiclesDetails.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <button class="btn btn-primary" onclick="document.getElementById('addVForm').style.display = 'block';document.getElementById('addForm').style.display = 'none';document.getElementById('editForm').style.display = 'none';document.getElementById('editVForm').style.display = 'none';document.getElementById('deleteForm').style.display = 'none';document.getElementById('deleteVForm').style.display = 'none';"> Add Vehicle </button>
  2. <table id="vehicle" class="table display table-striped table-bordered table-hover table-sm" cellspacing="0" width="100%">
  3. <thead>
  4. <tr style="color:white;">
  5. <th colspan="1" style="background: #5d8a4c;">Customer</th>
  6. <th style="background: #5d8a4c;font-family:'Lobster', helvetica,;" colspan="3" ><?php echo $_COOKIE['customerName']; ?></th>
  7. </tr>
  8. <tr>
  9. <th></th>
  10. <th></th>
  11. <th>Id</th>
  12. <th>Number</th>
  13. </tr>
  14. </thead>
  15. <tfoot>
  16. <tr>
  17. <th></th>
  18. <th></th>
  19. <th>Id</th>
  20. <th>Number</th>
  21. </tr>
  22. </tfoot>
  23. </table>
  24. <script type="text/javascript">
  25. $(document).ready(function() {
  26. var table = $('#vehicle').DataTable( {
  27. "buttons": true,
  28. "ajax": "api/v1/Customers/vehicles.txt",
  29. "columns": [
  30. {
  31. "className": 'delete',
  32. "orderable": false,
  33. "data": null,
  34. "defaultContent": 'Delete'
  35. },
  36. {
  37. "className": 'edit',
  38. "orderable": false,
  39. "data": null,
  40. "defaultContent": 'Edit'
  41. },
  42. { "data": "Id" },
  43. { "data": "Number" }
  44. ],
  45. "order": [[1, 'asc']]
  46. } );
  47. // Add event listener for opening and closing details
  48. $('#vehicle tbody').on('click', 'td.delete', function () {
  49. var tr = $(this).closest('tr');
  50. var row = table.row( tr );
  51. var number = row.data()['Number'];
  52. var vehicleid = row.data()['Id'];
  53. var id = row.data()['Customer_Id'];
  54. document.getElementById('deleteVid').value = vehicleid;
  55. document.getElementById('deleteVForm').style.display = 'block';
  56. document.getElementById('editVForm').style.display = 'none';
  57. document.getElementById('addVForm').style.display = 'none';
  58. document.getElementById('editForm').style.display = 'none';
  59. document.getElementById('addForm').style.display = 'none';
  60. document.getElementById('deleteForm').style.display = 'none';
  61. } );
  62. // Add event listener for opening and closing details
  63. $('#vehicle tbody').on('click', 'tr td.edit', function () {
  64. var tr = $(this).closest('tr');
  65. var row = table.row( tr );
  66. var vehicle_id = row.data()['Id'];
  67. var number = row.data()['Number'];
  68. document.getElementById('vehicle_id').value = vehicle_id;
  69. document.getElementById('number').value = number;
  70. document.getElementById('editVForm').style.display = 'block';
  71. document.getElementById('addVForm').style.display = 'none';
  72. document.getElementById('deleteVForm').style.display = 'none';
  73. document.getElementById('editForm').style.display = 'none';
  74. document.getElementById('addForm').style.display = 'none';
  75. document.getElementById('deleteForm').style.display = 'none';
  76. } );
  77. } );
  78. </script>