mirror of https://github.com/4xmen/xshop.git
added fast category edit ux feature
parent
89f80a50ce
commit
d1ef32bb79
@ -0,0 +1,59 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
document.querySelectorAll('.edit-category-btn')?.forEach(function (el) {
|
||||
el.setAttribute('href', '#edit-category');
|
||||
el.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
let id = this.closest('tr').querySelector('input.chkbox').getAttribute('value');
|
||||
const url = document.querySelector('#category-edit-url').value + id;
|
||||
document.querySelector('#iframe-modal iframe').setAttribute('src', url);
|
||||
document.querySelector('#iframe-modal').style.display = 'block';
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelector('#iframe-modal')?.addEventListener('click', function (e) {
|
||||
if (e.target == this) {
|
||||
this.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelector('#categories-save-btn')?.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
const url = document.querySelector('#ajax-sync-form').getAttribute('action');
|
||||
|
||||
// Serialize the form data
|
||||
const formData = new FormData();
|
||||
const checkboxes = document.querySelectorAll('input[type="checkbox"]:checked');
|
||||
|
||||
checkboxes.forEach(checkbox => {
|
||||
formData.append('cat[]', checkbox.value);
|
||||
});
|
||||
|
||||
// Optional: log serialized data for debugging
|
||||
for (const [key, value] of formData.entries()) {
|
||||
console.log(`${key}: ${value}`);
|
||||
}
|
||||
|
||||
// Get the URL from the form's action attribute
|
||||
|
||||
// Make the AJAX POST request using Axios
|
||||
axios.post(url, formData)
|
||||
.then(response => {
|
||||
// Handle success
|
||||
if (response.data.OK == true){
|
||||
$toast.success(response.data.message);
|
||||
}else{
|
||||
|
||||
$toast.error(response.data.error);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
// Handle error
|
||||
$toast.error( error);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
@ -0,0 +1,27 @@
|
||||
@include('components.panel-header')
|
||||
<div id="panel-preloader">
|
||||
<div class="loader"></div>
|
||||
</div>
|
||||
<input type="hidden" id="panel-dir" @if(langIsRTL(config('app.locale'))) value="rtl" @else value="ltr" @endif>
|
||||
<form action="{{route('admin.product.category-save',$product->slug)}}" method="post" id="ajax-sync-form">
|
||||
@csrf
|
||||
<div class="container pt-4" >
|
||||
@include('components.err')
|
||||
<h5>
|
||||
{{__("Categories")}} [{{$product->name}}]
|
||||
</h5>
|
||||
<ul class="nested-ul">
|
||||
{!!showCatNestedControl($cats,old('cat',isset($product)?$product->categories()->pluck('id')->toArray():[]))!!}
|
||||
</ul>
|
||||
</div>
|
||||
<button class="action-btn circle-btn"
|
||||
data-bs-toggle="tooltip"
|
||||
data-bs-placement="top"
|
||||
data-bs-custom-class="custom-tooltip"
|
||||
data-bs-title="{{__("Save")}}"
|
||||
id="categories-save-btn"
|
||||
>
|
||||
<i class="ri-save-2-line"></i>
|
||||
</button>
|
||||
</form>
|
||||
@include('components.panel-footer')
|
Loading…
Reference in New Issue