vehiclesDetails.php 3.4 KB

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