[MediaWiki-commits] [Gerrit] Move setSkipTutorialPreference to Tutorial class - change (mediawiki...UploadWizard)
jenkins-bot has submitted this change and it was merged. Change subject: Move setSkipTutorialPreference to Tutorial class .. Move setSkipTutorialPreference to Tutorial class Change-Id: Iaa0c77c26a8c0f937b7ad85081af79eb5119283b --- M UploadWizardHooks.php M resources/controller/uw.controller.Tutorial.js M resources/mw.UploadWizard.js 3 files changed, 41 insertions(+), 31 deletions(-) Approvals: Gilles: Looks good to me, approved jenkins-bot: Verified diff --git a/UploadWizardHooks.php b/UploadWizardHooks.php index 7420cb1..b15ae62 100644 --- a/UploadWizardHooks.php +++ b/UploadWizardHooks.php @@ -558,6 +558,10 @@ 'uw.controller.base', 'uw.ui.Tutorial', ), + + 'messages' = array( + 'mwe-upwiz-prevent-close-wait', + ), ), 'uw.controller.Upload' = array( diff --git a/resources/controller/uw.controller.Tutorial.js b/resources/controller/uw.controller.Tutorial.js index 377ebac..84690d6 100644 --- a/resources/controller/uw.controller.Tutorial.js +++ b/resources/controller/uw.controller.Tutorial.js @@ -16,8 +16,12 @@ */ ( function ( mw, uw, $, oo ) { - function Tutorial() { + var TP; + + function Tutorial( api ) { var tutorial = this; + + this.api = api; uw.controller.Step.call( this, @@ -36,6 +40,13 @@ .on( 'next-step', function () { ( new mw.UploadWizardTutorialEvent( 'continue' ) ).dispatch(); + + // if the skip checkbox is checked, set the skip user preference + if ( $( '#mwe-upwiz-skip' ).is( ':checked' ) ) { + $( '#mwe-upwiz-skip' ).tipsy( 'hide' ); + tutorial.setSkipPreference(); + } + tutorial.emit( 'next-step' ); } ) ); @@ -43,5 +54,29 @@ oo.inheritClass( Tutorial, uw.controller.Step ); + TP = Tutorial.prototype; + + /** +* Set the skip tutorial user preference via the options API +*/ + TP.setSkipPreference = function () { + var api = this.api, + isComplete = false, + allowCloseWindow = mw.confirmCloseWindow( { + message: function () { return mw.message( 'mwe-upwiz-prevent-close-wait' ).text(); }, + test: function () { return !isComplete; } + } ); + + api.postWithToken( 'options', { + action: 'options', + change: 'upwiz_skiptutorial=1' + } ) + .done( function () { + isComplete = true; + allowCloseWindow(); + return true; + } ); + }; + uw.controller.Tutorial = Tutorial; }( mediaWiki, mediaWiki.uploadWizard, jQuery, OO ) ); diff --git a/resources/mw.UploadWizard.js b/resources/mw.UploadWizard.js index e96ce88..5701998 100644 --- a/resources/mw.UploadWizard.js +++ b/resources/mw.UploadWizard.js @@ -30,14 +30,8 @@ this.showDeed = false; this.steps = { - tutorial: new uw.controller.Tutorial() + tutorial: new uw.controller.Tutorial( this.api ) .on( 'next-step', function () { - // if the skip checkbox is checked, set the skip user preference - if ( $( '#mwe-upwiz-skip' ).is( ':checked' ) ) { - $( '#mwe-upwiz-skip' ).tipsy( 'hide' ); - wizard.setSkipTutorialPreference(); - } - wizard.moveToStep( 'file' ); } ), file: new uw.controller.Upload(), @@ -1076,29 +1070,6 @@ } else { $( '#mwe-upwiz-details-error-count' ).empty(); } - }, - - /** -* Set the skip tutorial user preference via the options API -*/ - setSkipTutorialPreference: function () { - var api = this.api, - isComplete = false, - allowCloseWindow = mw.confirmCloseWindow( { - message:
[MediaWiki-commits] [Gerrit] Move setSkipTutorialPreference to Tutorial class - change (mediawiki...UploadWizard)
MarkTraceur has uploaded a new change for review. https://gerrit.wikimedia.org/r/153413 Change subject: Move setSkipTutorialPreference to Tutorial class .. Move setSkipTutorialPreference to Tutorial class Change-Id: Iaa0c77c26a8c0f937b7ad85081af79eb5119283b --- M resources/controller/uw.controller.Tutorial.js M resources/mw.UploadWizard.js 2 files changed, 30 insertions(+), 37 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard refs/changes/13/153413/1 diff --git a/resources/controller/uw.controller.Tutorial.js b/resources/controller/uw.controller.Tutorial.js index 278e6ad..936daff 100644 --- a/resources/controller/uw.controller.Tutorial.js +++ b/resources/controller/uw.controller.Tutorial.js @@ -16,8 +16,12 @@ */ ( function ( mw, uw, $, oo ) { - function Tutorial() { + var TP; + + function Tutorial( api ) { var tutorial = this; + + this.api = api; uw.controller.Step.call( this, $( '#mwe-upwiz-stepdiv-tutorial' ), $( '#mwe-upwiz-step-tutorial' ) ); @@ -36,11 +40,35 @@ .on( 'next-step', function () { ( new mw.UploadWizardTutorialEvent( 'continue' ) ).dispatch(); + + // if the skip checkbox is checked, set the skip user preference + if ( $( '#mwe-upwiz-skip' ).is( ':checked' ) ) { + $( '#mwe-upwiz-skip' ).tipsy( 'hide' ); + tutorial.setSkipPreference(); + } + tutorial.emit( 'next-step' ); } ); } oo.inheritClass( Tutorial, uw.controller.Step ); + TP = Tutorial.prototype; + + /** +* Set the skip tutorial user preference via the options API +*/ + TP.setSkipPreference: function () { + var api = this.api; + + api.getToken( 'options' ).done( token ) { + api.post( { + action: 'options', + change: 'upwiz_skiptutorial=1', + token: token + } ); + ); + }; + uw.controller.Tutorial = Tutorial; }( mediaWiki, mediaWiki.uploadWizard, jQuery, OO ) ); diff --git a/resources/mw.UploadWizard.js b/resources/mw.UploadWizard.js index e6967da..0dd1779 100644 --- a/resources/mw.UploadWizard.js +++ b/resources/mw.UploadWizard.js @@ -33,14 +33,8 @@ this.eventFlowLogger = new uw.EventFlowLogger( mw.eventLog ); this.steps = [ - new uw.controller.Tutorial() + new uw.controller.Tutorial( this.api ) .on( 'next-step', function () { - // if the skip checkbox is checked, set the skip user preference - if ( $( '#mwe-upwiz-skip' ).is( ':checked' ) ) { - $( '#mwe-upwiz-skip' ).tipsy( 'hide' ); - wizard.setSkipTutorialPreference(); - } - wizard.moveToStep( 'file' ); } ), @@ -1065,35 +1059,6 @@ } else { $( '#mwe-upwiz-details-error-count' ).empty(); } - }, - - /** -* Set the skip tutorial user preference via the options API -*/ - setSkipTutorialPreference: function() { - var api = this.api, - tokenRequest = { - 'action': 'tokens', - 'type' : 'options' - }, - prefRequest = { - 'action': 'options', - 'change': 'upwiz_skiptutorial=1' - }; - - api.post( tokenRequest, - function( data ) { - var token; - try { - token = data.tokens.optionstoken; - } catch ( e ) { - throw new Error( 'Could not get token to set user preferences (requires MediaWiki 1.20).' ); - } - prefRequest.token = token; - api.post( prefRequest, function() { return true; } ); - } - ); - }, /** -- To view, visit https://gerrit.wikimedia.org/r/153413 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iaa0c77c26a8c0f937b7ad85081af79eb5119283b Gerrit-PatchSet: 1 Gerrit-Project: