@@ -323,6 +323,36 @@ MoinMoin.prototype.toggleSubtree = function (item) {
323
323
} ;
324
324
325
325
326
+ MoinMoin . prototype . displayFlashMessages = function ( messages ) {
327
+ for ( i = 0 ; i < messages . length ; i += 1 ) {
328
+ f = $ ( document . createElement ( 'p' ) ) ;
329
+ f . html ( messages [ i ] [ 0 ] ) ;
330
+ f . addClass ( 'moin-flash' ) ;
331
+ f . addClass ( 'moin-flash-javascript' ) ;
332
+ f . addClass ( 'moin-flash-' + messages [ i ] [ 1 ] ) ;
333
+ $ ( f ) . click ( function ( ) {
334
+ this . remove ( ) ;
335
+ } ) ;
336
+ $ ( '#moin-flash' ) . append ( f ) ;
337
+ }
338
+ }
339
+
340
+ // remove all flash messages previously added via javascript
341
+ MoinMoin . prototype . clearFlashMessages = function ( ) {
342
+ $ ( '#moin-flash .moin-flash-javascript' ) . remove ( ) ;
343
+ }
344
+
345
+ MoinMoin . prototype . saveFlashMessages = function ( messages ) {
346
+ localStorage . setItem ( "moin-flash-messages" , JSON . stringify ( messages ) )
347
+ }
348
+
349
+ MoinMoin . prototype . restoreFlashMessages = function ( ) {
350
+ messages = JSON . parse ( localStorage . getItem ( "moin-flash-messages" ) || "[]" )
351
+ localStorage . removeItem ( "moin-flash-messages" )
352
+ this . clearFlashMessages ( )
353
+ this . displayFlashMessages ( messages )
354
+ }
355
+
326
356
// User Settings page enhancements - make long multi-form page appear as a shorter page
327
357
// with a row of tabs at the top or side that may be clicked to select a form.
328
358
MoinMoin . prototype . enhanceUserSettings = function ( ) {
@@ -421,20 +451,10 @@ MoinMoin.prototype.enhanceUserSettings = function () {
421
451
clearInterval ( buttonDotAnimation ) ;
422
452
// if the response indicates a redirect, set the new location
423
453
if ( data . redirect ) {
454
+ MoinMoin . prototype . saveFlashMessages ( data . flash )
424
455
location . href = data . redirect ;
425
456
return ;
426
457
}
427
- // remove all flash messages previously added via javascript
428
- $ ( '#moin-flash .moin-flash-javascript' ) . remove ( ) ;
429
- // add new flash messages from the response
430
- for ( i = 0 ; i < data . flash . length ; i += 1 ) {
431
- f = $ ( document . createElement ( 'p' ) ) ;
432
- f . html ( data . flash [ i ] [ 0 ] ) ;
433
- f . addClass ( 'moin-flash' ) ;
434
- f . addClass ( 'moin-flash-javascript' ) ;
435
- f . addClass ( 'moin-flash-' + data . flash [ i ] [ 1 ] ) ;
436
- $ ( '#moin-flash' ) . append ( f ) ;
437
- }
438
458
// get the new form element from the response
439
459
newform = $ ( data . form ) ;
440
460
// set event handlers on the new form
@@ -445,9 +465,13 @@ MoinMoin.prototype.enhanceUserSettings = function () {
445
465
// replace the old form with the new one
446
466
form . replaceWith ( newform ) ;
447
467
if ( ev . currentTarget . id === 'usersettings_ui' || ev . currentTarget . id === 'usersettings_personal' ) {
468
+ MoinMoin . prototype . saveFlashMessages ( data . flash )
448
469
// theme or language may have changed, show user the new theme/language
449
470
location . reload ( true ) ;
471
+ return ;
450
472
}
473
+ // show any flash messages received with the server response
474
+ MoinMoin . prototype . displayFlashMessages ( data . flash )
451
475
} , 'json' ) ;
452
476
return false ;
453
477
}
@@ -848,4 +872,5 @@ $(document).ready(function () {
848
872
// placing initToggleComments after enhanceEdit prevents odd autoscroll issue when editing hidden comments
849
873
moin . initToggleComments ( ) ;
850
874
875
+ moin . restoreFlashMessages ( ) ;
851
876
} ) ;
0 commit comments