jenkins-bot has submitted this change and it was merged.
Change subject: Manage save button state properly
......................................................................
Manage save button state properly
Simply calling setDisabled() on the save button from NewTopicWidget
isn't just ugly, it also doesn't work correctly: when EditorControlsWidget's
disabled state changes, that propagates to the save button,
overwriting what NewTopicWidget did.
Instead, manage "saveability" state in EditorControlsWidget,
and have NewTopicWidget interact with that.
Bonus: centralize saveability toggling code in NewTopicWidget
and also run it on save (so the save button is disabled again).
Change-Id: I890b8508ee6ecd489c46df72aa1ad4f293e5fa1e
---
M modules/flow/ui/widgets/editor/mw.flow.ui.EditorControlsWidget.js
M modules/flow/ui/widgets/mw.flow.ui.NewTopicWidget.js
2 files changed, 24 insertions(+), 13 deletions(-)
Approvals:
Sbisson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/flow/ui/widgets/editor/mw.flow.ui.EditorControlsWidget.js
b/modules/flow/ui/widgets/editor/mw.flow.ui.EditorControlsWidget.js
index e357c23..cf37680 100644
--- a/modules/flow/ui/widgets/editor/mw.flow.ui.EditorControlsWidget.js
+++ b/modules/flow/ui/widgets/editor/mw.flow.ui.EditorControlsWidget.js
@@ -48,6 +48,7 @@
this.cancelButton.connect( this, { click: [ 'emit', 'cancel' ]
} );
// Initialize
+ this.toggleSaveable( true );
this.$element
.append(
this.termsLabel.$element,
@@ -71,13 +72,22 @@
this.termsLabel.setLabel( msg );
};
+ /**
+ * Toggle whether the save button can be used
+ * @param {boolean} [saveable=!this.saveable] Whether the save button
can be used
+ */
+ mw.flow.ui.EditorControlsWidget.prototype.toggleSaveable = function (
saveable ) {
+ this.saveable = saveable === undefined ? !this.saveable :
!!saveable;
+ this.saveButton.setDisabled( this.isDisabled() ||
!this.saveable );
+ };
+
mw.flow.ui.EditorControlsWidget.prototype.setDisabled = function (
disabled ) {
// Parent method
mw.flow.ui.EditorControlsWidget.parent.prototype.setDisabled.call( this,
disabled );
if ( this.cancelButton && this.saveButton ) {
this.cancelButton.setDisabled( this.isDisabled() );
- this.saveButton.setDisabled( this.isDisabled() );
+ this.saveButton.setDisabled( this.isDisabled() ||
!this.saveable );
}
};
diff --git a/modules/flow/ui/widgets/mw.flow.ui.NewTopicWidget.js
b/modules/flow/ui/widgets/mw.flow.ui.NewTopicWidget.js
index 60d2b81..adfa6b7 100644
--- a/modules/flow/ui/widgets/mw.flow.ui.NewTopicWidget.js
+++ b/modules/flow/ui/widgets/mw.flow.ui.NewTopicWidget.js
@@ -47,7 +47,7 @@
// Events
this.editor.connect( this, {
- change: 'onChange',
+ change: 'updateSaveButtonState',
saveContent: 'onEditorSave',
cancel: 'onEditorCancel'
} );
@@ -61,12 +61,12 @@
} );
this.title.connect( this, {
- change: 'onChange'
+ change: 'updateSaveButtonState'
} );
this.title.$element.on( 'focusin', this.onTitleFocusIn.bind(
this ) );
- // TODO: Expose a better way to disable the save button
specifically
- // through the editor widget
- this.editor.editorControlsWidget.saveButton.setDisabled( true );
+
+ // Initialization
+ this.updateSaveButtonState();
this.$element
.addClass( 'flow-ui-newTopicWidget' )
@@ -83,19 +83,19 @@
OO.inheritClass( mw.flow.ui.NewTopicWidget, OO.ui.Widget );
/**
- * Respond to changes in either the editor or the title
+ * Update the state of the save button.
+ * @private
*/
- mw.flow.ui.NewTopicWidget.prototype.onChange = function () {
- // TODO: Expose a better way to disable the save button
specifically
- // through the editor widget
- this.editor.editorControlsWidget.saveButton.setDisabled(
- !this.title.getValue() ||
- this.editor.isEmpty()
+ mw.flow.ui.NewTopicWidget.prototype.updateSaveButtonState = function ()
{
+ this.editor.editorControlsWidget.toggleSaveable(
+ this.title.getValue() &&
+ !this.editor.isEmpty()
);
};
/**
* Respond to title input focusin event
+ * @private
*/
mw.flow.ui.NewTopicWidget.prototype.onTitleFocusIn = function () {
if ( !this.isExpanded() ) {
@@ -138,6 +138,7 @@
// Clear for next use
widget.title.setValue( '' );
widget.editor.setContent( '', 'html' );
+ widget.updateSaveButtonState();
} );
};
--
To view, visit https://gerrit.wikimedia.org/r/232070
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I890b8508ee6ecd489c46df72aa1ad4f293e5fa1e
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Sbisson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits