Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

app-ecommerce-customer-detail-overview.js 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /**
  2. * Page Detail overview
  3. */
  4. 'use strict';
  5. // Datatable (js)
  6. document.addEventListener('DOMContentLoaded', function (e) {
  7. const dt_customer_order = document.querySelector('.datatables-customer-order'),
  8. order_details = baseUrl + 'app/ecommerce/order/details',
  9. statusObj = {
  10. 1: { title: 'Ready to Pickup', class: 'bg-label-info' },
  11. 2: { title: 'Dispatched', class: 'bg-label-warning' },
  12. 3: { title: 'Delivered', class: 'bg-label-success' },
  13. 4: { title: 'Out for delivery', class: 'bg-label-primary' }
  14. };
  15. // orders datatable
  16. if (dt_customer_order) {
  17. let tableTitle = document.createElement('h5');
  18. tableTitle.classList.add('card-title', 'mb-0');
  19. tableTitle.innerHTML = 'Orders placed';
  20. var dt_order = new DataTable(dt_customer_order, {
  21. ajax: assetsPath + 'json/ecommerce-customer-order.json', // JSON file to add data
  22. columns: [
  23. // columns according to JSON
  24. { data: 'id' },
  25. { data: 'order' },
  26. { data: 'date' },
  27. { data: 'status' },
  28. { data: 'spent' },
  29. { data: 'id' }
  30. ],
  31. columnDefs: [
  32. {
  33. // For Responsive
  34. className: 'control',
  35. searchable: false,
  36. orderable: false,
  37. responsivePriority: 2,
  38. targets: 0,
  39. render: function (data, type, full, meta) {
  40. return '';
  41. }
  42. },
  43. {
  44. // order order number
  45. targets: 1,
  46. responsivePriority: 4,
  47. render: function (data, type, full, meta) {
  48. const id = full['order'];
  49. return "<a href='" + order_details + "'><span>#" + id + '</span></a>';
  50. }
  51. },
  52. {
  53. // date
  54. targets: 2,
  55. render: function (data, type, full, meta) {
  56. const date = new Date(full.date); // convert the date string to a Date object
  57. const formattedDate = date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
  58. return '<span class="text-nowrap">' + formattedDate + '</span > ';
  59. }
  60. },
  61. {
  62. // status
  63. targets: 3,
  64. render: function (data, type, full, meta) {
  65. const status = full['status'];
  66. return (
  67. '<span class="badge ' +
  68. statusObj[status].class +
  69. '" text-capitalized>' +
  70. statusObj[status].title +
  71. '</span>'
  72. );
  73. }
  74. },
  75. {
  76. // spent
  77. targets: 4,
  78. render: function (data, type, full, meta) {
  79. const spent = full['spent'];
  80. return '<span >' + spent + '</span>';
  81. }
  82. },
  83. {
  84. targets: -1,
  85. title: 'Actions',
  86. searchable: false,
  87. orderable: false,
  88. render: function (data, type, full, meta) {
  89. return `
  90. <div class="text-xxl-center">
  91. <button class="btn btn-icon dropdown-toggle hide-arrow" data-bs-toggle="dropdown">
  92. <i class="icon-base bx bx-dots-vertical-rounded"></i>
  93. </button>
  94. <div class="dropdown-menu dropdown-menu-end m-0">
  95. <a href="javascript:void(0);" class="dropdown-item">View</a>
  96. <a href="javascript:void(0);" class="dropdown-item delete-record">Delete</a>
  97. </div>
  98. </div>
  99. `;
  100. }
  101. }
  102. ],
  103. order: [[1, 'desc']],
  104. layout: {
  105. topStart: {
  106. rowClass: 'row card-header border-bottom mx-0 px-3 py-0',
  107. features: [tableTitle]
  108. },
  109. topEnd: {
  110. search: {
  111. placeholder: 'Search order',
  112. text: '_INPUT_'
  113. }
  114. },
  115. bottomStart: {
  116. rowClass: 'row mx-3 justify-content-between',
  117. features: ['info']
  118. },
  119. bottomEnd: 'paging'
  120. },
  121. language: {
  122. paginate: {
  123. next: '<i class="icon-base bx bx-chevron-right scaleX-n1-rtl icon-18px"></i>',
  124. previous: '<i class="icon-base bx bx-chevron-left scaleX-n1-rtl icon-18px"></i>',
  125. first: '<i class="icon-base bx bx-chevrons-left scaleX-n1-rtl icon-18px"></i>',
  126. last: '<i class="icon-base bx bx-chevrons-right scaleX-n1-rtl icon-18px"></i>'
  127. }
  128. },
  129. displayLength: 6,
  130. // For responsive popup
  131. responsive: {
  132. details: {
  133. display: DataTable.Responsive.display.modal({
  134. header: function (row) {
  135. const data = row.data();
  136. return 'Details of ' + data['order'];
  137. }
  138. }),
  139. type: 'column',
  140. renderer: function (api, rowIdx, columns) {
  141. const data = columns
  142. .map(function (col) {
  143. return col.title !== '' // Do not show row in modal popup if title is blank (for check box)
  144. ? `<tr data-dt-row="${col.rowIndex}" data-dt-column="${col.columnIndex}">
  145. <td>${col.title}:</td>
  146. <td>${col.data}</td>
  147. </tr>`
  148. : '';
  149. })
  150. .join('');
  151. if (data) {
  152. const div = document.createElement('div');
  153. div.classList.add('table-responsive');
  154. const table = document.createElement('table');
  155. div.appendChild(table);
  156. table.classList.add('table');
  157. const tbody = document.createElement('tbody');
  158. tbody.innerHTML = data;
  159. table.appendChild(tbody);
  160. return div;
  161. }
  162. return false;
  163. }
  164. }
  165. }
  166. });
  167. }
  168. //? The 'delete-record' class is necessary for the functionality of the following code.
  169. document.addEventListener('click', function (e) {
  170. if (e.target.classList.contains('delete-record')) {
  171. dt_order.row(e.target.closest('tr')).remove().draw();
  172. const modalEl = document.querySelector('.dtr-bs-modal');
  173. if (modalEl && modalEl.classList.contains('show')) {
  174. const modal = bootstrap.Modal.getInstance(modalEl);
  175. modal?.hide();
  176. }
  177. }
  178. });
  179. // Filter form control to default size
  180. // ? setTimeout used for customer-detail-overview table initialization
  181. setTimeout(() => {
  182. const elementsToModify = [
  183. { selector: '.dt-buttons .btn', classToRemove: 'btn-secondary' },
  184. { selector: '.dt-search .form-control', classToRemove: 'form-control-sm' },
  185. { selector: '.dt-length .form-select', classToRemove: 'form-select-sm' },
  186. { selector: '.dt-layout-table', classToRemove: 'row mt-2' },
  187. { selector: '.dt-layout-start', classToAdd: 'mb-xxl-0 mb-4' },
  188. { selector: '.dt-layout-full', classToRemove: 'col-md col-12', classToAdd: 'table-responsive' }
  189. ];
  190. // Delete record
  191. elementsToModify.forEach(({ selector, classToRemove, classToAdd }) => {
  192. document.querySelectorAll(selector).forEach(element => {
  193. if (classToRemove) {
  194. classToRemove.split(' ').forEach(className => element.classList.remove(className));
  195. }
  196. if (classToAdd) {
  197. classToAdd.split(' ').forEach(className => element.classList.add(className));
  198. }
  199. });
  200. });
  201. }, 100);
  202. });
  203. // Validation & Phone mask