@@ -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 } )
0 commit comments