initial commit
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTAppEcommerceCategories = function () {
|
||||
// Shared variables
|
||||
var table;
|
||||
var datatable;
|
||||
|
||||
// Private functions
|
||||
var initDatatable = function () {
|
||||
// Init datatable --- more info on datatables: https://datatables.net/manual/
|
||||
datatable = $(table).DataTable({
|
||||
"info": false,
|
||||
'order': [],
|
||||
'pageLength': 10,
|
||||
'columnDefs': [
|
||||
{ orderable: false, targets: 0 }, // Disable ordering on column 0 (checkbox)
|
||||
{ orderable: false, targets: 3 }, // Disable ordering on column 3 (actions)
|
||||
]
|
||||
});
|
||||
|
||||
// Re-init functions on datatable re-draws
|
||||
datatable.on('draw', function () {
|
||||
handleDeleteRows();
|
||||
});
|
||||
}
|
||||
|
||||
// Search Datatable --- official docs reference: https://datatables.net/reference/api/search()
|
||||
var handleSearchDatatable = () => {
|
||||
const filterSearch = document.querySelector('[data-kt-ecommerce-category-filter="search"]');
|
||||
filterSearch.addEventListener('keyup', function (e) {
|
||||
datatable.search(e.target.value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Delete cateogry
|
||||
var handleDeleteRows = () => {
|
||||
// Select all delete buttons
|
||||
const deleteButtons = table.querySelectorAll('[data-kt-ecommerce-category-filter="delete_row"]');
|
||||
|
||||
deleteButtons.forEach(d => {
|
||||
// Delete button on click
|
||||
d.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Select parent row
|
||||
const parent = e.target.closest('tr');
|
||||
|
||||
// Get category name
|
||||
const categoryName = parent.querySelector('[data-kt-ecommerce-category-filter="category_name"]').innerText;
|
||||
|
||||
// SweetAlert2 pop up --- official docs reference: https://sweetalert2.github.io/
|
||||
Swal.fire({
|
||||
text: "Are you sure you want to delete " + categoryName + "?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, delete!",
|
||||
cancelButtonText: "No, cancel",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-danger",
|
||||
cancelButton: "btn fw-bold btn-active-light-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
Swal.fire({
|
||||
text: "You have deleted " + categoryName + "!.",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-primary",
|
||||
}
|
||||
}).then(function () {
|
||||
// Remove current row
|
||||
datatable.row($(parent)).remove().draw();
|
||||
});
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: categoryName + " was not deleted.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Public methods
|
||||
return {
|
||||
init: function () {
|
||||
table = document.querySelector('#kt_ecommerce_category_table');
|
||||
|
||||
if (!table) {
|
||||
return;
|
||||
}
|
||||
|
||||
initDatatable();
|
||||
handleSearchDatatable();
|
||||
handleDeleteRows();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTAppEcommerceCategories.init();
|
||||
});
|
||||
@@ -0,0 +1,128 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTAppEcommerceProducts = function () {
|
||||
// Shared variables
|
||||
var table;
|
||||
var datatable;
|
||||
|
||||
// Private functions
|
||||
var initDatatable = function () {
|
||||
// Init datatable --- more info on datatables: https://datatables.net/manual/
|
||||
datatable = $(table).DataTable({
|
||||
"info": false,
|
||||
'order': [],
|
||||
'pageLength': 10,
|
||||
'columnDefs': [
|
||||
{ render: DataTable.render.number(',', '.', 2), targets: 4},
|
||||
{ orderable: false, targets: 0 }, // Disable ordering on column 0 (checkbox)
|
||||
{ orderable: false, targets: 7 }, // Disable ordering on column 7 (actions)
|
||||
]
|
||||
});
|
||||
|
||||
// Re-init functions on datatable re-draws
|
||||
datatable.on('draw', function () {
|
||||
handleDeleteRows();
|
||||
});
|
||||
}
|
||||
|
||||
// Search Datatable --- official docs reference: https://datatables.net/reference/api/search()
|
||||
var handleSearchDatatable = () => {
|
||||
const filterSearch = document.querySelector('[data-kt-ecommerce-product-filter="search"]');
|
||||
filterSearch.addEventListener('keyup', function (e) {
|
||||
datatable.search(e.target.value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Handle status filter dropdown
|
||||
var handleStatusFilter = () => {
|
||||
const filterStatus = document.querySelector('[data-kt-ecommerce-product-filter="status"]');
|
||||
$(filterStatus).on('change', e => {
|
||||
let value = e.target.value;
|
||||
if(value === 'all'){
|
||||
value = '';
|
||||
}
|
||||
datatable.column(6).search(value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Delete cateogry
|
||||
var handleDeleteRows = () => {
|
||||
// Select all delete buttons
|
||||
const deleteButtons = table.querySelectorAll('[data-kt-ecommerce-product-filter="delete_row"]');
|
||||
|
||||
deleteButtons.forEach(d => {
|
||||
// Delete button on click
|
||||
d.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Select parent row
|
||||
const parent = e.target.closest('tr');
|
||||
|
||||
// Get category name
|
||||
const productName = parent.querySelector('[data-kt-ecommerce-product-filter="product_name"]').innerText;
|
||||
|
||||
// SweetAlert2 pop up --- official docs reference: https://sweetalert2.github.io/
|
||||
Swal.fire({
|
||||
text: "Are you sure you want to delete " + productName + "?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, delete!",
|
||||
cancelButtonText: "No, cancel",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-danger",
|
||||
cancelButton: "btn fw-bold btn-active-light-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
Swal.fire({
|
||||
text: "You have deleted " + productName + "!.",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-primary",
|
||||
}
|
||||
}).then(function () {
|
||||
// Remove current row
|
||||
datatable.row($(parent)).remove().draw();
|
||||
});
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: productName + " was not deleted.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Public methods
|
||||
return {
|
||||
init: function () {
|
||||
table = document.querySelector('#kt_ecommerce_products_table');
|
||||
|
||||
if (!table) {
|
||||
return;
|
||||
}
|
||||
|
||||
initDatatable();
|
||||
handleSearchDatatable();
|
||||
handleStatusFilter();
|
||||
handleDeleteRows();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTAppEcommerceProducts.init();
|
||||
});
|
||||
@@ -0,0 +1,287 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTAppEcommerceSaveCategory = function () {
|
||||
|
||||
// Private functions
|
||||
|
||||
// Init quill editor
|
||||
const initQuill = () => {
|
||||
// Define all elements for quill editor
|
||||
const elements = [
|
||||
'#kt_ecommerce_add_category_description',
|
||||
'#kt_ecommerce_add_category_meta_description'
|
||||
];
|
||||
|
||||
// Loop all elements
|
||||
elements.forEach(element => {
|
||||
// Get quill element
|
||||
let quill = document.querySelector(element);
|
||||
|
||||
// Break if element not found
|
||||
if (!quill) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Init quill --- more info: https://quilljs.com/docs/quickstart/
|
||||
quill = new Quill(element, {
|
||||
modules: {
|
||||
toolbar: [
|
||||
[{
|
||||
header: [1, 2, false]
|
||||
}],
|
||||
['bold', 'italic', 'underline'],
|
||||
['image', 'code-block']
|
||||
]
|
||||
},
|
||||
placeholder: 'Type your text here...',
|
||||
theme: 'snow' // or 'bubble'
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Init tagify
|
||||
const initTagify = () => {
|
||||
// Define all elements for tagify
|
||||
const elements = [
|
||||
'#kt_ecommerce_add_category_meta_keywords'
|
||||
];
|
||||
|
||||
// Loop all elements
|
||||
elements.forEach(element => {
|
||||
// Get tagify element
|
||||
const tagify = document.querySelector(element);
|
||||
|
||||
// Break if element not found
|
||||
if (!tagify) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Init tagify --- more info: https://yaireo.github.io/tagify/
|
||||
new Tagify(tagify);
|
||||
});
|
||||
}
|
||||
|
||||
// Init form repeater --- more info: https://github.com/DubFriend/jquery.repeater
|
||||
const initFormRepeater = () => {
|
||||
$('#kt_ecommerce_add_category_conditions').repeater({
|
||||
initEmpty: false,
|
||||
|
||||
defaultValues: {
|
||||
'text-input': 'foo'
|
||||
},
|
||||
|
||||
show: function () {
|
||||
$(this).slideDown();
|
||||
|
||||
// Init select2 on new repeated items
|
||||
initConditionsSelect2();
|
||||
},
|
||||
|
||||
hide: function (deleteElement) {
|
||||
$(this).slideUp(deleteElement);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Init condition select2
|
||||
const initConditionsSelect2 = () => {
|
||||
// Tnit new repeating condition types
|
||||
const allConditionTypes = document.querySelectorAll('[data-kt-ecommerce-catalog-add-category="condition_type"]');
|
||||
allConditionTypes.forEach(type => {
|
||||
if ($(type).hasClass("select2-hidden-accessible")) {
|
||||
return;
|
||||
} else {
|
||||
$(type).select2({
|
||||
minimumResultsForSearch: -1
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Tnit new repeating condition equals
|
||||
const allConditionEquals = document.querySelectorAll('[data-kt-ecommerce-catalog-add-category="condition_equals"]');
|
||||
allConditionEquals.forEach(equal => {
|
||||
if ($(equal).hasClass("select2-hidden-accessible")) {
|
||||
return;
|
||||
} else {
|
||||
$(equal).select2({
|
||||
minimumResultsForSearch: -1
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Category status handler
|
||||
const handleStatus = () => {
|
||||
const target = document.getElementById('kt_ecommerce_add_category_status');
|
||||
const select = document.getElementById('kt_ecommerce_add_category_status_select');
|
||||
const statusClasses = ['bg-success', 'bg-warning', 'bg-danger'];
|
||||
|
||||
$(select).on('change', function (e) {
|
||||
const value = e.target.value;
|
||||
|
||||
switch (value) {
|
||||
case "published": {
|
||||
target.classList.remove(...statusClasses);
|
||||
target.classList.add('bg-success');
|
||||
hideDatepicker();
|
||||
break;
|
||||
}
|
||||
case "scheduled": {
|
||||
target.classList.remove(...statusClasses);
|
||||
target.classList.add('bg-warning');
|
||||
showDatepicker();
|
||||
break;
|
||||
}
|
||||
case "unpublished": {
|
||||
target.classList.remove(...statusClasses);
|
||||
target.classList.add('bg-danger');
|
||||
hideDatepicker();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Handle datepicker
|
||||
const datepicker = document.getElementById('kt_ecommerce_add_category_status_datepicker');
|
||||
|
||||
// Init flatpickr --- more info: https://flatpickr.js.org/
|
||||
$('#kt_ecommerce_add_category_status_datepicker').flatpickr({
|
||||
enableTime: true,
|
||||
dateFormat: "Y-m-d H:i",
|
||||
});
|
||||
|
||||
const showDatepicker = () => {
|
||||
datepicker.parentNode.classList.remove('d-none');
|
||||
}
|
||||
|
||||
const hideDatepicker = () => {
|
||||
datepicker.parentNode.classList.add('d-none');
|
||||
}
|
||||
}
|
||||
|
||||
// Condition type handler
|
||||
const handleConditions = () => {
|
||||
const allConditions = document.querySelectorAll('[name="method"][type="radio"]');
|
||||
const conditionMatch = document.querySelector('[data-kt-ecommerce-catalog-add-category="auto-options"]');
|
||||
allConditions.forEach(radio => {
|
||||
radio.addEventListener('change', e => {
|
||||
if (e.target.value === '1') {
|
||||
conditionMatch.classList.remove('d-none');
|
||||
} else {
|
||||
conditionMatch.classList.add('d-none');
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
// Submit form handler
|
||||
const handleSubmit = () => {
|
||||
// Define variables
|
||||
let validator;
|
||||
|
||||
// Get elements
|
||||
const form = document.getElementById('kt_ecommerce_add_category_form');
|
||||
const submitButton = document.getElementById('kt_ecommerce_add_category_submit');
|
||||
|
||||
// Init form validation rules. For more info check the FormValidation plugin's official documentation:https://formvalidation.io/
|
||||
validator = FormValidation.formValidation(
|
||||
form,
|
||||
{
|
||||
fields: {
|
||||
'category_name': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Category name is required'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap: new FormValidation.plugins.Bootstrap5({
|
||||
rowSelector: '.fv-row',
|
||||
eleInvalidClass: '',
|
||||
eleValidClass: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Handle submit button
|
||||
submitButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
// Validate form before submit
|
||||
if (validator) {
|
||||
validator.validate().then(function (status) {
|
||||
console.log('validated!');
|
||||
|
||||
if (status == 'Valid') {
|
||||
submitButton.setAttribute('data-kt-indicator', 'on');
|
||||
|
||||
// Disable submit button whilst loading
|
||||
submitButton.disabled = true;
|
||||
|
||||
setTimeout(function () {
|
||||
submitButton.removeAttribute('data-kt-indicator');
|
||||
|
||||
Swal.fire({
|
||||
text: "Form has been successfully submitted!",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
// Enable submit button after loading
|
||||
submitButton.disabled = false;
|
||||
|
||||
// Redirect to customers list page
|
||||
window.location = form.getAttribute("data-kt-redirect");
|
||||
}
|
||||
});
|
||||
}, 2000);
|
||||
} else {
|
||||
Swal.fire({
|
||||
text: "Sorry, looks like there are some errors detected, please try again.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Public methods
|
||||
return {
|
||||
init: function () {
|
||||
// Init forms
|
||||
initQuill();
|
||||
initTagify();
|
||||
initFormRepeater();
|
||||
initConditionsSelect2();
|
||||
|
||||
// Handle forms
|
||||
handleStatus();
|
||||
handleConditions();
|
||||
handleSubmit();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTAppEcommerceSaveCategory.init();
|
||||
});
|
||||
@@ -0,0 +1,416 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTAppEcommerceSaveProduct = function () {
|
||||
|
||||
// Private functions
|
||||
|
||||
// Init quill editor
|
||||
const initQuill = () => {
|
||||
// Define all elements for quill editor
|
||||
const elements = [
|
||||
'#kt_ecommerce_add_product_description',
|
||||
'#kt_ecommerce_add_product_meta_description'
|
||||
];
|
||||
|
||||
// Loop all elements
|
||||
elements.forEach(element => {
|
||||
// Get quill element
|
||||
let quill = document.querySelector(element);
|
||||
|
||||
// Break if element not found
|
||||
if (!quill) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Init quill --- more info: https://quilljs.com/docs/quickstart/
|
||||
quill = new Quill(element, {
|
||||
modules: {
|
||||
toolbar: [
|
||||
[{
|
||||
header: [1, 2, false]
|
||||
}],
|
||||
['bold', 'italic', 'underline'],
|
||||
['image', 'code-block']
|
||||
]
|
||||
},
|
||||
placeholder: 'Type your text here...',
|
||||
theme: 'snow' // or 'bubble'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Init tagify
|
||||
const initTagify = () => {
|
||||
// Define all elements for tagify
|
||||
const elements = [
|
||||
'#kt_ecommerce_add_product_category',
|
||||
'#kt_ecommerce_add_product_tags'
|
||||
];
|
||||
|
||||
// Loop all elements
|
||||
elements.forEach(element => {
|
||||
// Get tagify element
|
||||
const tagify = document.querySelector(element);
|
||||
|
||||
// Break if element not found
|
||||
if (!tagify) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Init tagify --- more info: https://yaireo.github.io/tagify/
|
||||
new Tagify(tagify, {
|
||||
whitelist: ["new", "trending", "sale", "discounted", "selling fast", "last 10"],
|
||||
dropdown: {
|
||||
maxItems: 20, // <- mixumum allowed rendered suggestions
|
||||
classname: "tagify__inline__suggestions", // <- custom classname for this dropdown, so it could be targeted
|
||||
enabled: 0, // <- show suggestions on focus
|
||||
closeOnSelect: false // <- do not hide the suggestions dropdown once an item has been selected
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Init form repeater --- more info: https://github.com/DubFriend/jquery.repeater
|
||||
const initFormRepeater = () => {
|
||||
$('#kt_ecommerce_add_product_options').repeater({
|
||||
initEmpty: false,
|
||||
|
||||
defaultValues: {
|
||||
'text-input': 'foo'
|
||||
},
|
||||
|
||||
show: function () {
|
||||
$(this).slideDown();
|
||||
|
||||
// Init select2 on new repeated items
|
||||
initConditionsSelect2();
|
||||
},
|
||||
|
||||
hide: function (deleteElement) {
|
||||
$(this).slideUp(deleteElement);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Init condition select2
|
||||
const initConditionsSelect2 = () => {
|
||||
// Tnit new repeating condition types
|
||||
const allConditionTypes = document.querySelectorAll('[data-kt-ecommerce-catalog-add-product="product_option"]');
|
||||
allConditionTypes.forEach(type => {
|
||||
if ($(type).hasClass("select2-hidden-accessible")) {
|
||||
return;
|
||||
} else {
|
||||
$(type).select2({
|
||||
minimumResultsForSearch: -1
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Init noUIslider
|
||||
const initSlider = () => {
|
||||
var slider = document.querySelector("#kt_ecommerce_add_product_discount_slider");
|
||||
var value = document.querySelector("#kt_ecommerce_add_product_discount_label");
|
||||
|
||||
noUiSlider.create(slider, {
|
||||
start: [10],
|
||||
connect: true,
|
||||
range: {
|
||||
"min": 1,
|
||||
"max": 100
|
||||
}
|
||||
});
|
||||
|
||||
slider.noUiSlider.on("update", function (values, handle) {
|
||||
value.innerHTML = Math.round(values[handle]);
|
||||
if (handle) {
|
||||
value.innerHTML = Math.round(values[handle]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Init DropzoneJS --- more info:
|
||||
const initDropzone = () => {
|
||||
var myDropzone = new Dropzone("#kt_ecommerce_add_product_media", {
|
||||
url: "https://keenthemes.com/scripts/void.php", // Set the url for your upload script location
|
||||
paramName: "file", // The name that will be used to transfer the file
|
||||
maxFiles: 10,
|
||||
maxFilesize: 10, // MB
|
||||
addRemoveLinks: true,
|
||||
accept: function (file, done) {
|
||||
if (file.name == "wow.jpg") {
|
||||
done("Naha, you don't.");
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Handle discount options
|
||||
const handleDiscount = () => {
|
||||
const discountOptions = document.querySelectorAll('input[name="discount_option"]');
|
||||
const percentageEl = document.getElementById('kt_ecommerce_add_product_discount_percentage');
|
||||
const fixedEl = document.getElementById('kt_ecommerce_add_product_discount_fixed');
|
||||
|
||||
discountOptions.forEach(option => {
|
||||
option.addEventListener('change', e => {
|
||||
const value = e.target.value;
|
||||
|
||||
switch (value) {
|
||||
case '2': {
|
||||
percentageEl.classList.remove('d-none');
|
||||
fixedEl.classList.add('d-none');
|
||||
break;
|
||||
}
|
||||
case '3': {
|
||||
percentageEl.classList.add('d-none');
|
||||
fixedEl.classList.remove('d-none');
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
percentageEl.classList.add('d-none');
|
||||
fixedEl.classList.add('d-none');
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Shipping option handler
|
||||
const handleShipping = () => {
|
||||
const shippingOption = document.getElementById('kt_ecommerce_add_product_shipping_checkbox');
|
||||
const shippingForm = document.getElementById('kt_ecommerce_add_product_shipping');
|
||||
|
||||
shippingOption.addEventListener('change', e => {
|
||||
const value = e.target.checked;
|
||||
|
||||
if (value) {
|
||||
shippingForm.classList.remove('d-none');
|
||||
} else {
|
||||
shippingForm.classList.add('d-none');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Category status handler
|
||||
const handleStatus = () => {
|
||||
const target = document.getElementById('kt_ecommerce_add_product_status');
|
||||
const select = document.getElementById('kt_ecommerce_add_product_status_select');
|
||||
const statusClasses = ['bg-success', 'bg-warning', 'bg-danger'];
|
||||
|
||||
$(select).on('change', function (e) {
|
||||
const value = e.target.value;
|
||||
|
||||
switch (value) {
|
||||
case "published": {
|
||||
target.classList.remove(...statusClasses);
|
||||
target.classList.add('bg-success');
|
||||
hideDatepicker();
|
||||
break;
|
||||
}
|
||||
case "scheduled": {
|
||||
target.classList.remove(...statusClasses);
|
||||
target.classList.add('bg-warning');
|
||||
showDatepicker();
|
||||
break;
|
||||
}
|
||||
case "inactive": {
|
||||
target.classList.remove(...statusClasses);
|
||||
target.classList.add('bg-danger');
|
||||
hideDatepicker();
|
||||
break;
|
||||
}
|
||||
case "draft": {
|
||||
target.classList.remove(...statusClasses);
|
||||
target.classList.add('bg-primary');
|
||||
hideDatepicker();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Handle datepicker
|
||||
const datepicker = document.getElementById('kt_ecommerce_add_product_status_datepicker');
|
||||
|
||||
// Init flatpickr --- more info: https://flatpickr.js.org/
|
||||
$('#kt_ecommerce_add_product_status_datepicker').flatpickr({
|
||||
enableTime: true,
|
||||
dateFormat: "Y-m-d H:i",
|
||||
});
|
||||
|
||||
const showDatepicker = () => {
|
||||
datepicker.parentNode.classList.remove('d-none');
|
||||
}
|
||||
|
||||
const hideDatepicker = () => {
|
||||
datepicker.parentNode.classList.add('d-none');
|
||||
}
|
||||
}
|
||||
|
||||
// Condition type handler
|
||||
const handleConditions = () => {
|
||||
const allConditions = document.querySelectorAll('[name="method"][type="radio"]');
|
||||
const conditionMatch = document.querySelector('[data-kt-ecommerce-catalog-add-category="auto-options"]');
|
||||
allConditions.forEach(radio => {
|
||||
radio.addEventListener('change', e => {
|
||||
if (e.target.value === '1') {
|
||||
conditionMatch.classList.remove('d-none');
|
||||
} else {
|
||||
conditionMatch.classList.add('d-none');
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
// Submit form handler
|
||||
const handleSubmit = () => {
|
||||
// Define variables
|
||||
let validator;
|
||||
|
||||
// Get elements
|
||||
const form = document.getElementById('kt_ecommerce_add_product_form');
|
||||
const submitButton = document.getElementById('kt_ecommerce_add_product_submit');
|
||||
|
||||
// Init form validation rules. For more info check the FormValidation plugin's official documentation:https://formvalidation.io/
|
||||
validator = FormValidation.formValidation(
|
||||
form,
|
||||
{
|
||||
fields: {
|
||||
'product_name': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Product name is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'sku': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'SKU is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'sku': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Product barcode is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'shelf': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Shelf quantity is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'price': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Product base price is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'tax': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Product tax class is required'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap: new FormValidation.plugins.Bootstrap5({
|
||||
rowSelector: '.fv-row',
|
||||
eleInvalidClass: '',
|
||||
eleValidClass: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Handle submit button
|
||||
submitButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
// Validate form before submit
|
||||
if (validator) {
|
||||
validator.validate().then(function (status) {
|
||||
console.log('validated!');
|
||||
|
||||
if (status == 'Valid') {
|
||||
submitButton.setAttribute('data-kt-indicator', 'on');
|
||||
|
||||
// Disable submit button whilst loading
|
||||
submitButton.disabled = true;
|
||||
|
||||
setTimeout(function () {
|
||||
submitButton.removeAttribute('data-kt-indicator');
|
||||
|
||||
Swal.fire({
|
||||
text: "Form has been successfully submitted!",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
// Enable submit button after loading
|
||||
submitButton.disabled = false;
|
||||
|
||||
// Redirect to customers list page
|
||||
window.location = form.getAttribute("data-kt-redirect");
|
||||
}
|
||||
});
|
||||
}, 2000);
|
||||
} else {
|
||||
Swal.fire({
|
||||
html: "Sorry, looks like there are some errors detected, please try again. <br/><br/>Please note that there may be errors in the <strong>General</strong> or <strong>Advanced</strong> tabs",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Public methods
|
||||
return {
|
||||
init: function () {
|
||||
// Init forms
|
||||
initQuill();
|
||||
initTagify();
|
||||
initSlider();
|
||||
initFormRepeater();
|
||||
initDropzone();
|
||||
initConditionsSelect2();
|
||||
|
||||
// Handle forms
|
||||
handleStatus();
|
||||
handleConditions();
|
||||
handleDiscount();
|
||||
handleShipping();
|
||||
handleSubmit();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTAppEcommerceSaveProduct.init();
|
||||
});
|
||||
@@ -0,0 +1,214 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTModalAddAddress = function () {
|
||||
var submitButton;
|
||||
var cancelButton;
|
||||
var closeButton;
|
||||
var validator;
|
||||
var form;
|
||||
var modal;
|
||||
|
||||
// Init form inputs
|
||||
var handleForm = function () {
|
||||
// Init form validation rules. For more info check the FormValidation plugin's official documentation:https://formvalidation.io/
|
||||
validator = FormValidation.formValidation(
|
||||
form,
|
||||
{
|
||||
fields: {
|
||||
'name': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Address name is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'country': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Country is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'address1': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Address 1 is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'city': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'City is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'state': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'State is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'postcode': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Postcode is required'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap: new FormValidation.plugins.Bootstrap5({
|
||||
rowSelector: '.fv-row',
|
||||
eleInvalidClass: '',
|
||||
eleValidClass: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Revalidate country field. For more info, plase visit the official plugin site: https://select2.org/
|
||||
$(form.querySelector('[name="country"]')).on('change', function() {
|
||||
// Revalidate the field when an option is chosen
|
||||
validator.revalidateField('country');
|
||||
});
|
||||
|
||||
// Action buttons
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Validate form before submit
|
||||
if (validator) {
|
||||
validator.validate().then(function (status) {
|
||||
console.log('validated!');
|
||||
|
||||
if (status == 'Valid') {
|
||||
submitButton.setAttribute('data-kt-indicator', 'on');
|
||||
|
||||
// Disable submit button whilst loading
|
||||
submitButton.disabled = true;
|
||||
|
||||
setTimeout(function() {
|
||||
submitButton.removeAttribute('data-kt-indicator');
|
||||
|
||||
Swal.fire({
|
||||
text: "Form has been successfully submitted!",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
// Hide modal
|
||||
modal.hide();
|
||||
|
||||
// Enable submit button after loading
|
||||
submitButton.disabled = false;
|
||||
}
|
||||
});
|
||||
}, 2000);
|
||||
} else {
|
||||
Swal.fire({
|
||||
text: "Sorry, looks like there are some errors detected, please try again.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
cancelButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to cancel?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, cancel it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
form.reset(); // Reset form
|
||||
modal.hide(); // Hide modal
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Your form has not been cancelled!.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
closeButton.addEventListener('click', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to cancel?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, cancel it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
form.reset(); // Reset form
|
||||
modal.hide(); // Hide modal
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Your form has not been cancelled!.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
// Public functions
|
||||
init: function () {
|
||||
// Elements
|
||||
modal = new bootstrap.Modal(document.querySelector('#kt_modal_add_address'));
|
||||
|
||||
form = document.querySelector('#kt_modal_add_address_form');
|
||||
submitButton = form.querySelector('#kt_modal_add_address_submit');
|
||||
cancelButton = form.querySelector('#kt_modal_add_address_cancel');
|
||||
closeButton = form.querySelector('#kt_modal_add_address_close');
|
||||
|
||||
handleForm();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTModalAddAddress.init();
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTUsersAddAuthApp = function () {
|
||||
// Shared variables
|
||||
const element = document.getElementById('kt_modal_add_auth_app');
|
||||
const modal = new bootstrap.Modal(element);
|
||||
|
||||
// Init add schedule modal
|
||||
var initAddAuthApp = () => {
|
||||
|
||||
// Close button handler
|
||||
const closeButton = element.querySelector('[data-kt-users-modal-action="close"]');
|
||||
closeButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to close?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, close it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
modal.hide(); // Hide modal
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// QR code to text code swapper
|
||||
var initCodeSwap = () => {
|
||||
const qrCode = element.querySelector('[ data-kt-add-auth-action="qr-code"]');
|
||||
const textCode = element.querySelector('[ data-kt-add-auth-action="text-code"]');
|
||||
const qrCodeButton = element.querySelector('[ data-kt-add-auth-action="qr-code-button"]');
|
||||
const textCodeButton = element.querySelector('[ data-kt-add-auth-action="text-code-button"]');
|
||||
const qrCodeLabel = element.querySelector('[ data-kt-add-auth-action="qr-code-label"]');
|
||||
const textCodeLabel = element.querySelector('[ data-kt-add-auth-action="text-code-label"]');
|
||||
|
||||
const toggleClass = () =>{
|
||||
qrCode.classList.toggle('d-none');
|
||||
qrCodeButton.classList.toggle('d-none');
|
||||
qrCodeLabel.classList.toggle('d-none');
|
||||
textCode.classList.toggle('d-none');
|
||||
textCodeButton.classList.toggle('d-none');
|
||||
textCodeLabel.classList.toggle('d-none');
|
||||
}
|
||||
|
||||
// Swap to text code handler
|
||||
textCodeButton.addEventListener('click', e =>{
|
||||
e.preventDefault();
|
||||
|
||||
toggleClass();
|
||||
});
|
||||
|
||||
qrCodeButton.addEventListener('click', e =>{
|
||||
e.preventDefault();
|
||||
|
||||
toggleClass();
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
// Public functions
|
||||
init: function () {
|
||||
initAddAuthApp();
|
||||
initCodeSwap();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTUsersAddAuthApp.init();
|
||||
});
|
||||
@@ -0,0 +1,173 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTUsersAddOneTimePassword = function () {
|
||||
// Shared variables
|
||||
const element = document.getElementById('kt_modal_add_one_time_password');
|
||||
const form = element.querySelector('#kt_modal_add_one_time_password_form');
|
||||
const modal = new bootstrap.Modal(element);
|
||||
|
||||
// Init one time password modal
|
||||
var initAddOneTimePassword = () => {
|
||||
|
||||
// Init form validation rules. For more info check the FormValidation plugin's official documentation:https://formvalidation.io/
|
||||
var validator = FormValidation.formValidation(
|
||||
form,
|
||||
{
|
||||
fields: {
|
||||
'otp_mobile_number': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Valid mobile number is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'otp_confirm_password': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Password confirmation is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap: new FormValidation.plugins.Bootstrap5({
|
||||
rowSelector: '.fv-row',
|
||||
eleInvalidClass: '',
|
||||
eleValidClass: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Close button handler
|
||||
const closeButton = element.querySelector('[data-kt-users-modal-action="close"]');
|
||||
closeButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to close?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, close it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
modal.hide(); // Hide modal
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Cancel button handler
|
||||
const cancelButton = element.querySelector('[data-kt-users-modal-action="cancel"]');
|
||||
cancelButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to cancel?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, cancel it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
form.reset(); // Reset form
|
||||
modal.hide(); // Hide modal
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Your form has not been cancelled!.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Submit button handler
|
||||
const submitButton = element.querySelector('[data-kt-users-modal-action="submit"]');
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
// Prevent default button action
|
||||
e.preventDefault();
|
||||
|
||||
// Validate form before submit
|
||||
if (validator) {
|
||||
validator.validate().then(function (status) {
|
||||
console.log('validated!');
|
||||
|
||||
if (status == 'Valid') {
|
||||
// Show loading indication
|
||||
submitButton.setAttribute('data-kt-indicator', 'on');
|
||||
|
||||
// Disable button to avoid multiple click
|
||||
submitButton.disabled = true;
|
||||
|
||||
// Simulate form submission. For more info check the plugin's official documentation: https://sweetalert2.github.io/
|
||||
setTimeout(function () {
|
||||
// Remove loading indication
|
||||
submitButton.removeAttribute('data-kt-indicator');
|
||||
|
||||
// Enable button
|
||||
submitButton.disabled = false;
|
||||
|
||||
// Show popup confirmation
|
||||
Swal.fire({
|
||||
text: "Form has been successfully submitted!",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
modal.hide();
|
||||
}
|
||||
});
|
||||
|
||||
//form.submit(); // Submit form
|
||||
}, 2000);
|
||||
} else {
|
||||
// Show popup warning. For more info check the plugin's official documentation: https://sweetalert2.github.io/
|
||||
Swal.fire({
|
||||
text: "Sorry, looks like there are some errors detected, please try again.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
// Public functions
|
||||
init: function () {
|
||||
initAddOneTimePassword();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTUsersAddOneTimePassword.init();
|
||||
});
|
||||
@@ -0,0 +1,110 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTCustomerViewPaymentMethod = function () {
|
||||
|
||||
// Private functions
|
||||
var initPaymentMethod = function () {
|
||||
// Define variables
|
||||
const table = document.getElementById('kt_customer_view_payment_method');
|
||||
const tableRows = table.querySelectorAll('[ data-kt-customer-payment-method="row"]');
|
||||
|
||||
tableRows.forEach(row => {
|
||||
// Select delete button
|
||||
const deleteButton = row.querySelector('[data-kt-customer-payment-method="delete"]');
|
||||
|
||||
// Delete button action
|
||||
deleteButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
// Popup confirmation
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to delete this card?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, delete it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
row.remove();
|
||||
modal.hide(); // Hide modal
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Your card was not deleted!.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Handle set as primary button
|
||||
const handlePrimaryButton = () => {
|
||||
// Define variable
|
||||
const button = document.querySelector('[data-kt-payment-mehtod-action="set_as_primary"]');
|
||||
|
||||
button.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
// Popup confirmation
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to set this card as primary?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, set it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
Swal.fire({
|
||||
text: "Your card was set to primary!.",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Your card was not set to primary!.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Public methods
|
||||
return {
|
||||
init: function () {
|
||||
initPaymentMethod();
|
||||
handlePrimaryButton();
|
||||
}
|
||||
}
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTCustomerViewPaymentMethod.init();
|
||||
});
|
||||
@@ -0,0 +1,110 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTCustomerViewPaymentTable = function () {
|
||||
|
||||
// Define shared variables
|
||||
var datatable;
|
||||
var table = document.querySelector('#kt_table_customers_payment');
|
||||
|
||||
// Private functions
|
||||
var initCustomerView = function () {
|
||||
// Set date data order
|
||||
const tableRows = table.querySelectorAll('tbody tr');
|
||||
|
||||
tableRows.forEach(row => {
|
||||
const dateRow = row.querySelectorAll('td');
|
||||
const realDate = moment(dateRow[3].innerHTML, "DD MMM YYYY, LT").format(); // select date from 4th column in table
|
||||
dateRow[3].setAttribute('data-order', realDate);
|
||||
});
|
||||
|
||||
// Init datatable --- more info on datatables: https://datatables.net/manual/
|
||||
datatable = $(table).DataTable({
|
||||
"info": false,
|
||||
'order': [],
|
||||
"pageLength": 5,
|
||||
"lengthChange": false,
|
||||
'columnDefs': [
|
||||
{ orderable: false, targets: 4 }, // Disable ordering on column 5 (actions)
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
// Delete customer
|
||||
var deleteRows = () => {
|
||||
// Select all delete buttons
|
||||
const deleteButtons = table.querySelectorAll('[data-kt-customer-table-filter="delete_row"]');
|
||||
|
||||
deleteButtons.forEach(d => {
|
||||
// Delete button on click
|
||||
d.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Select parent row
|
||||
const parent = e.target.closest('tr');
|
||||
|
||||
// Get customer name
|
||||
const invoiceNumber = parent.querySelectorAll('td')[0].innerText;
|
||||
|
||||
// SweetAlert2 pop up --- official docs reference: https://sweetalert2.github.io/
|
||||
Swal.fire({
|
||||
text: "Are you sure you want to delete " + invoiceNumber + "?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, delete!",
|
||||
cancelButtonText: "No, cancel",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-danger",
|
||||
cancelButton: "btn fw-bold btn-active-light-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
Swal.fire({
|
||||
text: "You have deleted " + invoiceNumber + "!.",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-primary",
|
||||
}
|
||||
}).then(function () {
|
||||
// Remove current row
|
||||
datatable.row($(parent)).remove().draw();
|
||||
}).then(function () {
|
||||
// Detect checked checkboxes
|
||||
toggleToolbars();
|
||||
});
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: customerName + " was not deleted.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// Public methods
|
||||
return {
|
||||
init: function () {
|
||||
if (!table) {
|
||||
return;
|
||||
}
|
||||
|
||||
initCustomerView();
|
||||
deleteRows();
|
||||
}
|
||||
}
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTCustomerViewPaymentTable.init();
|
||||
});
|
||||
@@ -0,0 +1,217 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTModalUpdateAddress = function () {
|
||||
var element;
|
||||
var submitButton;
|
||||
var cancelButton;
|
||||
var closeButton;
|
||||
var form;
|
||||
var modal;
|
||||
var validator;
|
||||
|
||||
// Init form inputs
|
||||
var initForm = function () {
|
||||
// Init form validation rules. For more info check the FormValidation plugin's official documentation:https://formvalidation.io/
|
||||
validator = FormValidation.formValidation(
|
||||
form,
|
||||
{
|
||||
fields: {
|
||||
'name': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Address name is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'country': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Country is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'address1': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Address 1 is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'city': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'City is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'state': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'State is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'postcode': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Postcode is required'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap: new FormValidation.plugins.Bootstrap5({
|
||||
rowSelector: '.fv-row',
|
||||
eleInvalidClass: '',
|
||||
eleValidClass: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Revalidate country field. For more info, plase visit the official plugin site: https://select2.org/
|
||||
$(form.querySelector('[name="country"]')).on('change', function () {
|
||||
// Revalidate the field when an option is chosen
|
||||
validator.revalidateField('country');
|
||||
});
|
||||
|
||||
// Action buttons
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
// Prevent default button action
|
||||
e.preventDefault();
|
||||
|
||||
// Validate form before submit
|
||||
if (validator) {
|
||||
validator.validate().then(function (status) {
|
||||
console.log('validated!');
|
||||
|
||||
if (status == 'Valid') {
|
||||
submitButton.setAttribute('data-kt-indicator', 'on');
|
||||
|
||||
// Disable submit button whilst loading
|
||||
submitButton.disabled = true;
|
||||
|
||||
setTimeout(function() {
|
||||
submitButton.removeAttribute('data-kt-indicator');
|
||||
|
||||
Swal.fire({
|
||||
text: "Form has been successfully submitted!",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
// Hide modal
|
||||
modal.hide();
|
||||
|
||||
// Enable submit button after loading
|
||||
submitButton.disabled = false;
|
||||
}
|
||||
});
|
||||
}, 2000);
|
||||
} else {
|
||||
Swal.fire({
|
||||
text: "Sorry, looks like there are some errors detected, please try again.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
cancelButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to cancel?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, cancel it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
form.reset(); // Reset form
|
||||
modal.hide(); // Hide modal
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Your form has not been cancelled!.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
closeButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to cancel?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, cancel it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
form.reset(); // Reset form
|
||||
modal.hide(); // Hide modal
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Your form has not been cancelled!.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
// Public functions
|
||||
init: function () {
|
||||
// Elements
|
||||
element = document.querySelector('#kt_modal_update_address');
|
||||
modal = new bootstrap.Modal(element);
|
||||
|
||||
form = element.querySelector('#kt_modal_update_address_form');
|
||||
submitButton = form.querySelector('#kt_modal_update_address_submit');
|
||||
cancelButton = form.querySelector('#kt_modal_update_address_cancel');
|
||||
closeButton = element.querySelector('#kt_modal_update_address_close');
|
||||
|
||||
initForm();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTModalUpdateAddress.init();
|
||||
});
|
||||
@@ -0,0 +1,194 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTUsersUpdatePassword = function () {
|
||||
// Shared variables
|
||||
const element = document.getElementById('kt_modal_update_password');
|
||||
const form = element.querySelector('#kt_modal_update_password_form');
|
||||
const modal = new bootstrap.Modal(element);
|
||||
|
||||
// Init add schedule modal
|
||||
var initUpdatePassword = () => {
|
||||
|
||||
// Init form validation rules. For more info check the FormValidation plugin's official documentation:https://formvalidation.io/
|
||||
var validator = FormValidation.formValidation(
|
||||
form,
|
||||
{
|
||||
fields: {
|
||||
'current_password': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Current password is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'new_password': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'The password is required'
|
||||
},
|
||||
callback: {
|
||||
message: 'Please enter valid password',
|
||||
callback: function (input) {
|
||||
if (input.value.length > 0) {
|
||||
return validatePassword();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'confirm_password': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'The password confirmation is required'
|
||||
},
|
||||
identical: {
|
||||
compare: function () {
|
||||
return form.querySelector('[name="new_password"]').value;
|
||||
},
|
||||
message: 'The password and its confirm are not the same'
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap: new FormValidation.plugins.Bootstrap5({
|
||||
rowSelector: '.fv-row',
|
||||
eleInvalidClass: '',
|
||||
eleValidClass: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Close button handler
|
||||
const closeButton = element.querySelector('[data-kt-users-modal-action="close"]');
|
||||
closeButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to cancel?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, cancel it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
form.reset(); // Reset form
|
||||
modal.hide(); // Hide modal
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Your form has not been cancelled!.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Cancel button handler
|
||||
const cancelButton = element.querySelector('[data-kt-users-modal-action="cancel"]');
|
||||
cancelButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to cancel?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, cancel it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
form.reset(); // Reset form
|
||||
modal.hide(); // Hide modal
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Your form has not been cancelled!.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Submit button handler
|
||||
const submitButton = element.querySelector('[data-kt-users-modal-action="submit"]');
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
// Prevent default button action
|
||||
e.preventDefault();
|
||||
|
||||
// Validate form before submit
|
||||
if (validator) {
|
||||
validator.validate().then(function (status) {
|
||||
console.log('validated!');
|
||||
|
||||
if (status == 'Valid') {
|
||||
// Show loading indication
|
||||
submitButton.setAttribute('data-kt-indicator', 'on');
|
||||
|
||||
// Disable button to avoid multiple click
|
||||
submitButton.disabled = true;
|
||||
|
||||
// Simulate form submission. For more info check the plugin's official documentation: https://sweetalert2.github.io/
|
||||
setTimeout(function () {
|
||||
// Remove loading indication
|
||||
submitButton.removeAttribute('data-kt-indicator');
|
||||
|
||||
// Enable button
|
||||
submitButton.disabled = false;
|
||||
|
||||
// Show popup confirmation
|
||||
Swal.fire({
|
||||
text: "Form has been successfully submitted!",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
modal.hide();
|
||||
}
|
||||
});
|
||||
|
||||
//form.submit(); // Submit form
|
||||
}, 2000);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
// Public functions
|
||||
init: function () {
|
||||
initUpdatePassword();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTUsersUpdatePassword.init();
|
||||
});
|
||||
@@ -0,0 +1,166 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTUsersUpdateEmail = function () {
|
||||
// Shared variables
|
||||
const element = document.getElementById('kt_modal_update_phone');
|
||||
const form = element.querySelector('#kt_modal_update_phone_form');
|
||||
const modal = new bootstrap.Modal(element);
|
||||
|
||||
// Init add schedule modal
|
||||
var initUpdateEmail = () => {
|
||||
|
||||
// Init form validation rules. For more info check the FormValidation plugin's official documentation:https://formvalidation.io/
|
||||
var validator = FormValidation.formValidation(
|
||||
form,
|
||||
{
|
||||
fields: {
|
||||
'profile_phone': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Phone number is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap: new FormValidation.plugins.Bootstrap5({
|
||||
rowSelector: '.fv-row',
|
||||
eleInvalidClass: '',
|
||||
eleValidClass: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Close button handler
|
||||
const closeButton = element.querySelector('[data-kt-users-modal-action="close"]');
|
||||
closeButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to cancel?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, cancel it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
form.reset(); // Reset form
|
||||
modal.hide(); // Hide modal
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Your form has not been cancelled!.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Cancel button handler
|
||||
const cancelButton = element.querySelector('[data-kt-users-modal-action="cancel"]');
|
||||
cancelButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to cancel?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, cancel it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
form.reset(); // Reset form
|
||||
modal.hide(); // Hide modal
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Your form has not been cancelled!.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Submit button handler
|
||||
const submitButton = element.querySelector('[data-kt-users-modal-action="submit"]');
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
// Prevent default button action
|
||||
e.preventDefault();
|
||||
|
||||
// Validate form before submit
|
||||
if (validator) {
|
||||
validator.validate().then(function (status) {
|
||||
console.log('validated!');
|
||||
|
||||
if (status == 'Valid') {
|
||||
// Show loading indication
|
||||
submitButton.setAttribute('data-kt-indicator', 'on');
|
||||
|
||||
// Disable button to avoid multiple click
|
||||
submitButton.disabled = true;
|
||||
|
||||
// Simulate form submission. For more info check the plugin's official documentation: https://sweetalert2.github.io/
|
||||
setTimeout(function () {
|
||||
// Remove loading indication
|
||||
submitButton.removeAttribute('data-kt-indicator');
|
||||
|
||||
// Enable button
|
||||
submitButton.disabled = false;
|
||||
|
||||
// Show popup confirmation
|
||||
Swal.fire({
|
||||
text: "Form has been successfully submitted!",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
modal.hide();
|
||||
}
|
||||
});
|
||||
|
||||
//form.submit(); // Submit form
|
||||
}, 2000);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
// Public functions
|
||||
init: function () {
|
||||
initUpdateEmail();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTUsersUpdateEmail.init();
|
||||
});
|
||||
@@ -0,0 +1,106 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTEcommerceUpdateProfile = function () {
|
||||
var submitButton;
|
||||
var validator;
|
||||
var form;
|
||||
|
||||
// Init form inputs
|
||||
var handleForm = function () {
|
||||
// Init form validation rules. For more info check the FormValidation plugin's official documentation:https://formvalidation.io/
|
||||
validator = FormValidation.formValidation(
|
||||
form,
|
||||
{
|
||||
fields: {
|
||||
'name': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Name is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'gen_email': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'General Email is required'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap: new FormValidation.plugins.Bootstrap5({
|
||||
rowSelector: '.fv-row',
|
||||
eleInvalidClass: '',
|
||||
eleValidClass: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Action buttons
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Validate form before submit
|
||||
if (validator) {
|
||||
validator.validate().then(function (status) {
|
||||
console.log('validated!');
|
||||
|
||||
if (status == 'Valid') {
|
||||
submitButton.setAttribute('data-kt-indicator', 'on');
|
||||
|
||||
// Disable submit button whilst loading
|
||||
submitButton.disabled = true;
|
||||
|
||||
setTimeout(function() {
|
||||
submitButton.removeAttribute('data-kt-indicator');
|
||||
|
||||
Swal.fire({
|
||||
text: "Your profile has been saved!",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
// Enable submit button after loading
|
||||
submitButton.disabled = false;
|
||||
}
|
||||
});
|
||||
}, 2000);
|
||||
} else {
|
||||
Swal.fire({
|
||||
text: "Sorry, looks like there are some errors detected, please try again.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
// Public functions
|
||||
init: function () {
|
||||
// Elements
|
||||
form = document.querySelector('#kt_ecommerce_customer_profile');
|
||||
submitButton = form.querySelector('#kt_ecommerce_customer_profile_submit');
|
||||
|
||||
handleForm();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTEcommerceUpdateProfile.init();
|
||||
});
|
||||
@@ -0,0 +1,238 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTModalCustomersAdd = function () {
|
||||
var submitButton;
|
||||
var cancelButton;
|
||||
var closeButton;
|
||||
var validator;
|
||||
var form;
|
||||
var modal;
|
||||
|
||||
// Init form inputs
|
||||
var handleForm = function () {
|
||||
// Init form validation rules. For more info check the FormValidation plugin's official documentation:https://formvalidation.io/
|
||||
validator = FormValidation.formValidation(
|
||||
form,
|
||||
{
|
||||
fields: {
|
||||
'name': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Customer name is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'email': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Customer email is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'first-name': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'First name is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'last-name': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Last name is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'country': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Country is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'address1': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Address 1 is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'city': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'City is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'state': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'State is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'postcode': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Postcode is required'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap: new FormValidation.plugins.Bootstrap5({
|
||||
rowSelector: '.fv-row',
|
||||
eleInvalidClass: '',
|
||||
eleValidClass: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Revalidate country field. For more info, plase visit the official plugin site: https://select2.org/
|
||||
$(form.querySelector('[name="country"]')).on('change', function() {
|
||||
// Revalidate the field when an option is chosen
|
||||
validator.revalidateField('country');
|
||||
});
|
||||
|
||||
// Action buttons
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Validate form before submit
|
||||
if (validator) {
|
||||
validator.validate().then(function (status) {
|
||||
console.log('validated!');
|
||||
|
||||
if (status == 'Valid') {
|
||||
submitButton.setAttribute('data-kt-indicator', 'on');
|
||||
|
||||
// Disable submit button whilst loading
|
||||
submitButton.disabled = true;
|
||||
|
||||
setTimeout(function() {
|
||||
submitButton.removeAttribute('data-kt-indicator');
|
||||
|
||||
Swal.fire({
|
||||
text: "Form has been successfully submitted!",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
// Hide modal
|
||||
modal.hide();
|
||||
|
||||
// Enable submit button after loading
|
||||
submitButton.disabled = false;
|
||||
|
||||
// Redirect to customers list page
|
||||
window.location = form.getAttribute("data-kt-redirect");
|
||||
}
|
||||
});
|
||||
}, 2000);
|
||||
} else {
|
||||
Swal.fire({
|
||||
text: "Sorry, looks like there are some errors detected, please try again.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
cancelButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to cancel?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, cancel it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
form.reset(); // Reset form
|
||||
modal.hide(); // Hide modal
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Your form has not been cancelled!.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
closeButton.addEventListener('click', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to cancel?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, cancel it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
form.reset(); // Reset form
|
||||
modal.hide(); // Hide modal
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Your form has not been cancelled!.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
// Public functions
|
||||
init: function () {
|
||||
// Elements
|
||||
modal = new bootstrap.Modal(document.querySelector('#kt_modal_add_customer'));
|
||||
|
||||
form = document.querySelector('#kt_modal_add_customer_form');
|
||||
submitButton = form.querySelector('#kt_modal_add_customer_submit');
|
||||
cancelButton = form.querySelector('#kt_modal_add_customer_cancel');
|
||||
closeButton = form.querySelector('#kt_modal_add_customer_close');
|
||||
|
||||
handleForm();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTModalCustomersAdd.init();
|
||||
});
|
||||
@@ -0,0 +1,189 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTCustomersExport = function () {
|
||||
var element;
|
||||
var submitButton;
|
||||
var cancelButton;
|
||||
var closeButton;
|
||||
var validator;
|
||||
var form;
|
||||
var modal;
|
||||
|
||||
// Init form inputs
|
||||
var handleForm = function () {
|
||||
// Init form validation rules. For more info check the FormValidation plugin's official documentation:https://formvalidation.io/
|
||||
validator = FormValidation.formValidation(
|
||||
form,
|
||||
{
|
||||
fields: {
|
||||
'date': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Date range is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap: new FormValidation.plugins.Bootstrap5({
|
||||
rowSelector: '.fv-row',
|
||||
eleInvalidClass: '',
|
||||
eleValidClass: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Action buttons
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Validate form before submit
|
||||
if (validator) {
|
||||
validator.validate().then(function (status) {
|
||||
console.log('validated!');
|
||||
|
||||
if (status == 'Valid') {
|
||||
submitButton.setAttribute('data-kt-indicator', 'on');
|
||||
|
||||
// Disable submit button whilst loading
|
||||
submitButton.disabled = true;
|
||||
|
||||
setTimeout(function() {
|
||||
submitButton.removeAttribute('data-kt-indicator');
|
||||
|
||||
Swal.fire({
|
||||
text: "Customer list has been successfully exported!",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
modal.hide();
|
||||
|
||||
// Enable submit button after loading
|
||||
submitButton.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
//form.submit(); // Submit form
|
||||
}, 2000);
|
||||
} else {
|
||||
Swal.fire({
|
||||
text: "Sorry, looks like there are some errors detected, please try again.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
cancelButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to cancel?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, cancel it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
form.reset(); // Reset form
|
||||
modal.hide(); // Hide modal
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Your form has not been cancelled!.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
closeButton.addEventListener('click', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
Swal.fire({
|
||||
text: "Are you sure you would like to cancel?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, cancel it!",
|
||||
cancelButtonText: "No, return",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
cancelButton: "btn btn-active-light"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
form.reset(); // Reset form
|
||||
modal.hide(); // Hide modal
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Your form has not been cancelled!.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var initForm = function () {
|
||||
const datepicker = form.querySelector("[name=date]");
|
||||
|
||||
// Handle datepicker range -- For more info on flatpickr plugin, please visit: https://flatpickr.js.org/
|
||||
$(datepicker).flatpickr({
|
||||
altInput: true,
|
||||
altFormat: "F j, Y",
|
||||
dateFormat: "Y-m-d",
|
||||
mode: "range"
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
// Public functions
|
||||
init: function () {
|
||||
// Elements
|
||||
element = document.querySelector('#kt_customers_export_modal');
|
||||
modal = new bootstrap.Modal(element);
|
||||
|
||||
form = document.querySelector('#kt_customers_export_form');
|
||||
submitButton = form.querySelector('#kt_customers_export_submit');
|
||||
cancelButton = form.querySelector('#kt_customers_export_cancel');
|
||||
closeButton = element.querySelector('#kt_customers_export_close');
|
||||
|
||||
handleForm();
|
||||
initForm();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTCustomersExport.init();
|
||||
});
|
||||
@@ -0,0 +1,242 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTCustomersList = function () {
|
||||
// Define shared variables
|
||||
var datatable;
|
||||
var filterMonth;
|
||||
var filterPayment;
|
||||
var table
|
||||
|
||||
// Private functions
|
||||
var initCustomerList = function () {
|
||||
// Set date data order
|
||||
const tableRows = table.querySelectorAll('tbody tr');
|
||||
|
||||
tableRows.forEach(row => {
|
||||
const dateRow = row.querySelectorAll('td');
|
||||
const realDate = moment(dateRow[5].innerHTML, "DD MMM YYYY, LT").format(); // select date from 5th column in table
|
||||
dateRow[5].setAttribute('data-order', realDate);
|
||||
});
|
||||
|
||||
// Init datatable --- more info on datatables: https://datatables.net/manual/
|
||||
datatable = $(table).DataTable({
|
||||
"info": false,
|
||||
'order': [],
|
||||
'columnDefs': [
|
||||
{ orderable: false, targets: 0 }, // Disable ordering on column 0 (checkbox)
|
||||
{ orderable: false, targets: 6 }, // Disable ordering on column 6 (actions)
|
||||
]
|
||||
});
|
||||
|
||||
// Re-init functions on every table re-draw -- more info: https://datatables.net/reference/event/draw
|
||||
datatable.on('draw', function () {
|
||||
initToggleToolbar();
|
||||
handleDeleteRows();
|
||||
toggleToolbars();
|
||||
});
|
||||
}
|
||||
|
||||
// Search Datatable --- official docs reference: https://datatables.net/reference/api/search()
|
||||
var handleSearchDatatable = () => {
|
||||
const filterSearch = document.querySelector('[data-kt-customer-table-filter="search"]');
|
||||
filterSearch.addEventListener('keyup', function (e) {
|
||||
datatable.search(e.target.value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Delete customer
|
||||
var handleDeleteRows = () => {
|
||||
// Select all delete buttons
|
||||
const deleteButtons = table.querySelectorAll('[data-kt-customer-table-filter="delete_row"]');
|
||||
|
||||
deleteButtons.forEach(d => {
|
||||
// Delete button on click
|
||||
d.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Select parent row
|
||||
const parent = e.target.closest('tr');
|
||||
|
||||
// Get customer name
|
||||
const customerName = parent.querySelectorAll('td')[1].innerText;
|
||||
|
||||
// SweetAlert2 pop up --- official docs reference: https://sweetalert2.github.io/
|
||||
Swal.fire({
|
||||
text: "Are you sure you want to delete " + customerName + "?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, delete!",
|
||||
cancelButtonText: "No, cancel",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-danger",
|
||||
cancelButton: "btn fw-bold btn-active-light-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
Swal.fire({
|
||||
text: "You have deleted " + customerName + "!.",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-primary",
|
||||
}
|
||||
}).then(function () {
|
||||
// Remove current row
|
||||
datatable.row($(parent)).remove().draw();
|
||||
});
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: customerName + " was not deleted.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// Handle status filter dropdown
|
||||
var handleStatusFilter = () => {
|
||||
const filterStatus = document.querySelector('[data-kt-ecommerce-order-filter="status"]');
|
||||
$(filterStatus).on('change', e => {
|
||||
let value = e.target.value;
|
||||
if (value === 'all') {
|
||||
value = '';
|
||||
}
|
||||
datatable.column(3).search(value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Init toggle toolbar
|
||||
var initToggleToolbar = () => {
|
||||
// Toggle selected action toolbar
|
||||
// Select all checkboxes
|
||||
const checkboxes = table.querySelectorAll('[type="checkbox"]');
|
||||
|
||||
// Select elements
|
||||
const deleteSelected = document.querySelector('[data-kt-customer-table-select="delete_selected"]');
|
||||
|
||||
// Toggle delete selected toolbar
|
||||
checkboxes.forEach(c => {
|
||||
// Checkbox on click event
|
||||
c.addEventListener('click', function () {
|
||||
setTimeout(function () {
|
||||
toggleToolbars();
|
||||
}, 50);
|
||||
});
|
||||
});
|
||||
|
||||
// Deleted selected rows
|
||||
deleteSelected.addEventListener('click', function () {
|
||||
// SweetAlert2 pop up --- official docs reference: https://sweetalert2.github.io/
|
||||
Swal.fire({
|
||||
text: "Are you sure you want to delete selected customers?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, delete!",
|
||||
cancelButtonText: "No, cancel",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-danger",
|
||||
cancelButton: "btn fw-bold btn-active-light-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
Swal.fire({
|
||||
text: "You have deleted all selected customers!.",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-primary",
|
||||
}
|
||||
}).then(function () {
|
||||
// Remove all selected customers
|
||||
checkboxes.forEach(c => {
|
||||
if (c.checked) {
|
||||
datatable.row($(c.closest('tbody tr'))).remove().draw();
|
||||
}
|
||||
});
|
||||
|
||||
// Remove header checked box
|
||||
const headerCheckbox = table.querySelectorAll('[type="checkbox"]')[0];
|
||||
headerCheckbox.checked = false;
|
||||
});
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: "Selected customers was not deleted.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Toggle toolbars
|
||||
const toggleToolbars = () => {
|
||||
// Define variables
|
||||
const toolbarBase = document.querySelector('[data-kt-customer-table-toolbar="base"]');
|
||||
const toolbarSelected = document.querySelector('[data-kt-customer-table-toolbar="selected"]');
|
||||
const selectedCount = document.querySelector('[data-kt-customer-table-select="selected_count"]');
|
||||
|
||||
// Select refreshed checkbox DOM elements
|
||||
const allCheckboxes = table.querySelectorAll('tbody [type="checkbox"]');
|
||||
|
||||
// Detect checkboxes state & count
|
||||
let checkedState = false;
|
||||
let count = 0;
|
||||
|
||||
// Count checked boxes
|
||||
allCheckboxes.forEach(c => {
|
||||
if (c.checked) {
|
||||
checkedState = true;
|
||||
count++;
|
||||
}
|
||||
});
|
||||
|
||||
// Toggle toolbars
|
||||
if (checkedState) {
|
||||
selectedCount.innerHTML = count;
|
||||
toolbarBase.classList.add('d-none');
|
||||
toolbarSelected.classList.remove('d-none');
|
||||
} else {
|
||||
toolbarBase.classList.remove('d-none');
|
||||
toolbarSelected.classList.add('d-none');
|
||||
}
|
||||
}
|
||||
|
||||
// Public methods
|
||||
return {
|
||||
init: function () {
|
||||
table = document.querySelector('#kt_customers_table');
|
||||
|
||||
if (!table) {
|
||||
return;
|
||||
}
|
||||
|
||||
initCustomerList();
|
||||
initToggleToolbar();
|
||||
handleSearchDatatable();
|
||||
handleDeleteRows();
|
||||
handleStatusFilter();
|
||||
}
|
||||
}
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTCustomersList.init();
|
||||
});
|
||||
@@ -0,0 +1,136 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTAppEcommerceReportCustomerOrders = function () {
|
||||
// Shared variables
|
||||
var table;
|
||||
var datatable;
|
||||
|
||||
// Private functions
|
||||
var initDatatable = function () {
|
||||
// Set date data order
|
||||
const tableRows = table.querySelectorAll('tbody tr');
|
||||
|
||||
tableRows.forEach(row => {
|
||||
const dateRow = row.querySelectorAll('td');
|
||||
const realDate = moment(dateRow[3].innerHTML, "DD MMM YYYY, LT").format(); // select date from 4th column in table
|
||||
dateRow[3].setAttribute('data-order', realDate);
|
||||
});
|
||||
|
||||
// Init datatable --- more info on datatables: https://datatables.net/manual/
|
||||
datatable = $(table).DataTable({
|
||||
"info": false,
|
||||
'order': [],
|
||||
'pageLength': 10,
|
||||
});
|
||||
}
|
||||
|
||||
// Init daterangepicker
|
||||
var initDaterangepicker = () => {
|
||||
var start = moment().subtract(29, "days");
|
||||
var end = moment();
|
||||
var input = $("#kt_ecommerce_report_customer_orders_daterangepicker");
|
||||
|
||||
function cb(start, end) {
|
||||
input.html(start.format("MMMM D, YYYY") + " - " + end.format("MMMM D, YYYY"));
|
||||
}
|
||||
|
||||
input.daterangepicker({
|
||||
startDate: start,
|
||||
endDate: end,
|
||||
ranges: {
|
||||
"Today": [moment(), moment()],
|
||||
"Yesterday": [moment().subtract(1, "days"), moment().subtract(1, "days")],
|
||||
"Last 7 Days": [moment().subtract(6, "days"), moment()],
|
||||
"Last 30 Days": [moment().subtract(29, "days"), moment()],
|
||||
"This Month": [moment().startOf("month"), moment().endOf("month")],
|
||||
"Last Month": [moment().subtract(1, "month").startOf("month"), moment().subtract(1, "month").endOf("month")]
|
||||
}
|
||||
}, cb);
|
||||
|
||||
cb(start, end);
|
||||
}
|
||||
|
||||
// Handle status filter dropdown
|
||||
var handleStatusFilter = () => {
|
||||
const filterStatus = document.querySelector('[data-kt-ecommerce-order-filter="status"]');
|
||||
$(filterStatus).on('change', e => {
|
||||
let value = e.target.value;
|
||||
if (value === 'all') {
|
||||
value = '';
|
||||
}
|
||||
datatable.column(2).search(value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Hook export buttons
|
||||
var exportButtons = () => {
|
||||
const documentTitle = 'Customer Orders Report';
|
||||
var buttons = new $.fn.dataTable.Buttons(table, {
|
||||
buttons: [
|
||||
{
|
||||
extend: 'copyHtml5',
|
||||
title: documentTitle
|
||||
},
|
||||
{
|
||||
extend: 'excelHtml5',
|
||||
title: documentTitle
|
||||
},
|
||||
{
|
||||
extend: 'csvHtml5',
|
||||
title: documentTitle
|
||||
},
|
||||
{
|
||||
extend: 'pdfHtml5',
|
||||
title: documentTitle
|
||||
}
|
||||
]
|
||||
}).container().appendTo($('#kt_ecommerce_report_customer_orders_export'));
|
||||
|
||||
// Hook dropdown menu click event to datatable export buttons
|
||||
const exportButtons = document.querySelectorAll('#kt_ecommerce_report_customer_orders_export_menu [data-kt-ecommerce-export]');
|
||||
exportButtons.forEach(exportButton => {
|
||||
exportButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
// Get clicked export value
|
||||
const exportValue = e.target.getAttribute('data-kt-ecommerce-export');
|
||||
const target = document.querySelector('.dt-buttons .buttons-' + exportValue);
|
||||
|
||||
// Trigger click event on hidden datatable export buttons
|
||||
target.click();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Search Datatable --- official docs reference: https://datatables.net/reference/api/search()
|
||||
var handleSearchDatatable = () => {
|
||||
const filterSearch = document.querySelector('[data-kt-ecommerce-order-filter="search"]');
|
||||
filterSearch.addEventListener('keyup', function (e) {
|
||||
datatable.search(e.target.value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Public methods
|
||||
return {
|
||||
init: function () {
|
||||
table = document.querySelector('#kt_ecommerce_report_customer_orders_table');
|
||||
|
||||
if (!table) {
|
||||
return;
|
||||
}
|
||||
|
||||
initDatatable();
|
||||
initDaterangepicker();
|
||||
exportButtons();
|
||||
handleSearchDatatable();
|
||||
handleStatusFilter();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTAppEcommerceReportCustomerOrders.init();
|
||||
});
|
||||
@@ -0,0 +1,123 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTAppEcommerceReportReturns = function () {
|
||||
// Shared variables
|
||||
var table;
|
||||
var datatable;
|
||||
|
||||
// Private functions
|
||||
var initDatatable = function () {
|
||||
// Set date data order
|
||||
const tableRows = table.querySelectorAll('tbody tr');
|
||||
|
||||
tableRows.forEach(row => {
|
||||
const dateRow = row.querySelectorAll('td');
|
||||
const realDate = moment(dateRow[0].innerHTML, "MMM DD, YYYY").format(); // select date from 4th column in table
|
||||
dateRow[0].setAttribute('data-order', realDate);
|
||||
});
|
||||
|
||||
// Init datatable --- more info on datatables: https://datatables.net/manual/
|
||||
datatable = $(table).DataTable({
|
||||
"info": false,
|
||||
'order': [],
|
||||
'pageLength': 10,
|
||||
});
|
||||
}
|
||||
|
||||
// Init daterangepicker
|
||||
var initDaterangepicker = () => {
|
||||
var start = moment().subtract(29, "days");
|
||||
var end = moment();
|
||||
var input = $("#kt_ecommerce_report_returns_daterangepicker");
|
||||
|
||||
function cb(start, end) {
|
||||
input.html(start.format("MMMM D, YYYY") + " - " + end.format("MMMM D, YYYY"));
|
||||
}
|
||||
|
||||
input.daterangepicker({
|
||||
startDate: start,
|
||||
endDate: end,
|
||||
ranges: {
|
||||
"Today": [moment(), moment()],
|
||||
"Yesterday": [moment().subtract(1, "days"), moment().subtract(1, "days")],
|
||||
"Last 7 Days": [moment().subtract(6, "days"), moment()],
|
||||
"Last 30 Days": [moment().subtract(29, "days"), moment()],
|
||||
"This Month": [moment().startOf("month"), moment().endOf("month")],
|
||||
"Last Month": [moment().subtract(1, "month").startOf("month"), moment().subtract(1, "month").endOf("month")]
|
||||
}
|
||||
}, cb);
|
||||
|
||||
cb(start, end);
|
||||
}
|
||||
|
||||
// Hook export buttons
|
||||
var exportButtons = () => {
|
||||
const documentTitle = 'Returns Report';
|
||||
var buttons = new $.fn.dataTable.Buttons(table, {
|
||||
buttons: [
|
||||
{
|
||||
extend: 'copyHtml5',
|
||||
title: documentTitle
|
||||
},
|
||||
{
|
||||
extend: 'excelHtml5',
|
||||
title: documentTitle
|
||||
},
|
||||
{
|
||||
extend: 'csvHtml5',
|
||||
title: documentTitle
|
||||
},
|
||||
{
|
||||
extend: 'pdfHtml5',
|
||||
title: documentTitle
|
||||
}
|
||||
]
|
||||
}).container().appendTo($('#kt_ecommerce_report_returns_export'));
|
||||
|
||||
// Hook dropdown menu click event to datatable export buttons
|
||||
const exportButtons = document.querySelectorAll('#kt_ecommerce_report_returns_export_menu [data-kt-ecommerce-export]');
|
||||
exportButtons.forEach(exportButton => {
|
||||
exportButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
// Get clicked export value
|
||||
const exportValue = e.target.getAttribute('data-kt-ecommerce-export');
|
||||
const target = document.querySelector('.dt-buttons .buttons-' + exportValue);
|
||||
|
||||
// Trigger click event on hidden datatable export buttons
|
||||
target.click();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Search Datatable --- official docs reference: https://datatables.net/reference/api/search()
|
||||
var handleSearchDatatable = () => {
|
||||
const filterSearch = document.querySelector('[data-kt-ecommerce-order-filter="search"]');
|
||||
filterSearch.addEventListener('keyup', function (e) {
|
||||
datatable.search(e.target.value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Public methods
|
||||
return {
|
||||
init: function () {
|
||||
table = document.querySelector('#kt_ecommerce_report_returns_table');
|
||||
|
||||
if (!table) {
|
||||
return;
|
||||
}
|
||||
|
||||
initDatatable();
|
||||
initDaterangepicker();
|
||||
exportButtons();
|
||||
handleSearchDatatable();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTAppEcommerceReportReturns.init();
|
||||
});
|
||||
@@ -0,0 +1,124 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTAppEcommerceReportSales = function () {
|
||||
// Shared variables
|
||||
var table;
|
||||
var datatable;
|
||||
|
||||
// Private functions
|
||||
var initDatatable = function () {
|
||||
// Set date data order
|
||||
const tableRows = table.querySelectorAll('tbody tr');
|
||||
|
||||
tableRows.forEach(row => {
|
||||
const dateRow = row.querySelectorAll('td');
|
||||
const realDate = moment(dateRow[0].innerHTML, "MMM DD, YYYY").format(); // select date from 4th column in table
|
||||
dateRow[0].setAttribute('data-order', realDate);
|
||||
});
|
||||
|
||||
|
||||
// Init datatable --- more info on datatables: https://datatables.net/manual/
|
||||
datatable = $(table).DataTable({
|
||||
"info": false,
|
||||
'order': [],
|
||||
'pageLength': 10,
|
||||
});
|
||||
}
|
||||
|
||||
// Init daterangepicker
|
||||
var initDaterangepicker = () => {
|
||||
var start = moment().subtract(29, "days");
|
||||
var end = moment();
|
||||
var input = $("#kt_ecommerce_report_sales_daterangepicker");
|
||||
|
||||
function cb(start, end) {
|
||||
input.html(start.format("MMMM D, YYYY") + " - " + end.format("MMMM D, YYYY"));
|
||||
}
|
||||
|
||||
input.daterangepicker({
|
||||
startDate: start,
|
||||
endDate: end,
|
||||
ranges: {
|
||||
"Today": [moment(), moment()],
|
||||
"Yesterday": [moment().subtract(1, "days"), moment().subtract(1, "days")],
|
||||
"Last 7 Days": [moment().subtract(6, "days"), moment()],
|
||||
"Last 30 Days": [moment().subtract(29, "days"), moment()],
|
||||
"This Month": [moment().startOf("month"), moment().endOf("month")],
|
||||
"Last Month": [moment().subtract(1, "month").startOf("month"), moment().subtract(1, "month").endOf("month")]
|
||||
}
|
||||
}, cb);
|
||||
|
||||
cb(start, end);
|
||||
}
|
||||
|
||||
// Hook export buttons
|
||||
var exportButtons = () => {
|
||||
const documentTitle = 'Sales Report';
|
||||
var buttons = new $.fn.dataTable.Buttons(table, {
|
||||
buttons: [
|
||||
{
|
||||
extend: 'copyHtml5',
|
||||
title: documentTitle
|
||||
},
|
||||
{
|
||||
extend: 'excelHtml5',
|
||||
title: documentTitle
|
||||
},
|
||||
{
|
||||
extend: 'csvHtml5',
|
||||
title: documentTitle
|
||||
},
|
||||
{
|
||||
extend: 'pdfHtml5',
|
||||
title: documentTitle
|
||||
}
|
||||
]
|
||||
}).container().appendTo($('#kt_ecommerce_report_sales_export'));
|
||||
|
||||
// Hook dropdown menu click event to datatable export buttons
|
||||
const exportButtons = document.querySelectorAll('#kt_ecommerce_report_sales_export_menu [data-kt-ecommerce-export]');
|
||||
exportButtons.forEach(exportButton => {
|
||||
exportButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
// Get clicked export value
|
||||
const exportValue = e.target.getAttribute('data-kt-ecommerce-export');
|
||||
const target = document.querySelector('.dt-buttons .buttons-' + exportValue);
|
||||
|
||||
// Trigger click event on hidden datatable export buttons
|
||||
target.click();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Search Datatable --- official docs reference: https://datatables.net/reference/api/search()
|
||||
var handleSearchDatatable = () => {
|
||||
const filterSearch = document.querySelector('[data-kt-ecommerce-order-filter="search"]');
|
||||
filterSearch.addEventListener('keyup', function (e) {
|
||||
datatable.search(e.target.value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Public methods
|
||||
return {
|
||||
init: function () {
|
||||
table = document.querySelector('#kt_ecommerce_report_sales_table');
|
||||
|
||||
if (!table) {
|
||||
return;
|
||||
}
|
||||
|
||||
initDatatable();
|
||||
initDaterangepicker();
|
||||
exportButtons();
|
||||
handleSearchDatatable();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTAppEcommerceReportSales.init();
|
||||
});
|
||||
@@ -0,0 +1,137 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTAppEcommerceReportShipping = function () {
|
||||
// Shared variables
|
||||
var table;
|
||||
var datatable;
|
||||
|
||||
// Private functions
|
||||
var initDatatable = function () {
|
||||
// Set date data order
|
||||
const tableRows = table.querySelectorAll('tbody tr');
|
||||
|
||||
tableRows.forEach(row => {
|
||||
const dateRow = row.querySelectorAll('td');
|
||||
const realDate = moment(dateRow[0].innerHTML, "MMM DD, YYYY").format(); // select date from 4th column in table
|
||||
dateRow[0].setAttribute('data-order', realDate);
|
||||
});
|
||||
|
||||
|
||||
// Init datatable --- more info on datatables: https://datatables.net/manual/
|
||||
datatable = $(table).DataTable({
|
||||
"info": false,
|
||||
'order': [],
|
||||
'pageLength': 10,
|
||||
});
|
||||
}
|
||||
|
||||
// Init daterangepicker
|
||||
var initDaterangepicker = () => {
|
||||
var start = moment().subtract(29, "days");
|
||||
var end = moment();
|
||||
var input = $("#kt_ecommerce_report_shipping_daterangepicker");
|
||||
|
||||
function cb(start, end) {
|
||||
input.html(start.format("MMMM D, YYYY") + " - " + end.format("MMMM D, YYYY"));
|
||||
}
|
||||
|
||||
input.daterangepicker({
|
||||
startDate: start,
|
||||
endDate: end,
|
||||
ranges: {
|
||||
"Today": [moment(), moment()],
|
||||
"Yesterday": [moment().subtract(1, "days"), moment().subtract(1, "days")],
|
||||
"Last 7 Days": [moment().subtract(6, "days"), moment()],
|
||||
"Last 30 Days": [moment().subtract(29, "days"), moment()],
|
||||
"This Month": [moment().startOf("month"), moment().endOf("month")],
|
||||
"Last Month": [moment().subtract(1, "month").startOf("month"), moment().subtract(1, "month").endOf("month")]
|
||||
}
|
||||
}, cb);
|
||||
|
||||
cb(start, end);
|
||||
}
|
||||
|
||||
// Handle status filter dropdown
|
||||
var handleStatusFilter = () => {
|
||||
const filterStatus = document.querySelector('[data-kt-ecommerce-order-filter="status"]');
|
||||
$(filterStatus).on('change', e => {
|
||||
let value = e.target.value;
|
||||
if (value === 'all') {
|
||||
value = '';
|
||||
}
|
||||
datatable.column(3).search(value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Hook export buttons
|
||||
var exportButtons = () => {
|
||||
const documentTitle = 'Shipping Report';
|
||||
var buttons = new $.fn.dataTable.Buttons(table, {
|
||||
buttons: [
|
||||
{
|
||||
extend: 'copyHtml5',
|
||||
title: documentTitle
|
||||
},
|
||||
{
|
||||
extend: 'excelHtml5',
|
||||
title: documentTitle
|
||||
},
|
||||
{
|
||||
extend: 'csvHtml5',
|
||||
title: documentTitle
|
||||
},
|
||||
{
|
||||
extend: 'pdfHtml5',
|
||||
title: documentTitle
|
||||
}
|
||||
]
|
||||
}).container().appendTo($('#kt_ecommerce_report_shipping_export'));
|
||||
|
||||
// Hook dropdown menu click event to datatable export buttons
|
||||
const exportButtons = document.querySelectorAll('#kt_ecommerce_report_shipping_export_menu [data-kt-ecommerce-export]');
|
||||
exportButtons.forEach(exportButton => {
|
||||
exportButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
// Get clicked export value
|
||||
const exportValue = e.target.getAttribute('data-kt-ecommerce-export');
|
||||
const target = document.querySelector('.dt-buttons .buttons-' + exportValue);
|
||||
|
||||
// Trigger click event on hidden datatable export buttons
|
||||
target.click();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Search Datatable --- official docs reference: https://datatables.net/reference/api/search()
|
||||
var handleSearchDatatable = () => {
|
||||
const filterSearch = document.querySelector('[data-kt-ecommerce-order-filter="search"]');
|
||||
filterSearch.addEventListener('keyup', function (e) {
|
||||
datatable.search(e.target.value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Public methods
|
||||
return {
|
||||
init: function () {
|
||||
table = document.querySelector('#kt_ecommerce_report_shipping_table');
|
||||
|
||||
if (!table) {
|
||||
return;
|
||||
}
|
||||
|
||||
initDatatable();
|
||||
initDaterangepicker();
|
||||
exportButtons();
|
||||
handleSearchDatatable();
|
||||
handleStatusFilter();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTAppEcommerceReportShipping.init();
|
||||
});
|
||||
@@ -0,0 +1,127 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTAppEcommerceReportViews = function () {
|
||||
// Shared variables
|
||||
var table;
|
||||
var datatable;
|
||||
|
||||
// Private functions
|
||||
var initDatatable = function () {
|
||||
// Init datatable --- more info on datatables: https://datatables.net/manual/
|
||||
datatable = $(table).DataTable({
|
||||
"info": false,
|
||||
'order': [],
|
||||
'pageLength': 10,
|
||||
});
|
||||
}
|
||||
|
||||
// Init daterangepicker
|
||||
var initDaterangepicker = () => {
|
||||
var start = moment().subtract(29, "days");
|
||||
var end = moment();
|
||||
var input = $("#kt_ecommerce_report_views_daterangepicker");
|
||||
|
||||
function cb(start, end) {
|
||||
input.html(start.format("MMMM D, YYYY") + " - " + end.format("MMMM D, YYYY"));
|
||||
}
|
||||
|
||||
input.daterangepicker({
|
||||
startDate: start,
|
||||
endDate: end,
|
||||
ranges: {
|
||||
"Today": [moment(), moment()],
|
||||
"Yesterday": [moment().subtract(1, "days"), moment().subtract(1, "days")],
|
||||
"Last 7 Days": [moment().subtract(6, "days"), moment()],
|
||||
"Last 30 Days": [moment().subtract(29, "days"), moment()],
|
||||
"This Month": [moment().startOf("month"), moment().endOf("month")],
|
||||
"Last Month": [moment().subtract(1, "month").startOf("month"), moment().subtract(1, "month").endOf("month")]
|
||||
}
|
||||
}, cb);
|
||||
|
||||
cb(start, end);
|
||||
}
|
||||
|
||||
// Handle rating filter dropdown
|
||||
var handleStatusFilter = () => {
|
||||
const filterStatus = document.querySelector('[data-kt-ecommerce-order-filter="rating"]');
|
||||
$(filterStatus).on('change', e => {
|
||||
let value = e.target.value;
|
||||
if (value === 'all') {
|
||||
value = '';
|
||||
}
|
||||
datatable.column(2).search(value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Hook export buttons
|
||||
var exportButtons = () => {
|
||||
const documentTitle = 'Product Views Report';
|
||||
var buttons = new $.fn.dataTable.Buttons(table, {
|
||||
buttons: [
|
||||
{
|
||||
extend: 'copyHtml5',
|
||||
title: documentTitle
|
||||
},
|
||||
{
|
||||
extend: 'excelHtml5',
|
||||
title: documentTitle
|
||||
},
|
||||
{
|
||||
extend: 'csvHtml5',
|
||||
title: documentTitle
|
||||
},
|
||||
{
|
||||
extend: 'pdfHtml5',
|
||||
title: documentTitle
|
||||
}
|
||||
]
|
||||
}).container().appendTo($('#kt_ecommerce_report_views_export'));
|
||||
|
||||
// Hook dropdown menu click event to datatable export buttons
|
||||
const exportButtons = document.querySelectorAll('#kt_ecommerce_report_views_export_menu [data-kt-ecommerce-export]');
|
||||
exportButtons.forEach(exportButton => {
|
||||
exportButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
// Get clicked export value
|
||||
const exportValue = e.target.getAttribute('data-kt-ecommerce-export');
|
||||
const target = document.querySelector('.dt-buttons .buttons-' + exportValue);
|
||||
|
||||
// Trigger click event on hidden datatable export buttons
|
||||
target.click();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Search Datatable --- official docs reference: https://datatables.net/reference/api/search()
|
||||
var handleSearchDatatable = () => {
|
||||
const filterSearch = document.querySelector('[data-kt-ecommerce-order-filter="search"]');
|
||||
filterSearch.addEventListener('keyup', function (e) {
|
||||
datatable.search(e.target.value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Public methods
|
||||
return {
|
||||
init: function () {
|
||||
table = document.querySelector('#kt_ecommerce_report_views_table');
|
||||
|
||||
if (!table) {
|
||||
return;
|
||||
}
|
||||
|
||||
initDatatable();
|
||||
initDaterangepicker();
|
||||
exportButtons();
|
||||
handleSearchDatatable();
|
||||
handleStatusFilter();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTAppEcommerceReportViews.init();
|
||||
});
|
||||
@@ -0,0 +1,181 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTAppEcommerceSalesListing = function () {
|
||||
// Shared variables
|
||||
var table;
|
||||
var datatable;
|
||||
var flatpickr;
|
||||
var minDate, maxDate;
|
||||
|
||||
// Private functions
|
||||
var initDatatable = function () {
|
||||
// Init datatable --- more info on datatables: https://datatables.net/manual/
|
||||
datatable = $(table).DataTable({
|
||||
"info": false,
|
||||
'order': [],
|
||||
'pageLength': 10,
|
||||
'columnDefs': [
|
||||
{ orderable: false, targets: 0 }, // Disable ordering on column 0 (checkbox)
|
||||
{ orderable: false, targets: 7 }, // Disable ordering on column 7 (actions)
|
||||
]
|
||||
});
|
||||
|
||||
// Re-init functions on datatable re-draws
|
||||
datatable.on('draw', function () {
|
||||
handleDeleteRows();
|
||||
});
|
||||
}
|
||||
|
||||
// Init flatpickr --- more info :https://flatpickr.js.org/getting-started/
|
||||
var initFlatpickr = () => {
|
||||
const element = document.querySelector('#kt_ecommerce_sales_flatpickr');
|
||||
flatpickr = $(element).flatpickr({
|
||||
altInput: true,
|
||||
altFormat: "d/m/Y",
|
||||
dateFormat: "Y-m-d",
|
||||
mode: "range",
|
||||
onChange: function (selectedDates, dateStr, instance) {
|
||||
handleFlatpickr(selectedDates, dateStr, instance);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Search Datatable --- official docs reference: https://datatables.net/reference/api/search()
|
||||
var handleSearchDatatable = () => {
|
||||
const filterSearch = document.querySelector('[data-kt-ecommerce-order-filter="search"]');
|
||||
filterSearch.addEventListener('keyup', function (e) {
|
||||
datatable.search(e.target.value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Handle status filter dropdown
|
||||
var handleStatusFilter = () => {
|
||||
const filterStatus = document.querySelector('[data-kt-ecommerce-order-filter="status"]');
|
||||
$(filterStatus).on('change', e => {
|
||||
let value = e.target.value;
|
||||
if (value === 'all') {
|
||||
value = '';
|
||||
}
|
||||
datatable.column(3).search(value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Handle flatpickr --- more info: https://flatpickr.js.org/events/
|
||||
var handleFlatpickr = (selectedDates, dateStr, instance) => {
|
||||
minDate = selectedDates[0] ? new Date(selectedDates[0]) : null;
|
||||
maxDate = selectedDates[1] ? new Date(selectedDates[1]) : null;
|
||||
|
||||
// Datatable date filter --- more info: https://datatables.net/extensions/datetime/examples/integration/datatables.html
|
||||
// Custom filtering function which will search data in column four between two values
|
||||
$.fn.dataTable.ext.search.push(
|
||||
function (settings, data, dataIndex) {
|
||||
var min = minDate;
|
||||
var max = maxDate;
|
||||
var dateAdded = new Date(moment($(data[5]).text(), 'DD/MM/YYYY'));
|
||||
var dateModified = new Date(moment($(data[6]).text(), 'DD/MM/YYYY'));
|
||||
|
||||
if (
|
||||
(min === null && max === null) ||
|
||||
(min === null && max >= dateModified) ||
|
||||
(min <= dateAdded && max === null) ||
|
||||
(min <= dateAdded && max >= dateModified)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
datatable.draw();
|
||||
}
|
||||
|
||||
// Handle clear flatpickr
|
||||
var handleClearFlatpickr = () => {
|
||||
const clearButton = document.querySelector('#kt_ecommerce_sales_flatpickr_clear');
|
||||
clearButton.addEventListener('click', e => {
|
||||
flatpickr.clear();
|
||||
});
|
||||
}
|
||||
|
||||
// Delete cateogry
|
||||
var handleDeleteRows = () => {
|
||||
// Select all delete buttons
|
||||
const deleteButtons = table.querySelectorAll('[data-kt-ecommerce-order-filter="delete_row"]');
|
||||
|
||||
deleteButtons.forEach(d => {
|
||||
// Delete button on click
|
||||
d.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Select parent row
|
||||
const parent = e.target.closest('tr');
|
||||
|
||||
// Get category name
|
||||
const orderID = parent.querySelector('[data-kt-ecommerce-order-filter="order_id"]').innerText;
|
||||
|
||||
// SweetAlert2 pop up --- official docs reference: https://sweetalert2.github.io/
|
||||
Swal.fire({
|
||||
text: "Are you sure you want to delete order: " + orderID + "?",
|
||||
icon: "warning",
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Yes, delete!",
|
||||
cancelButtonText: "No, cancel",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-danger",
|
||||
cancelButton: "btn fw-bold btn-active-light-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
Swal.fire({
|
||||
text: "You have deleted " + orderID + "!.",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-primary",
|
||||
}
|
||||
}).then(function () {
|
||||
// Remove current row
|
||||
datatable.row($(parent)).remove().draw();
|
||||
});
|
||||
} else if (result.dismiss === 'cancel') {
|
||||
Swal.fire({
|
||||
text: orderID + " was not deleted.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn fw-bold btn-primary",
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Public methods
|
||||
return {
|
||||
init: function () {
|
||||
table = document.querySelector('#kt_ecommerce_sales_table');
|
||||
|
||||
if (!table) {
|
||||
return;
|
||||
}
|
||||
|
||||
initDatatable();
|
||||
initFlatpickr();
|
||||
handleSearchDatatable();
|
||||
handleStatusFilter();
|
||||
handleDeleteRows();
|
||||
handleClearFlatpickr();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTAppEcommerceSalesListing.init();
|
||||
});
|
||||
@@ -0,0 +1,338 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTAppEcommerceSalesSaveOrder = function () {
|
||||
// Shared variables
|
||||
var table;
|
||||
var datatable;
|
||||
|
||||
// Private functions
|
||||
const initSaveOrder = () => {
|
||||
// Init flatpickr
|
||||
$('#kt_ecommerce_edit_order_date').flatpickr({
|
||||
altInput: true,
|
||||
altFormat: "d F, Y",
|
||||
dateFormat: "Y-m-d",
|
||||
});
|
||||
|
||||
// Init select2 country options
|
||||
// Format options
|
||||
const optionFormat = (item) => {
|
||||
if ( !item.id ) {
|
||||
return item.text;
|
||||
}
|
||||
|
||||
var span = document.createElement('span');
|
||||
var template = '';
|
||||
|
||||
template += '<img src="' + item.element.getAttribute('data-kt-select2-country') + '" class="rounded-circle h-20px me-2" alt="image"/>';
|
||||
template += item.text;
|
||||
|
||||
span.innerHTML = template;
|
||||
|
||||
return $(span);
|
||||
}
|
||||
|
||||
// Init Select2 --- more info: https://select2.org/
|
||||
$('#kt_ecommerce_edit_order_billing_country').select2({
|
||||
placeholder: "Select a country",
|
||||
minimumResultsForSearch: Infinity,
|
||||
templateSelection: optionFormat,
|
||||
templateResult: optionFormat
|
||||
});
|
||||
|
||||
$('#kt_ecommerce_edit_order_shipping_country').select2({
|
||||
placeholder: "Select a country",
|
||||
minimumResultsForSearch: Infinity,
|
||||
templateSelection: optionFormat,
|
||||
templateResult: optionFormat
|
||||
});
|
||||
|
||||
// Init datatable --- more info on datatables: https://datatables.net/manual/
|
||||
table = document.querySelector('#kt_ecommerce_edit_order_product_table');
|
||||
datatable = $(table).DataTable({
|
||||
'order': [],
|
||||
"scrollY": "400px",
|
||||
"scrollCollapse": true,
|
||||
"paging": false,
|
||||
"info": false,
|
||||
'columnDefs': [
|
||||
{ orderable: false, targets: 0 }, // Disable ordering on column 0 (checkbox)
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
// Search Datatable --- official docs reference: https://datatables.net/reference/api/search()
|
||||
var handleSearchDatatable = () => {
|
||||
const filterSearch = document.querySelector('[data-kt-ecommerce-edit-order-filter="search"]');
|
||||
filterSearch.addEventListener('keyup', function (e) {
|
||||
datatable.search(e.target.value).draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Handle shipping form
|
||||
const handleShippingForm = () => {
|
||||
// Select elements
|
||||
const element = document.getElementById('kt_ecommerce_edit_order_shipping_form');
|
||||
const checkbox = document.getElementById('same_as_billing');
|
||||
|
||||
// Show/hide shipping form
|
||||
checkbox.addEventListener('change', e => {
|
||||
if (e.target.checked) {
|
||||
element.classList.add('d-none');
|
||||
} else {
|
||||
element.classList.remove('d-none');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Handle product select
|
||||
const handleProductSelect = () => {
|
||||
// Define variables
|
||||
const checkboxes = table.querySelectorAll('[type="checkbox"]');
|
||||
const target = document.getElementById('kt_ecommerce_edit_order_selected_products');
|
||||
const totalPrice = document.getElementById('kt_ecommerce_edit_order_total_price');
|
||||
|
||||
// Loop through all checked products
|
||||
checkboxes.forEach(checkbox => {
|
||||
checkbox.addEventListener('change', e => {
|
||||
// Select parent row element
|
||||
const parent = checkbox.closest('tr');
|
||||
|
||||
// Clone parent element as variable
|
||||
const product = parent.querySelector('[data-kt-ecommerce-edit-order-filter="product"]').cloneNode(true);
|
||||
|
||||
// Create inner wrapper
|
||||
const innerWrapper = document.createElement('div');
|
||||
|
||||
// Store inner content
|
||||
const innerContent = product.innerHTML;
|
||||
|
||||
// Add & remove classes on parent wrapper
|
||||
const wrapperClassesAdd = ['col', 'my-2'];
|
||||
const wrapperClassesRemove = ['d-flex', 'align-items-center'];
|
||||
|
||||
// Define additional classes
|
||||
const additionalClasses = ['border', 'border-dashed', 'rounded', 'p-3', 'bg-body'];
|
||||
|
||||
// Update parent wrapper classes
|
||||
product.classList.remove(...wrapperClassesRemove);
|
||||
product.classList.add(...wrapperClassesAdd);
|
||||
|
||||
// Remove parent default content
|
||||
product.innerHTML = '';
|
||||
|
||||
// Update inner wrapper classes
|
||||
innerWrapper.classList.add(...wrapperClassesRemove);
|
||||
innerWrapper.classList.add(...additionalClasses);
|
||||
|
||||
// Apply stored inner content into new inner wrapper
|
||||
innerWrapper.innerHTML = innerContent;
|
||||
|
||||
// Append new inner wrapper to parent wrapper
|
||||
product.appendChild(innerWrapper);
|
||||
|
||||
// Get product id
|
||||
const productId = product.getAttribute('data-kt-ecommerce-edit-order-id');
|
||||
|
||||
if (e.target.checked) {
|
||||
// Add product to selected product wrapper
|
||||
target.appendChild(product);
|
||||
} else {
|
||||
// Remove product from selected product wrapper
|
||||
const selectedProduct = target.querySelector('[data-kt-ecommerce-edit-order-id="' + productId + '"]');
|
||||
if (selectedProduct) {
|
||||
target.removeChild(selectedProduct);
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger empty message logic
|
||||
detectEmpty();
|
||||
});
|
||||
});
|
||||
|
||||
// Handle empty list message
|
||||
const detectEmpty = () => {
|
||||
// Select elements
|
||||
const message = target.querySelector('span');
|
||||
const products = target.querySelectorAll('[data-kt-ecommerce-edit-order-filter="product"]');
|
||||
|
||||
// Detect if element is empty
|
||||
if (products.length < 1) {
|
||||
// Show message
|
||||
message.classList.remove('d-none');
|
||||
|
||||
// Reset price
|
||||
totalPrice.innerText = '0.00';
|
||||
} else {
|
||||
// Hide message
|
||||
message.classList.add('d-none');
|
||||
|
||||
// Calculate price
|
||||
calculateTotal(products);
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate total cost
|
||||
const calculateTotal = (products) => {
|
||||
let countPrice = 0;
|
||||
|
||||
// Loop through all selected prodcucts
|
||||
products.forEach(product => {
|
||||
// Get product price
|
||||
const price = parseFloat(product.querySelector('[data-kt-ecommerce-edit-order-filter="price"]').innerText);
|
||||
|
||||
// Add to total
|
||||
countPrice = parseFloat(countPrice + price);
|
||||
});
|
||||
|
||||
// Update total price
|
||||
totalPrice.innerText = countPrice.toFixed(2);
|
||||
}
|
||||
}
|
||||
|
||||
// Submit form handler
|
||||
const handleSubmit = () => {
|
||||
// Define variables
|
||||
let validator;
|
||||
|
||||
// Get elements
|
||||
const form = document.getElementById('kt_ecommerce_edit_order_form');
|
||||
const submitButton = document.getElementById('kt_ecommerce_edit_order_submit');
|
||||
|
||||
// Init form validation rules. For more info check the FormValidation plugin's official documentation:https://formvalidation.io/
|
||||
validator = FormValidation.formValidation(
|
||||
form,
|
||||
{
|
||||
fields: {
|
||||
'payment_method': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Payment method is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'shipping_method': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Shipping method is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'order_date': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Order date is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'billing_order_address_1': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Address line 1 is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'billing_order_postcode': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Postcode is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'billing_order_state': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'State is required'
|
||||
}
|
||||
}
|
||||
},
|
||||
'billing_order_country': {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: 'Country is required'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap: new FormValidation.plugins.Bootstrap5({
|
||||
rowSelector: '.fv-row',
|
||||
eleInvalidClass: '',
|
||||
eleValidClass: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Handle submit button
|
||||
submitButton.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
|
||||
// Validate form before submit
|
||||
if (validator) {
|
||||
validator.validate().then(function (status) {
|
||||
console.log('validated!');
|
||||
|
||||
if (status == 'Valid') {
|
||||
submitButton.setAttribute('data-kt-indicator', 'on');
|
||||
|
||||
// Disable submit button whilst loading
|
||||
submitButton.disabled = true;
|
||||
|
||||
setTimeout(function () {
|
||||
submitButton.removeAttribute('data-kt-indicator');
|
||||
|
||||
Swal.fire({
|
||||
text: "Form has been successfully submitted!",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
// Enable submit button after loading
|
||||
submitButton.disabled = false;
|
||||
|
||||
// Redirect to customers list page
|
||||
window.location = form.getAttribute("data-kt-redirect");
|
||||
}
|
||||
});
|
||||
}, 2000);
|
||||
} else {
|
||||
Swal.fire({
|
||||
html: "Sorry, looks like there are some errors detected, please try again.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// Public methods
|
||||
return {
|
||||
init: function () {
|
||||
|
||||
initSaveOrder();
|
||||
handleSearchDatatable();
|
||||
handleShippingForm();
|
||||
handleProductSelect();
|
||||
handleSubmit();
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTAppEcommerceSalesSaveOrder.init();
|
||||
});
|
||||
@@ -0,0 +1,188 @@
|
||||
"use strict";
|
||||
|
||||
// Class definition
|
||||
var KTAppEcommerceSettings = function () {
|
||||
// Shared variables
|
||||
|
||||
|
||||
// Private functions
|
||||
const initForms = () => {
|
||||
const forms = [
|
||||
'kt_ecommerce_settings_general_form',
|
||||
'kt_ecommerce_settings_general_store',
|
||||
'kt_ecommerce_settings_general_localization',
|
||||
'kt_ecommerce_settings_general_products',
|
||||
'kt_ecommerce_settings_general_customers',
|
||||
];
|
||||
|
||||
// Init all forms
|
||||
forms.forEach(formId => {
|
||||
// Select form
|
||||
const form = document.getElementById(formId);
|
||||
|
||||
if(!form){
|
||||
return;
|
||||
}
|
||||
|
||||
// Dynamically create validation non-empty rule
|
||||
const requiredFields = form.querySelectorAll('.required');
|
||||
var detectedField;
|
||||
var validationFields = {
|
||||
fields: {},
|
||||
|
||||
plugins: {
|
||||
trigger: new FormValidation.plugins.Trigger(),
|
||||
bootstrap: new FormValidation.plugins.Bootstrap5({
|
||||
rowSelector: '.fv-row',
|
||||
eleInvalidClass: '',
|
||||
eleValidClass: ''
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Detect required fields
|
||||
requiredFields.forEach(el => {
|
||||
const input = el.closest('.row').querySelector('input');
|
||||
if (input) {
|
||||
detectedField = input;
|
||||
}
|
||||
|
||||
const textarea = el.closest('.row').querySelector('textarea');
|
||||
if (textarea) {
|
||||
detectedField = textarea;
|
||||
}
|
||||
|
||||
const select = el.closest('.row').querySelector('select');
|
||||
if (select) {
|
||||
detectedField = select;
|
||||
}
|
||||
|
||||
// Add validation rule
|
||||
const name = detectedField.getAttribute('name');
|
||||
validationFields.fields[name] = {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: el.innerText + ' is required'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Init form validation rules. For more info check the FormValidation plugin's official documentation:https://formvalidation.io/
|
||||
var validator = FormValidation.formValidation(
|
||||
form,
|
||||
validationFields
|
||||
);
|
||||
|
||||
// Submit button handler
|
||||
const submitButton = form.querySelector('[data-kt-ecommerce-settings-type="submit"]');
|
||||
submitButton.addEventListener('click', function (e) {
|
||||
// Prevent default button action
|
||||
e.preventDefault();
|
||||
|
||||
// Validate form before submit
|
||||
if (validator) {
|
||||
validator.validate().then(function (status) {
|
||||
console.log('validated!');
|
||||
|
||||
if (status == 'Valid') {
|
||||
// Show loading indication
|
||||
submitButton.setAttribute('data-kt-indicator', 'on');
|
||||
|
||||
// Disable button to avoid multiple click
|
||||
submitButton.disabled = true;
|
||||
|
||||
// Simulate form submission. For more info check the plugin's official documentation: https://sweetalert2.github.io/
|
||||
setTimeout(function () {
|
||||
// Remove loading indication
|
||||
submitButton.removeAttribute('data-kt-indicator');
|
||||
|
||||
// Enable button
|
||||
submitButton.disabled = false;
|
||||
|
||||
// Show popup confirmation
|
||||
Swal.fire({
|
||||
text: "Form has been successfully submitted!",
|
||||
icon: "success",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
});
|
||||
|
||||
//form.submit(); // Submit form
|
||||
}, 2000);
|
||||
} else {
|
||||
// Show popup error
|
||||
Swal.fire({
|
||||
text: "Oops! There are some error(s) detected.",
|
||||
icon: "error",
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: "Ok, got it!",
|
||||
customClass: {
|
||||
confirmButton: "btn btn-primary"
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Init Tagify
|
||||
const initTagify = () => {
|
||||
// Get tagify elements
|
||||
const elements = document.querySelectorAll('[data-kt-ecommerce-settings-type="tagify"]');
|
||||
|
||||
// Init tagify
|
||||
elements.forEach(element => {
|
||||
new Tagify(element);
|
||||
});
|
||||
}
|
||||
|
||||
// Init Select2 with flags
|
||||
const initSelect2Flags = () => {
|
||||
// Format options
|
||||
const optionFormat = (item) => {
|
||||
if ( !item.id ) {
|
||||
return item.text;
|
||||
}
|
||||
|
||||
var span = document.createElement('span');
|
||||
var template = '';
|
||||
|
||||
template += '<img src="' + item.element.getAttribute('data-kt-select2-country') + '" class="rounded-circle h-20px me-2" alt="image"/>';
|
||||
template += item.text;
|
||||
|
||||
span.innerHTML = template;
|
||||
|
||||
return $(span);
|
||||
}
|
||||
|
||||
// Init Select2 --- more info: https://select2.org/
|
||||
$('[data-kt-ecommerce-settings-type="select2_flags"]').select2({
|
||||
placeholder: "Select a country",
|
||||
minimumResultsForSearch: Infinity,
|
||||
templateSelection: optionFormat,
|
||||
templateResult: optionFormat
|
||||
});
|
||||
}
|
||||
|
||||
// Public methods
|
||||
return {
|
||||
init: function () {
|
||||
|
||||
initForms();
|
||||
initTagify();
|
||||
initSelect2Flags();
|
||||
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
// On document ready
|
||||
KTUtil.onDOMContentLoaded(function () {
|
||||
KTAppEcommerceSettings.init();
|
||||
});
|
||||
Reference in New Issue
Block a user