135 lines
3.3 KiB
JavaScript
135 lines
3.3 KiB
JavaScript
|
|
$('body').on('click', '.remove-item-btn', function (e) {
|
|
e.preventDefault();
|
|
let url = $(this).data('link');
|
|
let id = $(this).data('id');
|
|
|
|
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) {
|
|
location.reload();
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
//initialize ckeditor
|
|
document.querySelectorAll('.ckeditor-classic').forEach(editor => {
|
|
console.log(editor);
|
|
ClassicEditor
|
|
.create(editor)
|
|
.catch(error => {
|
|
console.error(error);
|
|
});
|
|
|
|
});
|
|
|
|
$('.date-picker').nepaliDatePicker({
|
|
// dateFormat: '%D, %M %d, %y',
|
|
dateFormat: '%y-%m-%d',
|
|
closeOnDateSelect: true,
|
|
});
|
|
|
|
// initialize filepond
|
|
const inputElement = document.querySelector('.filepond');
|
|
console.log(inputElement);
|
|
FilePond.registerPlugin(FilePondPluginImagePreview);
|
|
const pond = FilePond.create(inputElement);
|
|
FilePond.setOptions({
|
|
server: {
|
|
process: "/filepond/upload",
|
|
revert: '/delete',
|
|
headers: {
|
|
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content'),
|
|
},
|
|
}
|
|
});
|
|
|
|
|
|
//ajax form submit
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
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',
|
|
}
|
|
|
|
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')
|
|
}
|
|
})
|
|
.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);
|
|
});
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error during fetch:', error);
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
|