/** * App eCommerce review */ 'use strict'; // apex-chart (function () { let cardColor, shadeColor, labelColor, headingColor; if (isDarkStyle) { cardColor = config.colors_dark.cardColor; labelColor = config.colors_dark.textMuted; headingColor = config.colors_dark.headingColor; shadeColor = 'dark'; } else { cardColor = config.colors.cardColor; labelColor = config.colors.textMuted; headingColor = config.colors.headingColor; shadeColor = ''; } // Visitor Bar Chart // -------------------------------------------------------------------- const visitorBarChartEl = document.querySelector('#reviewsChart'), visitorBarChartConfig = { chart: { height: 160, width: 190, type: 'bar', toolbar: { show: false } }, plotOptions: { bar: { barHeight: '75%', columnWidth: '40%', startingShape: 'rounded', endingShape: 'rounded', borderRadius: 5, distributed: true } }, grid: { show: false, padding: { top: -25, bottom: -12 } }, colors: [ config.colors_label.success, config.colors_label.success, config.colors_label.success, config.colors_label.success, config.colors.success, config.colors_label.success, config.colors_label.success ], dataLabels: { enabled: false }, series: [ { data: [20, 40, 60, 80, 100, 80, 60] } ], legend: { show: false }, xaxis: { categories: ['M', 'T', 'W', 'T', 'F', 'S', 'S'], axisBorder: { show: false }, axisTicks: { show: false }, labels: { style: { colors: labelColor, fontSize: '13px' } } }, yaxis: { labels: { show: false } }, responsive: [ { breakpoint: 0, options: { chart: { width: '100%' }, plotOptions: { bar: { columnWidth: '40%' } } } }, { breakpoint: 1440, options: { chart: { height: 150, width: 190, toolbar: { show: false } }, plotOptions: { bar: { borderRadius: 6, columnWidth: '40%' } } } }, { breakpoint: 1400, options: { plotOptions: { bar: { borderRadius: 6, columnWidth: '40%' } } } }, { breakpoint: 1200, options: { chart: { height: 130, width: 190, toolbar: { show: false } }, plotOptions: { bar: { borderRadius: 6, columnWidth: '40%' } } } }, { breakpoint: 992, chart: { height: 150, width: 190, toolbar: { show: false } }, options: { plotOptions: { bar: { borderRadius: 5, columnWidth: '40%' } } } }, { breakpoint: 883, options: { plotOptions: { bar: { borderRadius: 5, columnWidth: '40%' } } } }, { breakpoint: 768, options: { chart: { height: 150, width: 190, toolbar: { show: false } }, plotOptions: { bar: { borderRadius: 4, columnWidth: '40%' } } } }, { breakpoint: 576, options: { chart: { width: '100%', height: '200', type: 'bar' }, plotOptions: { bar: { borderRadius: 6, columnWidth: '30% ' } } } }, { breakpoint: 420, options: { plotOptions: { chart: { width: '100%', height: '200', type: 'bar' }, bar: { borderRadius: 3, columnWidth: '30%' } } } } ] }; if (typeof visitorBarChartEl !== undefined && visitorBarChartEl !== null) { const visitorBarChart = new ApexCharts(visitorBarChartEl, visitorBarChartConfig); visitorBarChart.render(); } })(); // Datatable (jquery) $(function () { let borderColor, bodyBg, headingColor; if (isDarkStyle) { borderColor = config.colors_dark.borderColor; bodyBg = config.colors_dark.bodyBg; headingColor = config.colors_dark.headingColor; } else { borderColor = config.colors.borderColor; bodyBg = config.colors.bodyBg; headingColor = config.colors.headingColor; } // Variable declaration for table var dt_customer_review = $('.datatables-review'), customerView = 'app-ecommerce-customer-details-overview.html', statusObj = { Pending: { title: 'Pending', class: 'bg-label-warning' }, Published: { title: 'Published', class: 'bg-label-success' } }; // reviewer datatable if (dt_customer_review.length) { var dt_review = dt_customer_review.DataTable({ ajax: assetsPath + 'json/app-ecommerce-reviews.json', // JSON file to add data columns: [ // columns according to JSON { data: '' }, { data: 'id' }, { data: 'product' }, { data: 'reviewer' }, { data: 'review' }, { data: 'date' }, { data: 'status' }, { data: ' ' } ], columnDefs: [ { // For Responsive className: 'control', searchable: false, orderable: false, responsivePriority: 2, targets: 0, render: function (data, type, full, meta) { return ''; } }, { // For Checkboxes targets: 1, orderable: false, searchable: false, responsivePriority: 3, checkboxes: true, render: function () { return ''; }, checkboxes: { selectAllRender: '' } }, { // product targets: 2, render: function (data, type, full, meta) { var $product = full['product'], $company_name = full['company_name'], $id = full['id'], $image = full['product_image']; if ($image) { // For Avatar image var $output = 'Product-' +
                $id +
                ''; } else { // For Avatar badge var stateNum = Math.floor(Math.random() * 6); var states = ['success', 'danger', 'warning', 'info', 'dark', 'primary', 'secondary']; var $state = states[stateNum], $product = full['product'], $initials = $product.match(/\b\w/g) || []; $initials = (($initials.shift() || '') + ($initials.pop() || '')).toUpperCase(); $output = '' + $initials + ''; } // Creates full output for row var $row_output = '
' + '
' + '
' + $output + '
' + '
' + '
' + '' + $product + '' + '' + $company_name + '' + '
' + '
'; return $row_output; } }, { // reviewer targets: 3, responsivePriority: 1, render: function (data, type, full, meta) { var $name = full['reviewer'], $email = full['email'], $avatar = full['avatar']; if ($avatar) { // For Avatar image var $output = 'Avatar'; } else { // For Avatar badge var stateNum = Math.floor(Math.random() * 6); var states = ['success', 'danger', 'warning', 'info', 'dark', 'primary', 'secondary']; var $state = states[stateNum], $name = full['reviewer'], $initials = $name.match(/\b\w/g) || []; $initials = (($initials.shift() || '') + ($initials.pop() || '')).toUpperCase(); $output = '' + $initials + ''; } // Creates full output for row var $row_output = '
' + '
' + '
' + $output + '
' + '
' + '
' + '' + $name + '' + '' + $email + '' + '
' + '
'; return $row_output; } }, { // Review targets: 4, responsivePriority: 2, render: function (data, type, full, meta) { var $num = full['review']; var $heading = full['head']; var $comment = full['para']; var $readOnlyRatings = $('
'); // Initialize rateYo plugin $readOnlyRatings.rateYo({ rating: $num, rtl: isRtl, readOnly: true, // Make the rating read-only starWidth: '20px', // Set the width of each star spacing: '3px', // Spacing between the stars starSvg: '' }); var $review = '
' + $readOnlyRatings.prop('outerHTML') + // Get the HTML string of the rateYo plugin '

' + $heading + '

' + '' + $comment + '' + '
'; return $review; } }, { // date targets: 5, render: function (data, type, full, meta) { var date = new Date(full.date); // convert the date string to a Date object var formattedDate = date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }); return '' + formattedDate + ''; } }, { // User Status targets: 6, render: function (data, type, full, meta) { var $status = full['status']; return ( '' + statusObj[$status].title + '' ); } }, { // Actions targets: -1, title: 'Actions', searchable: false, orderable: false, render: function (data, type, full, meta) { return ( '
' + '' + '
' ); } } ], order: [[2, 'asc']], dom: '<"card-header d-flex align-items-md-center pb-md-2 flex-wrap"' + '<"me-5 ms-n2"f>' + '<"dt-action-buttons text-xl-end text-lg-start text-md-end text-start d-flex align-items-end align-items-md-center justify-content-md-end pt-0 gap-3 flex-wrap"l<"review_filter"> <"mx-0 me-md-n3 mt-sm-0"B>>' + '>t' + '<"row mx-2"' + '<"col-sm-12 col-md-6"i>' + '<"col-sm-12 col-md-6"p>' + '>', language: { sLengthMenu: '_MENU_', search: '', searchPlaceholder: 'Search Review' }, // Buttons with Dropdown buttons: [ { extend: 'collection', className: 'btn btn-label-secondary dropdown-toggle me-3', text: 'Export', buttons: [ { extend: 'print', text: 'Print', className: 'dropdown-item', exportOptions: { columns: [1, 2, 3, 4, 5, 6], // prevent avatar to be print format: { body: function (inner, coldex, rowdex) { if (inner.length <= 0) return inner; var el = $.parseHTML(inner); var result = ''; $.each(el, function (index, item) { if (item.classList !== undefined && item.classList.contains('customer-name')) { result = result + item.lastChild.firstChild.textContent; } else if (item.innerText === undefined) { result = result + item.textContent; } else result = result + item.innerText; }); return result; } } }, customize: function (win) { //customize print view for dark $(win.document.body) .css('color', headingColor) .css('border-color', borderColor) .css('background-color', bodyBg); $(win.document.body) .find('table') .addClass('compact') .css('color', 'inherit') .css('border-color', 'inherit') .css('background-color', 'inherit'); } }, { extend: 'csv', text: 'Csv', className: 'dropdown-item', exportOptions: { columns: [1, 2, 3, 4, 5, 6], // prevent avatar to be display format: { body: function (inner, coldex, rowdex) { if (inner.length <= 0) return inner; var el = $.parseHTML(inner); var result = ''; $.each(el, function (index, item) { if (item.classList !== undefined && item.classList.contains('customer-name')) { result = result + item.lastChild.firstChild.textContent; } else if (item.innerText === undefined) { result = result + item.textContent; } else result = result + item.innerText; }); return result; } } } }, { extend: 'excel', text: 'Excel', className: 'dropdown-item', exportOptions: { columns: [1, 2, 3, 4, 5, 6], // prevent avatar to be display format: { body: function (inner, coldex, rowdex) { if (inner.length <= 0) return inner; var el = $.parseHTML(inner); var result = ''; $.each(el, function (index, item) { if (item.classList !== undefined && item.classList.contains('customer-name')) { result = result + item.lastChild.firstChild.textContent; } else if (item.innerText === undefined) { result = result + item.textContent; } else result = result + item.innerText; }); return result; } } } }, { extend: 'pdf', text: 'Pdf', className: 'dropdown-item', exportOptions: { columns: [1, 2, 3, 4, 5, 6], // prevent avatar to be display format: { body: function (inner, coldex, rowdex) { if (inner.length <= 0) return inner; var el = $.parseHTML(inner); var result = ''; $.each(el, function (index, item) { if (item.classList !== undefined && item.classList.contains('customer-name')) { result = result + item.lastChild.firstChild.textContent; } else if (item.innerText === undefined) { result = result + item.textContent; } else result = result + item.innerText; }); return result; } } } }, { extend: 'copy', text: 'Copy', className: 'dropdown-item', exportOptions: { columns: [1, 2, 3, 4, 5, 6], // prevent avatar to be display format: { body: function (inner, coldex, rowdex) { if (inner.length <= 0) return inner; var el = $.parseHTML(inner); var result = ''; $.each(el, function (index, item) { if (item.classList !== undefined && item.classList.contains('customer-name')) { result = result + item.lastChild.firstChild.textContent; } else if (item.innerText === undefined) { result = result + item.textContent; } else result = result + item.innerText; }); return result; } } } } ] } ], // For responsive popup responsive: { details: { display: $.fn.dataTable.Responsive.display.modal({ header: function (row) { var data = row.data(); return 'Details of ' + data['reviewer']; } }), type: 'column', renderer: function (api, rowIdx, columns) { var data = $.map(columns, function (col, i) { return col.title !== '' // ? Do not show row in modal popup if title is blank (for check box) ? '' + '' + col.title + ':' + ' ' + '' + col.data + '' + '' : ''; }).join(''); return data ? $('').append(data) : false; } } }, initComplete: function () { // Adding role filter once table initialized this.api() .columns(6) .every(function () { var column = this; var select = $('') .appendTo('.review_filter') .on('change', function () { var val = $.fn.dataTable.util.escapeRegex($(this).val()); column.search(val ? '^' + val + '$' : '', true, false).draw(); }); column .data() .unique() .sort() .each(function (d, j) { select.append(''); }); }); } }); $('.dataTables_length').addClass('mt-0 mt-md-3'); // To remove default btn-secondary in export buttons $('.dt-buttons > .btn-group > button').removeClass('btn-secondary'); } // Delete Record $('.datatables-review tbody').on('click', '.delete-record', function () { dt_review.row($(this).parents('tr')).remove().draw(); }); // Filter form control to default size // ? setTimeout used for multilingual table initialization setTimeout(() => { $('.dataTables_filter .form-control').removeClass('form-control-sm'); $('.dataTables_length .form-select').removeClass('form-select-sm'); }, 300); });