/** * App eCommerce Category List */ 'use strict'; // Comment editor const commentEditor = document.querySelector('.comment-editor'); if (commentEditor) { new Quill(commentEditor, { modules: { toolbar: '.comment-toolbar' }, placeholder: 'Write a Comment...', theme: 'snow' }); } // 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 category list table var dt_category_list_table = $('.datatables-category-list'); //select2 for dropdowns in offcanvas var select2 = $('.select2'); if (select2.length) { select2.each(function () { var $this = $(this); $this.wrap('
').select2({ dropdownParent: $this.parent(), placeholder: $this.data('placeholder') //for dynamic placeholder }); }); } // Customers List Datatable if (dt_category_list_table.length) { var dt_category = dt_category_list_table.DataTable({ ajax: assetsPath + 'json/ecommerce-category-list.json', // JSON file to add data columns: [ // columns according to JSON { data: '' }, { data: 'id' }, { data: 'categories' }, { data: 'total_products' }, { data: 'total_earnings' }, { data: '' } ], columnDefs: [ { // For Responsive className: 'control', searchable: false, orderable: false, responsivePriority: 1, targets: 0, render: function (data, type, full, meta) { return ''; } }, { // For Checkboxes targets: 1, orderable: false, searchable: false, responsivePriority: 4, checkboxes: true, render: function () { return ''; }, checkboxes: { selectAllRender: '' } }, { // Categories and Category Detail targets: 2, responsivePriority: 2, render: function (data, type, full, meta) { var $name = full['categories'], $category_detail = full['category_detail'], $image = full['cat_image'], $id = full['id']; if ($image) { // For Product image var $output = 'Product-' +
                $id +
                ''; } else { // For Product badge var stateNum = Math.floor(Math.random() * 6); var states = ['success', 'danger', 'warning', 'info', 'dark', 'primary', 'secondary']; var $state = states[stateNum], $name = full['category_detail'], $initials = $name.match(/\b\w/g) || []; $initials = (($initials.shift() || '') + ($initials.pop() || '')).toUpperCase(); $output = '' + $initials + ''; } // Creates full output for Categories and Category Detail var $row_output = '
' + '
' + '
' + $output + '
' + '
' + '
' + '' + $name + '' + '' + $category_detail + '' + '
' + '
'; return $row_output; } }, { // Total products targets: 3, responsivePriority: 3, render: function (data, type, full, meta) { var $total_products = full['total_products']; return '
' + $total_products + '
'; } }, { // Total Earnings targets: 4, orderable: false, render: function (data, type, full, meta) { var $total_earnings = full['total_earnings']; return "
" + $total_earnings + '' + '' + '' + '' + '
' ); } } ], order: [2, 'desc'], //set any columns order asc/desc dom: '<"card-header d-flex flex-wrap py-0 flex-column flex-sm-row"' + '' + '<"d-flex justify-content-center justify-content-md-end align-items-baseline"<"dt-action-buttons d-flex justify-content-center flex-md-row align-items-baseline"lB>>' + '>t' + '<"row"' + '<"col-sm-12 col-md-6"i>' + '<"col-sm-12 col-md-6"p>' + '>', lengthMenu: [7, 10, 20, 50, 70, 100], //for length of menu language: { sLengthMenu: '_MENU_', search: '', searchPlaceholder: 'Search Category', paginate: { next: '', previous: '' } }, // Button for offcanvas buttons: [ { text: 'Add Category', className: 'add-new btn btn-primary ms-2', attr: { 'data-bs-toggle': 'offcanvas', 'data-bs-target': '#offcanvasEcommerceCategoryList' } } ], // For responsive popup responsive: { details: { display: $.fn.dataTable.Responsive.display.modal({ header: function (row) { var data = row.data(); return 'Details of ' + data['categories']; } }), 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; } } } }); $('.dt-action-buttons').addClass('pt-0'); $('.dataTables_filter').addClass('me-3 mb-sm-6 mb-0 ps-0'); } // Filter form control to default size // ? setTimeout used for multilingual table initialization setTimeout(() => { $('.dataTables_filter .form-control').removeClass('form-control-sm'); $('.dataTables_filter .form-control').addClass('ms-0'); $('.dataTables_length .form-select').removeClass('form-select-sm'); $('.dataTables_length .form-select').addClass('ms-0'); }, 300); }); //For form validation (function () { const eCommerceCategoryListForm = document.getElementById('eCommerceCategoryListForm'); //Add New customer Form Validation const fv = FormValidation.formValidation(eCommerceCategoryListForm, { fields: { categoryTitle: { validators: { notEmpty: { message: 'Please enter category title' } } }, slug: { validators: { notEmpty: { message: 'Please enter slug' } } } }, plugins: { trigger: new FormValidation.plugins.Trigger(), bootstrap5: new FormValidation.plugins.Bootstrap5({ // Use this for enabling/changing valid/invalid class eleValidClass: 'is-valid', rowSelector: function (field, ele) { // field is the field name & ele is the field element return '.mb-6'; } }), submitButton: new FormValidation.plugins.SubmitButton(), // Submit the form when all fields are valid // defaultSubmit: new FormValidation.plugins.DefaultSubmit(), autoFocus: new FormValidation.plugins.AutoFocus() } }); })();