/** * Page eCommerce Referral */ 'use strict'; // 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_user_table = $('.datatables-referral'), customerView = 'app-ecommerce-customer-details-overview.html', statusObj = { 1: { title: 'Paid', class: 'bg-label-success' }, 2: { title: 'Unpaid', class: 'bg-label-warning' }, 3: { title: 'Rejected', class: 'bg-label-danger' } }; // Users datatable if (dt_user_table.length) { var dt_user = dt_user_table.DataTable({ ajax: assetsPath + 'json/ecommerce-referral.json', // JSON file to add data columns: [ // columns according to JSON { data: '' }, { data: 'id' }, { data: 'user' }, { data: 'referred_id' }, { data: 'status' }, { data: 'value' }, { data: 'earning' } ], 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: '' } }, { // eCommerce full name and email targets: 2, responsivePriority: 1, render: function (data, type, full, meta) { var $name = full['user'], $email = full['email'], $image = full['avatar']; if ($image) { // 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['user'], $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; } }, { // eCommerce Role targets: 3, render: function (data, type, full, meta) { var $role = full['referred_id']; return '' + $role + ''; } }, { // eCommerce Status targets: 4, render: function (data, type, full, meta) { var $status = full['status']; return ( '' + statusObj[$status].title + '' ); } }, { // value targets: 5, render: function (data, type, full, meta) { var $plan = full['value']; return '' + $plan + ''; } }, { // earning targets: 6, render: function (data, type, full, meta) { var $earn = full['earning']; return '' + $earn + ' '; } } ], order: [[2, 'asc']], dom: '<"card-header d-flex flex-column flex-sm-row align-items-center py-0"<"head-label"><"d-flex align-items-center justify-content-end"l<"dt-action-buttons"B>>' + '>t' + '<"row"' + '<"col-sm-12 col-md-6"i>' + '<"col-sm-12 col-md-6"p>' + '>', language: { sLengthMenu: '_MENU_', paginate: { next: '', previous: '' } }, // Buttons with Dropdown buttons: [ { extend: 'collection', className: 'btn btn-label-secondary dropdown-toggle', text: 'Export', buttons: [ { extend: 'print', text: 'Print', className: 'dropdown-item', exportOptions: { columns: [1, 2, 3, 4, 5], // 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('user-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], // 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('user-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], // 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('user-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], // 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('user-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], // 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('user-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['user']; } }), 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; } } } }); $('div.head-label').html('
Referred users
'); $('.dataTables_length').addClass('me-2 ms-n2 ms-sm-0'); $('.dt-action-buttons').addClass('pt-0'); } // 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); });