Kai Nissen (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/226522

Change subject: [UploadWizard] Make button labels and targets configurable
......................................................................

[UploadWizard] Make button labels and targets configurable

This patch adds configurability of button labels and targets on the
"Thanks" page. To set a label and/or target, the 'display' section of
the campaign configuration is used. An example can be found in the
unit test.

Bug: T105285
Change-Id: Ieb6ee3660f7021d18a63c1fff3c6b088b54b6b23
---
M resources/ui/uw.ui.Thanks.js
M tests/qunit/controller/uw.controller.Thanks.test.js
2 files changed, 68 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard 
refs/changes/22/226522/1

diff --git a/resources/ui/uw.ui.Thanks.js b/resources/ui/uw.ui.Thanks.js
index e2b4304..48ac7c6 100644
--- a/resources/ui/uw.ui.Thanks.js
+++ b/resources/ui/uw.ui.Thanks.js
@@ -28,6 +28,20 @@
                var $header,
                        thanks = this;
 
+               this.getButtonConfig = function( buttonName, configField ) {
+                       if (
+                               !mw.UploadWizard.config ||
+                               !mw.UploadWizard.config.display ||
+                               !mw.UploadWizard.config.display[buttonName]
+                       ) {
+                               return false;
+                       }
+
+                       return typeof 
mw.UploadWizard.config.display[buttonName][configField] !== 'undefined' ?
+                               
mw.UploadWizard.config.display[buttonName][configField] :
+                               false;
+               };
+
                ui.Step.call(
                        this,
                        $( '#mwe-upwiz-stepdiv-thanks' ),
@@ -52,18 +66,25 @@
                this.$buttons = this.$div.find( '.mwe-upwiz-buttons' );
 
                this.homeButton = new oo.ui.ButtonWidget( {
-                       label: mw.message( 'mwe-upwiz-home' ).text(),
-                       href: mw.config.get( 'wgArticlePath' ).replace( '$1', 
'' )
+                       label: this.getButtonConfig( 'homeButton', 'label' ) || 
mw.message( 'mwe-upwiz-home' ).text(),
+                       href: this.getButtonConfig( 'homeButton', 'target' ) || 
mw.config.get( 'wgArticlePath' ).replace( '$1', '' )
                } );
 
-               this.homeButtonField = new oo.ui.FieldLayout( this.homeButton, 
{ align: 'inline' } );
+               this.homeButtonField = new oo.ui.FieldLayout( this.homeButton, 
{ align: 'inline' });
 
                this.beginButton = new oo.ui.ButtonWidget( {
-                       label: mw.message( 'mwe-upwiz-upload-another' ).text(),
+                       label: this.getButtonConfig( 'beginButton', 'label' ) 
||  mw.message( 'mwe-upwiz-upload-another' ).text(),
                        flags: [ 'progressive', 'primary' ]
-               } ).on( 'click', function () {
-                       thanks.emit( 'next-step' );
                } );
+               
+               var beginButtonTarget = this.getButtonConfig( 'beginButton', 
'target' );
+               if ( !beginButtonTarget ) {
+                       this.beginButton.on( 'click', function () {
+                               thanks.emit( 'next-step' );
+                       } );
+               } else {
+                       this.beginButton.setHref( beginButtonTarget );
+               }
 
                this.beginButtonField = new oo.ui.FieldLayout( 
this.beginButton, { align: 'inline' } );
 
diff --git a/tests/qunit/controller/uw.controller.Thanks.test.js 
b/tests/qunit/controller/uw.controller.Thanks.test.js
index 6c2acc5..62e9fda 100644
--- a/tests/qunit/controller/uw.controller.Thanks.test.js
+++ b/tests/qunit/controller/uw.controller.Thanks.test.js
@@ -38,4 +38,45 @@
 
                assert.strictEqual( auStub.callCount, 3 );
        } );
+
+       QUnit.test( 'Custom button configuration', 4, function( assert ) {
+               mw.UploadWizard.config = {
+                       display: {
+                               homeButton: {
+                                       label: 'This is just a test',
+                                       target: 
'https://wiki.example.com/wiki/Main_Page'
+                               },
+                               beginButton: {
+                                       label: 'Let me start again',
+                                       target: 
'https://commons.wikimedia.org/wiki/Special:UploadWizard'
+                               }
+                       }
+               };
+               var uiThanks = new uw.ui.Thanks();
+
+               assert.equal(
+                       uiThanks.homeButton.getLabel(),
+                       'This is just a test',
+                       'The label of the home button matches the configured 
text.'
+               );
+
+               assert.equal(
+                       uiThanks.homeButton.getHref(),
+                       'https://wiki.example.com/wiki/Main_Page',
+                       'The target of the home button matches the configured 
URL.'
+               );
+
+               assert.equal(
+                       uiThanks.beginButton.getLabel(),
+                       'Let me start again',
+                       'The label of the begin button matches the configured 
text.'
+               );
+
+               assert.equal(
+                       uiThanks.beginButton.getHref(),
+                       
'https://commons.wikimedia.org/wiki/Special:UploadWizard',
+                       'The target of the begin button matches the configured 
URL.'
+               );
+
+       } );
 }( mediaWiki.uploadWizard ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/226522
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieb6ee3660f7021d18a63c1fff3c6b088b54b6b23
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Kai Nissen (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to