Skip to content

Commit fa1b302

Browse files
reloxx13andi34
authored andcommitted
add theme load unsaved settings warning confirmation dialog
1 parent 77387ae commit fa1b302

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

assets/js/admin/themes.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ $(function () {
1010
const $deleteButton = $('#theme-delete-btn');
1111
const $select = $('#theme-select');
1212
const $currentInput = $('input[name="theme[current]"]');
13+
let lastAppliedThemeSnapshot = null;
14+
15+
function snapshotTheme() {
16+
lastAppliedThemeSnapshot = JSON.stringify(collectCurrentTheme());
17+
}
18+
19+
function hasUnsavedChanges() {
20+
if (lastAppliedThemeSnapshot === null) {
21+
return false;
22+
}
23+
24+
return JSON.stringify(collectCurrentTheme()) !== lastAppliedThemeSnapshot;
25+
}
1326

1427
function updateLoadButtonState() {
1528
if ($loadButton.length === 0 || $deleteButton.length === 0) {
@@ -220,6 +233,9 @@ $(function () {
220233
}
221234

222235
updateLoadButtonState();
236+
if (lastAppliedThemeSnapshot === null) {
237+
snapshotTheme();
238+
}
223239
})
224240
.fail(() => {
225241
photoboothTools.overlay.showError(photoboothTools.getTranslation('error'));
@@ -266,6 +282,7 @@ $(function () {
266282
$nameInput.val(name);
267283
refreshSelect();
268284
updateLoadButtonState();
285+
snapshotTheme();
269286
})
270287
.fail(() => {
271288
photoboothTools.overlay.showError(photoboothTools.getTranslation('error'));
@@ -278,6 +295,14 @@ $(function () {
278295
return;
279296
}
280297

298+
if (hasUnsavedChanges()) {
299+
const confirmMessage = photoboothTools.getTranslation('theme_unsaved_confirm');
300+
const confirmed = window.confirm(confirmMessage);
301+
if (!confirmed) {
302+
return;
303+
}
304+
}
305+
281306
$.getJSON(apiBase, {
282307
action: 'get',
283308
name: selected,
@@ -292,6 +317,7 @@ $(function () {
292317
if ($nameInput.length) {
293318
$nameInput.val(selected);
294319
}
320+
snapshotTheme();
295321
updateLoadButtonState();
296322
}
297323
})

resources/lang/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@
922922
"theme_delete": "Theme löschen",
923923
"theme_choose": "Theme auswählen",
924924
"theme_override_confirm": "Theme \"%s\" wird überschrieben. Fortfahren?",
925+
"theme_unsaved_confirm": "Es gibt ungespeicherte Theme-Änderungen. Laden verwirft sie. Fortfahren?",
925926
"text_settings": "Text-Einstellungen",
926927
"toggleFullscreen": "Vollbildmodus umschalten",
927928
"translate": "Übersetzen",

resources/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,7 @@
928928
"theme_delete": "Delete theme",
929929
"theme_choose": "Choose theme",
930930
"theme_override_confirm": "Saving will override theme \"%s\". Continue?",
931+
"theme_unsaved_confirm": "You have unsaved theme changes. Loading will discard them. Continue?",
931932
"text_settings": "Text settings",
932933
"toggleFullscreen": "Toggle Fullscreen",
933934
"translate": "Translate",

0 commit comments

Comments
 (0)