diff --git a/resources/views/admin/products/index.blade.php b/resources/views/admin/products/index.blade.php index 6c6a0f4..1bd67ca 100644 --- a/resources/views/admin/products/index.blade.php +++ b/resources/views/admin/products/index.blade.php @@ -599,12 +599,28 @@ hover:bg-slate-100 dark:hover:bg-white/5 rounded-lg flex items-center justify-be }, handleFilterSubmit(tab) { - // Clear page when searching - const url = new URL(window.location.href); - const pageKey = tab === 'products' ? 'product_page' : 'category_page'; - url.searchParams.delete(pageKey); + // When submitting the filter form, we want to reset to page 1 + const container = document.getElementById('tab-' + tab + '-container'); + const form = container?.querySelector('form'); + let params = new URLSearchParams(); - this.fetchTabData(tab); + if (form) { + const formData = new FormData(form); + for (let [key, value] of formData.entries()) { + if (value) params.set(key, value); + } + } + + // Ensure tab and ajax markers are present + params.set('tab', tab); + params.set('_ajax', '1'); + + // Explicitly remove page parameters to reset to page 1 + params.delete('product_page'); + params.delete('category_page'); + + const url = window.location.pathname + '?' + params.toString(); + this.fetchTabData(tab, url); }, bindPaginationLinks(containerSelector, tab) { @@ -749,73 +765,13 @@ hover:bg-slate-100 dark:hover:bg-white/5 rounded-lg flex items-center justify-be this.isStatusConfirmOpen = true; }, - async submitConfirmedForm() { + submitConfirmedForm() { if (this.isStatusConfirmOpen) { this.isStatusConfirmOpen = false; - this.loading = true; - try { - const response = await fetch(this.toggleFormAction, { - method: 'POST', - headers: { - 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content'), - 'Accept': 'application/json', - 'Content-Type': 'application/x-www-form-urlencoded', - 'X-Requested-With': 'XMLHttpRequest' - }, - body: new URLSearchParams({ - '_method': 'PATCH' - }) - }); - const data = await response.json(); - if (data.success) { - await this.fetchTabData(this.activeTab); - if (window.showToast) window.showToast(data.message, 'success'); - } else { - if (window.showToast) window.showToast(data.message || 'Error', 'error'); - } - } catch (error) { - console.error('Status toggle error:', error); - if (window.showToast) window.showToast('{{ __("Operation failed") }}', 'error'); - } finally { - this.loading = false; - } + this.$refs.statusToggleForm.submit(); } }, - confirmDelete(actionUrl) { - this.deleteFormAction = actionUrl; - this.isDeleteConfirmOpen = true; - }, - - async deleteItem() { - this.isDeleteConfirmOpen = false; - this.loading = true; - try { - const response = await fetch(this.deleteFormAction, { - method: 'POST', - headers: { - 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content'), - 'Accept': 'application/json', - 'X-Requested-With': 'XMLHttpRequest' - }, - body: new URLSearchParams({ - '_method': 'DELETE' - }) - }); - const data = await response.json(); - if (data.success) { - await this.fetchTabData(this.activeTab); - if (window.showToast) window.showToast(data.message, 'success'); - } else { - if (window.showToast) window.showToast(data.message || 'Error', 'error'); - } - } catch (error) { - console.error('Delete error:', error); - if (window.showToast) window.showToast('{{ __("Operation failed") }}', 'error'); - } finally { - this.loading = false; - } - }, getCategoryName(id) { const category = this.categories.find(c => c.id == id); diff --git a/resources/views/admin/products/partials/tab-products.blade.php b/resources/views/admin/products/partials/tab-products.blade.php index 4225faa..55e608f 100644 --- a/resources/views/admin/products/partials/tab-products.blade.php +++ b/resources/views/admin/products/partials/tab-products.blade.php @@ -183,7 +183,7 @@ $baseRoute = 'admin.data-config.products'; @else