From adc64b3002abd5553a875e9ec57da00516b0d761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Thu, 29 Nov 2018 23:16:23 +0100 Subject: [PATCH] ve.ui.MWCitationDialog: Unbreak the logic to enable/disable actions This code was written in 2014 and it seems that some change to ve.ui.MWTemplateDialog since then made it not work. No idea why or when it broke. But we can implement the functionality much more easily now by overriding #setApplicableStatus, which works correctly. Bug: T210796 Change-Id: I6e87ca979a96785fc74f1a57f7d80ba4b43705f2 --- modules/ve-cite/ve.ui.MWCitationDialog.js | 37 +++++------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/modules/ve-cite/ve.ui.MWCitationDialog.js b/modules/ve-cite/ve.ui.MWCitationDialog.js index 1f26a35c9..1d92bf2aa 100644 --- a/modules/ve-cite/ve.ui.MWCitationDialog.js +++ b/modules/ve-cite/ve.ui.MWCitationDialog.js @@ -103,38 +103,15 @@ ve.ui.MWCitationDialog.prototype.getSetupProcess = function ( data ) { }, this ); }; -ve.ui.MWCitationDialog.prototype.onTransclusionReady = function () { - // Parent method - ve.ui.MWCitationDialog.super.prototype.onTransclusionReady.call( this ); - - if ( !this.hasUsefulParameter() ) { - this.actions.setAbilities( { apply: false, insert: false } ); - } -}; - /** * @inheritdoc */ -ve.ui.MWCitationDialog.prototype.setPageByName = function ( param ) { - var hasUsefulParameter = this.hasUsefulParameter(); - - // Parent method - ve.ui.MWCitationDialog.super.prototype.setPageByName.call( this, param ); - - this.actions.setAbilities( { apply: hasUsefulParameter, insert: hasUsefulParameter } ); -}; - -/** - * @inheritdoc - */ -ve.ui.MWCitationDialog.prototype.onAddParameterBeforeLoad = function ( page ) { - var dialog = this, - hasUsefulParameter = this.hasUsefulParameter(); - - page.preLoad = true; - page.valueInput.on( 'change', function () { - dialog.actions.setAbilities( { apply: hasUsefulParameter, insert: hasUsefulParameter } ); - } ); +ve.ui.MWCitationDialog.prototype.setApplicableStatus = function () { + ve.ui.MWCitationDialog.super.prototype.setApplicableStatus.call( this ); + // Parent method disables 'apply' if no changes were made (this is okay for us), and + // disables 'insert' if transclusion is empty (but it is never empty in our case). + // Instead, disable 'insert' if no parameters were added. + this.actions.setAbilities( { insert: this.hasUsefulParameter() } ); }; /** @@ -149,7 +126,7 @@ ve.ui.MWCitationDialog.prototype.hasUsefulParameter = function () { page = this.bookletLayout.pages[ name ]; if ( page instanceof ve.ui.MWParameterPage && - ( !page.preLoad || page.valueInput.getValue() !== '' ) + page.valueInput.getValue() !== '' ) { return true; }