jenkins-bot has submitted this change and it was merged.
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 includes/CampaignSchema.php
M includes/UploadWizardCampaign.php
M resources/controller/uw.controller.Thanks.js
M resources/mw.UploadWizard.js
M resources/ui/uw.ui.Thanks.js
M tests/qunit/controller/uw.controller.Thanks.test.js
6 files changed, 108 insertions(+), 10 deletions(-)
Approvals:
MarkTraceur: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/CampaignSchema.php b/includes/CampaignSchema.php
index 7d4e5d0..069d392 100644
--- a/includes/CampaignSchema.php
+++ b/includes/CampaignSchema.php
@@ -102,6 +102,28 @@
),
"thanksLabel" => array(
"type" => "string"
+ ),
+ "homeButton" => array(
+ "type" => "object",
+ "properties" => array(
+ "label" => array(
+ "type" => "string"
+ ),
+ "target" => array(
+ "type" => "string"
+ )
+ )
+ ),
+ "beginButton" => array(
+ "type" => "object",
+ "properties" => array(
+ "label" => array(
+ "type" => "string"
+ ),
+ "target" => array(
+ "type" => "string"
+ )
+ )
)
)
),
diff --git a/includes/UploadWizardCampaign.php
b/includes/UploadWizardCampaign.php
index d30b45b..b58ebd9 100755
--- a/includes/UploadWizardCampaign.php
+++ b/includes/UploadWizardCampaign.php
@@ -300,7 +300,17 @@
$parsedConfig[$key] =
$this->parseValue( $value, $lang );
break;
case "display":
- $parsedConfig['display'] =
$this->parseArrayValues( $value, $lang );
+ foreach ( $value as $option =>
$optionValue ) {
+ if ( is_array( $optionValue ) )
{
+
$parsedConfig['display'][$option] = $this->parseArrayValues(
+ $optionValue,
+ $lang,
+ array( 'label' )
+ );
+ } else {
+
$parsedConfig['display'][$option] = $this->parseValue( $optionValue, $lang );
+ }
+ }
break;
case "fields":
$parsedConfig['fields'] = array();
diff --git a/resources/controller/uw.controller.Thanks.js
b/resources/controller/uw.controller.Thanks.js
index 9d2f8d2..cf32192 100644
--- a/resources/controller/uw.controller.Thanks.js
+++ b/resources/controller/uw.controller.Thanks.js
@@ -23,10 +23,10 @@
* @class
* @constructor
*/
- function Thanks() {
+ function Thanks( config ) {
uw.controller.Step.call(
this,
- new uw.ui.Thanks()
+ new uw.ui.Thanks( config )
.connect( this, {
'reset-wizard': [ 'emit',
'reset-wizard' ]
} )
diff --git a/resources/mw.UploadWizard.js b/resources/mw.UploadWizard.js
index 6040f85..0cc0d3e 100644
--- a/resources/mw.UploadWizard.js
+++ b/resources/mw.UploadWizard.js
@@ -56,7 +56,7 @@
wizard.steps.details.moveFrom();
} ),
- thanks: new uw.controller.Thanks()
+ thanks: new uw.controller.Thanks( config )
.on( 'reset-wizard', function () {
wizard.reset();
} )
diff --git a/resources/ui/uw.ui.Thanks.js b/resources/ui/uw.ui.Thanks.js
index e2b4304..463bc15 100644
--- a/resources/ui/uw.ui.Thanks.js
+++ b/resources/ui/uw.ui.Thanks.js
@@ -24,9 +24,12 @@
* @extends mw.uw.ui.Step
* @constructor
*/
- function Thanks() {
+ function Thanks( config ) {
var $header,
+ beginButtonTarget,
thanks = this;
+
+ this.config = config;
ui.Step.call(
this,
@@ -52,18 +55,26 @@
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.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' );
} );
+
+ // TODO: make the step order configurable by campaign
definitions instead of using this hack
+ 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' } );
@@ -165,5 +176,19 @@
this.$div.find( '.mwe-upwiz-thanks' ).remove();
};
+ /**
+ * Get button configuration options from a campaign definition
+ * @param {string} buttonName name of the button as defined in campaign
configuration
+ * @param {string} configField name of the button's attributes
+ * @return {Object|undefined}
+ */
+ TP.getButtonConfig = function ( buttonName, configField ) {
+ if ( !this.config || !this.config.display ||
!this.config.display[buttonName] ) {
+ return;
+ }
+
+ return this.config.display[buttonName][configField];
+ };
+
ui.Thanks = Thanks;
}( mediaWiki, jQuery, mediaWiki.uploadWizard.ui, OO ) );
diff --git a/tests/qunit/controller/uw.controller.Thanks.test.js
b/tests/qunit/controller/uw.controller.Thanks.test.js
index 6c2acc5..20966b4 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 ) {
+ var 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'
+ }
+ }
+ },
+ uiThanks = new uw.ui.Thanks( config );
+
+ 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: merged
Gerrit-Change-Id: Ieb6ee3660f7021d18a63c1fff3c6b088b54b6b23
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Kai Nissen (WMDE) <[email protected]>
Gerrit-Reviewer: Kai Nissen (WMDE) <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: WMDE-Fisch <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits