[MediaWiki-commits] [Gerrit] "You have unsaved changes" warning broken - change (mediawiki...Translate)
jenkins-bot has submitted this change and it was merged. Change subject: "You have unsaved changes" warning broken .. "You have unsaved changes" warning broken Handle three more cases: 1. Change language through ULS. 2. Change group through group selector. 3. Change the filters Bug: 46237 Change-Id: I846b6163156196086cd43b7015a0e82af82e0697 Followup: I958d9ca420100b0bedd919955283149d1bd3c23e --- M resources/js/ext.translate.base.js M resources/js/ext.translate.special.translate.js 2 files changed, 27 insertions(+), 6 deletions(-) Approvals: Siebrand: Looks good to me, approved jenkins-bot: Verified diff --git a/resources/js/ext.translate.base.js b/resources/js/ext.translate.base.js index 64d7a9e..8a6d0af 100644 --- a/resources/js/ext.translate.base.js +++ b/resources/js/ext.translate.base.js @@ -105,6 +105,14 @@ regions: ['SP'], autonym: mw.msg( 'translate-documentation-language' ) } ); + }, + + isDirty: function () { + return $( '.mw-ajax-dialog:visible' ).length // For old Translate + // For new Translate, something being typed in the current editor. + || mw.translate.dirty + // For new translate, previous editors has some unsaved edits + || $( '.tux-status-unsaved' ).length; } } ); @@ -119,12 +127,7 @@ function pageShowHandler() { $( window ).on( 'beforeunload.translate', function () { - if ( $( '.mw-ajax-dialog:visible' ).length // For old Translate - // For new Translate, something being typed in the current editor. - || mw.translate.dirty - // For new translate, previous editors has some unsaved edits - || $( '.tux-status-unsaved' ).length - ) { + if ( mw.translate.isDirty() ) { // Return our message return mw.msg( 'translate-js-support-unsaved-warning' ); } diff --git a/resources/js/ext.translate.special.translate.js b/resources/js/ext.translate.special.translate.js index 19add80..47ab587 100644 --- a/resources/js/ext.translate.special.translate.js +++ b/resources/js/ext.translate.special.translate.js @@ -62,6 +62,10 @@ api = new mw.Api(), $description = $( '.tux-editor-header .description' ); + if ( !checkDirty() ) { + return; + } + changes = { group: group.id }; @@ -88,6 +92,10 @@ language: language }; + if ( !checkDirty() ) { + return; + } + $( '.ext-translate-language-selector > .uls' ).text( $.uls.data.getAutonym( language ) ); $( '.tux-messagelist' ).data( 'targetlangcode', language ); @@ -99,6 +107,10 @@ changeFilter: function ( filter ) { var realFilters, uri; + + if ( !checkDirty() ) { + return; + } realFilters = [ '!ignored' ]; uri = new mw.Uri( window.location.href ); @@ -133,6 +145,12 @@ } } ); + function checkDirty() { + if ( mw.translate.isDirty() ) { + return window.confirm( mw.msg( 'translate-js-support-unsaved-warning' ) ); + } + return true; + } // Returns an array of jQuery objects of rows of translated // and proofread messages in the TUX editors. // Used several times. -- To view, visit https://gerrit.wikimedia.org/r/57042 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I846b6163156196086cd43b7015a0e82af82e0697 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Translate Gerrit-Branch: master Gerrit-Owner: Santhosh Gerrit-Reviewer: Siebrand Gerrit-Reviewer: jenkins-bot ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] "You have unsaved changes" warning broken - change (mediawiki...Translate)
Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/57042 Change subject: "You have unsaved changes" warning broken .. "You have unsaved changes" warning broken Handle three more cases: 1. Change language through ULS. 2. Change group through group selector. 3. Change the filters Bug: 46237 Change-Id: I846b6163156196086cd43b7015a0e82af82e0697 Followup: I958d9ca420100b0bedd919955283149d1bd3c23e --- M resources/js/ext.translate.base.js M resources/js/ext.translate.special.translate.js 2 files changed, 28 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate refs/changes/42/57042/1 diff --git a/resources/js/ext.translate.base.js b/resources/js/ext.translate.base.js index 64d7a9e..76a6a47 100644 --- a/resources/js/ext.translate.base.js +++ b/resources/js/ext.translate.base.js @@ -105,6 +105,14 @@ regions: ['SP'], autonym: mw.msg( 'translate-documentation-language' ) } ); + }, + + isDirty: function () { + return $( '.mw-ajax-dialog:visible' ).length // For old Translate + // For new Translate, something being typed in the current editor. + || mw.translate.dirty + // For new translate, previous editors has some unsaved edits + || $( '.tux-status-unsaved' ).length; } } ); @@ -119,18 +127,14 @@ function pageShowHandler() { $( window ).on( 'beforeunload.translate', function () { - if ( $( '.mw-ajax-dialog:visible' ).length // For old Translate - // For new Translate, something being typed in the current editor. - || mw.translate.dirty - // For new translate, previous editors has some unsaved edits - || $( '.tux-status-unsaved' ).length - ) { + if ( mw.translate.isDirty() ) { // Return our message return mw.msg( 'translate-js-support-unsaved-warning' ); } } ); } + $( document ).ready( function () { translateOnBeforeUnloadRegister(); } ); diff --git a/resources/js/ext.translate.special.translate.js b/resources/js/ext.translate.special.translate.js index 19add80..47ab587 100644 --- a/resources/js/ext.translate.special.translate.js +++ b/resources/js/ext.translate.special.translate.js @@ -62,6 +62,10 @@ api = new mw.Api(), $description = $( '.tux-editor-header .description' ); + if ( !checkDirty() ) { + return; + } + changes = { group: group.id }; @@ -88,6 +92,10 @@ language: language }; + if ( !checkDirty() ) { + return; + } + $( '.ext-translate-language-selector > .uls' ).text( $.uls.data.getAutonym( language ) ); $( '.tux-messagelist' ).data( 'targetlangcode', language ); @@ -99,6 +107,10 @@ changeFilter: function ( filter ) { var realFilters, uri; + + if ( !checkDirty() ) { + return; + } realFilters = [ '!ignored' ]; uri = new mw.Uri( window.location.href ); @@ -133,6 +145,12 @@ } } ); + function checkDirty() { + if ( mw.translate.isDirty() ) { + return window.confirm( mw.msg( 'translate-js-support-unsaved-warning' ) ); + } + return true; + } // Returns an array of jQuery objects of rows of translated // and proofread messages in the TUX editors. // Used several times. -- To view, visit https://gerrit.wikimedia.org/r/57042 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I846b6163156196086cd43b7015a0e82af82e0697 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Translate Gerrit-Branch: master Gerrit-Owner: Santhosh ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits