From 3d0849112ae49ec7643f0dabedfd0c9719784fcf Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Wed, 2 Feb 2022 21:49:26 +0000 Subject: [PATCH] ReplyWidget: Factor out #createErrorMessage Change-Id: Ie7e34154d74c24ce8379552fdf13feba31fd401f --- modules/dt.ui.ReplyWidget.js | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/modules/dt.ui.ReplyWidget.js b/modules/dt.ui.ReplyWidget.js index c7466c538..2bb7f348a 100644 --- a/modules/dt.ui.ReplyWidget.js +++ b/modules/dt.ui.ReplyWidget.js @@ -330,8 +330,9 @@ ReplyWidget.prototype.getMode = null; * @param {boolean} [preserveStorage] Preserve auto-save storage */ ReplyWidget.prototype.clear = function ( preserveStorage ) { - if ( this.errorMessage ) { - this.errorMessage.$element.remove(); + if ( this.saveErrorMessage ) { + this.saveErrorMessage.$element.remove(); + this.saveErrorMessage = null; } this.$preview.empty(); this.previewWikitext = null; @@ -831,6 +832,22 @@ ReplyWidget.prototype.onUnload = function () { } ); }; +/** + * Create an error message widget and attach it to the DOM + * + * @param {string} message Message string + * @return {OO.ui.MessageWidget} Message widget + */ +ReplyWidget.prototype.createErrorMessage = function ( message ) { + var errorMessage = new OO.ui.MessageWidget( { + type: 'error', + label: message, + classes: [ 'ext-discussiontools-ui-replyWidget-error' ] + } ); + errorMessage.$element.insertBefore( this.replyBodyWidget.$element ); + return errorMessage; +}; + /** * Handle clicks on the reply button */ @@ -841,8 +858,9 @@ ReplyWidget.prototype.onReplyClick = function () { return; } - if ( this.errorMessage ) { - this.errorMessage.$element.remove(); + if ( this.saveErrorMessage ) { + this.saveErrorMessage.$element.remove(); + this.saveErrorMessage = null; } this.saveInitiated = mw.now(); @@ -897,12 +915,9 @@ ReplyWidget.prototype.onReplyClick = function () { widget.captchaInput.scrollElementIntoView(); } else { - widget.errorMessage = new OO.ui.MessageWidget( { - type: 'error', - label: code instanceof Error ? code.toString() : controller.getApi().getErrorMessage( data ), - classes: [ 'ext-discussiontools-ui-replyWidget-error' ] - } ); - widget.errorMessage.$element.insertBefore( widget.replyBodyWidget.$element ); + widget.saveErrorMessage = widget.createErrorMessage( + code instanceof Error ? code.toString() : controller.getApi().getErrorMessage( data ) + ); } if ( code instanceof Error ) {