-
Delete Space
-
Are you sure you want to delete this space? This action cannot be undone.
-
-
-
-
+
+
+
+
Delete Space
+
Are you sure you want to delete this space? This action cannot be undone.
+
+
+
-
+
diff --git a/resources/js/Pages/Media/Index.vue b/resources/js/Pages/Media/Index.vue
index 375f6a5..0796e44 100644
--- a/resources/js/Pages/Media/Index.vue
+++ b/resources/js/Pages/Media/Index.vue
@@ -26,7 +26,7 @@ async function fetchAssets(page = 1) {
if (filters.type) params.set('type', filters.type);
if (filters.tag) params.set('tag', filters.tag);
await csrfCookie();
- const res = await fetch(`/api/media?${params}`, {
+ const res = await fetch(`/api/v1/media?${params}`, {
credentials: 'include',
headers: { 'Accept': 'application/json', 'X-XSRF-TOKEN': xsrfToken() },
});
@@ -72,7 +72,7 @@ function closeDetail() { activeAsset.value = null; }
async function deleteAsset(asset) {
if (!confirm(`Delete "${asset.filename}"? This cannot be undone.`)) return;
await csrfCookie();
- const res = await fetch(`/api/media/${asset.id}`, {
+ const res = await fetch(`/api/v1/media/${asset.id}`, {
method: 'DELETE', credentials: 'include',
headers: { 'Accept': 'application/json', 'X-XSRF-TOKEN': xsrfToken() },
});
diff --git a/resources/js/Pages/Settings/Locales.vue b/resources/js/Pages/Settings/Locales.vue
index 003af30..d8d7f1b 100644
--- a/resources/js/Pages/Settings/Locales.vue
+++ b/resources/js/Pages/Settings/Locales.vue
@@ -29,23 +29,63 @@ function openAddModal() {
}
function selectLocale(s) { addingLocale.value = s; }
-function confirmAdd() {
+function xsrfToken() {
+ return decodeURIComponent(document.cookie.match(/XSRF-TOKEN=([^;]+)/)?.[1] ?? '');
+}
+
+function authHeaders(withBody = false) {
+ const headers = {
+ 'Accept': 'application/json',
+ 'X-Requested-With': 'XMLHttpRequest',
+ 'X-XSRF-TOKEN': xsrfToken(),
+ };
+ if (withBody) headers['Content-Type'] = 'application/json';
+ return headers;
+}
+
+async function confirmAdd() {
if (!addingLocale.value) return;
adding.value = true;
- router.post("/api/v1/locales", {
- locale: addingLocale.value.code,
- label: addingLocale.value.label,
- }, {
- onFinish: () => { adding.value = false; showAddModal.value = false; },
- preserveScroll: true,
- });
+ try {
+ const res = await fetch("/api/v1/locales", {
+ method: 'POST',
+ credentials: 'include',
+ headers: authHeaders(true),
+ body: JSON.stringify({
+ locale: addingLocale.value.code,
+ label: addingLocale.value.label,
+ }),
+ });
+ if (res.ok) {
+ showAddModal.value = false;
+ router.reload({ only: ['locales'] });
+ } else {
+ const data = await res.json().catch(() => ({}));
+ console.error('Failed to add locale:', data);
+ }
+ } finally {
+ adding.value = false;
+ }
}
-function toggleActive(locale) {
- router.patch("/api/v1/locales/" + locale.id, { is_active: !locale.is_active }, { preserveScroll: true });
+async function toggleActive(locale) {
+ const res = await fetch("/api/v1/locales/" + locale.id, {
+ method: 'PATCH',
+ credentials: 'include',
+ headers: authHeaders(true),
+ body: JSON.stringify({ is_active: !locale.is_active }),
+ });
+ if (res.ok) router.reload({ only: ['locales'] });
}
-function setDefault(locale) {
- router.patch("/api/v1/locales/" + locale.id, { is_default: true }, { preserveScroll: true });
+
+async function setDefault(locale) {
+ const res = await fetch("/api/v1/locales/" + locale.id, {
+ method: 'PATCH',
+ credentials: 'include',
+ headers: authHeaders(true),
+ body: JSON.stringify({ is_default: true }),
+ });
+ if (res.ok) router.reload({ only: ['locales'] });
}
const dragging = ref(null);
@@ -58,29 +98,45 @@ function onDragStart(i) { dragging.value = i; }
function onDragOver(i) { dragOver.value = i; }
function onDragEnd() { dragging.value = null; dragOver.value = null; }
-function onDrop(index) {
+async function onDrop(index) {
if (dragging.value === null || dragging.value === index) return;
const arr = [...localLocales.value];
const [moved] = arr.splice(dragging.value, 1);
arr.splice(index, 0, moved);
localLocales.value = arr;
dragging.value = null; dragOver.value = null;
- router.patch("/api/v1/locales/reorder", {
- order: arr.map((l, i) => ({ id: l.id, sort_order: i + 1 })),
- }, { preserveScroll: true });
+ const res = await fetch("/api/v1/locales/reorder", {
+ method: 'PATCH',
+ credentials: 'include',
+ headers: authHeaders(true),
+ body: JSON.stringify({
+ order: arr.map((l, i) => ({ id: l.id, sort_order: i + 1 })),
+ }),
+ });
+ if (res.ok) router.reload({ only: ['locales'] });
}
const deleteError = ref(null);
const deleting = ref(null);
-function deleteLocale(locale) {
+async function deleteLocale(locale) {
if (!confirm("Delete " + locale.label + " locale? This cannot be undone.")) return;
deleting.value = locale.id;
- router.delete("/api/v1/locales/" + locale.id, {
- onError: (e) => { deleteError.value = e.locale ?? "Cannot delete: content may exist in this locale."; },
- onFinish: () => { deleting.value = null; },
- preserveScroll: true,
- });
+ try {
+ const res = await fetch("/api/v1/locales/" + locale.id, {
+ method: 'DELETE',
+ credentials: 'include',
+ headers: authHeaders(),
+ });
+ if (res.ok) {
+ router.reload({ only: ['locales'] });
+ } else {
+ const data = await res.json().catch(() => ({}));
+ deleteError.value = data.message ?? data.locale ?? "Cannot delete: content may exist in this locale.";
+ }
+ } finally {
+ deleting.value = null;
+ }
}