2024-04-07 07:28:58 +00:00
|
|
|
|
|
|
|
$('body').on('click', '.remove-item-btn', function (e) {
|
2024-04-15 12:16:31 +00:00
|
|
|
e.preventDefault();
|
|
|
|
let url = $(this).data('link');
|
|
|
|
let id = $(this).data('id');
|
2024-04-10 09:36:30 +00:00
|
|
|
|
|
|
|
Swal.fire({
|
|
|
|
title: 'Are you sure?',
|
|
|
|
text: "You won't be able to revert this!",
|
|
|
|
icon: 'warning',
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonColor: '#3085d6',
|
|
|
|
cancelButtonColor: '#d33',
|
|
|
|
confirmButtonText: 'Yes, delete it!'
|
|
|
|
}).then((result) => {
|
|
|
|
if (result.isConfirmed) {
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
type: 'DELETE',
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
id: id
|
|
|
|
},
|
|
|
|
success: function (response) {
|
2024-04-15 12:16:31 +00:00
|
|
|
if (response.status == true) {
|
2024-04-10 12:21:18 +00:00
|
|
|
location.reload();
|
|
|
|
}
|
2024-04-10 09:36:30 +00:00
|
|
|
},
|
|
|
|
error: function (xhr, status, error) {
|
|
|
|
console.error(xhr.responseText);
|
|
|
|
}
|
|
|
|
});
|
2024-04-07 07:28:58 +00:00
|
|
|
}
|
2024-04-10 09:36:30 +00:00
|
|
|
});
|
2024-04-07 07:28:58 +00:00
|
|
|
});
|
|
|
|
|
2024-04-04 07:23:00 +00:00
|
|
|
//initialize ckeditor
|
|
|
|
document.querySelectorAll('.ckeditor-classic').forEach(editor => {
|
2024-04-10 09:36:30 +00:00
|
|
|
console.log(editor);
|
|
|
|
ClassicEditor
|
|
|
|
.create(editor)
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
});
|
2024-04-04 07:23:00 +00:00
|
|
|
|
2024-04-07 07:28:58 +00:00
|
|
|
});
|
2024-04-04 07:23:00 +00:00
|
|
|
|
|
|
|
//ajax form submit
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
2024-04-10 09:36:30 +00:00
|
|
|
let form = document.getElementById('storeUpdateForm');
|
|
|
|
|
|
|
|
let action = form.getAttribute('action');
|
|
|
|
|
|
|
|
let method = form.getAttribute('method');
|
|
|
|
|
|
|
|
toastr.options = {
|
|
|
|
'closeButton': true,
|
|
|
|
'debug': false,
|
|
|
|
'newestOnTop': true,
|
|
|
|
'progressBar': true,
|
|
|
|
'positionClass': 'toast-top-right',
|
|
|
|
'preventDuplicates': true,
|
|
|
|
'showDuration': '1000',
|
|
|
|
'hideDuration': '1000',
|
|
|
|
'timeOut': '5000',
|
|
|
|
'extendedTimeOut': '1000',
|
|
|
|
'showEasing': 'swing',
|
|
|
|
'hideEasing': 'linear',
|
|
|
|
'showMethod': 'fadeIn',
|
|
|
|
'hideMethod': 'fadeOut',
|
|
|
|
}
|
2024-04-07 07:28:58 +00:00
|
|
|
|
2024-04-10 09:36:30 +00:00
|
|
|
form.addEventListener('submit', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
let formData = new FormData(form);
|
|
|
|
|
|
|
|
fetch(action, {
|
|
|
|
method: method,
|
|
|
|
body: formData,
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
|
2024-04-04 07:23:00 +00:00
|
|
|
}
|
2024-04-10 09:36:30 +00:00
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
if (response.ok) {
|
|
|
|
response.json().then(data => {
|
|
|
|
toastr['success'](data.message);
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
response.json().then(data => {
|
|
|
|
if (data.errors) {
|
|
|
|
for (const [key, message] of Object.entries(data.errors)) {
|
|
|
|
let errorDiv = document.createElement('div');
|
|
|
|
errorDiv.innerHTML = `<span class="text-danger">${message}</span>`;
|
|
|
|
document.getElementById(key).parentNode.appendChild(errorDiv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error('Error parsing JSON:', error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
2024-04-07 07:28:58 +00:00
|
|
|
.catch(error => {
|
2024-04-10 09:36:30 +00:00
|
|
|
console.error('Error during fetch:', error);
|
2024-04-07 07:28:58 +00:00
|
|
|
});
|
2024-04-10 09:36:30 +00:00
|
|
|
});
|
2024-04-04 07:23:00 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2024-04-07 07:28:58 +00:00
|
|
|
|