jenkins-bot has submitted this change and it was merged. Change subject: Show pending state on action button and keep dialog open when switching to source mode ......................................................................
Show pending state on action button and keep dialog open when switching to source mode Instead of doing a blocking overlay, we're simply keeping the dialog open, which is necessary for the pending status of the action buttons anyway. Requires Ib2c8f336 in OOUI Bug: 65012 Change-Id: I65b5de4a1666a81b157a71f6fec490007689eb44 --- M modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js M modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js 2 files changed, 57 insertions(+), 42 deletions(-) Approvals: Catrope: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js index 7f1f038..715d896 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js @@ -881,56 +881,21 @@ }; /** - * Switch to edit source mode with the current wikitext + * Open the dialog to switch to edit source mode with the current wikitext, or just do it straight + * away if the document is unmodified. If we open the dialog, the document opacity will be set to + * half, which can be reset with the resetDocumentOpacity function. * * @method */ ve.init.mw.ViewPageTarget.prototype.editSource = function () { - var $documentNode = this.surface.getView().getDocument().getDocumentNode().$element, - target = this; - if ( !this.surface.getModel().hasBeenModified() ) { - target.submitting = true; - window.location.href = this.viewUri.clone().extend( { - action: 'edit', - veswitched: 1 - } ).toString(); + this.switchToWikitextEditor( true ); return; } - $documentNode.css( 'opacity', 0.5 ); + this.surface.getView().getDocument().getDocumentNode().$element.css( 'opacity', 0.5 ); - this.surface.getDialogs().openWindow( 'wikitextswitchconfirm' ).then( function ( opened ) { - opened.then( function ( closing ) { - closing.then( - function ( data ) { - if ( data.action === 'switch' ) { - // Get Wikitext from the DOM - target.serialize( - target.docToSave || - ve.dm.converter.getDomFromModel( - target.surface.getModel().getDocument() - ), - target.submitWithSaveFields.bind( - target, - { wpDiff: 1, veswitched: 1 } - ) - ); - } else if ( data.action === 'discard' ) { - target.submitting = true; - window.location.href = target.viewUri.clone().extend( { - action: 'edit', - veswitched: 1 - } ).toString(); - } - }, - function () { - // Undo the opacity change - $documentNode.css( 'opacity', 1 ); - } - ); - } ); - } ); + this.surface.getDialogs().openWindow( 'wikitextswitchconfirm', { target: this } ); }; /** @@ -1744,3 +1709,30 @@ return message; } }; + +/** + * Switches to the wikitext editor, either keeping (default) or discarding changes. + * + * @param {boolean} [discardChanges] Whether to discard changes or not. + */ +ve.init.mw.ViewPageTarget.prototype.switchToWikitextEditor = function ( discardChanges ) { + if ( discardChanges ) { + this.submitting = true; + window.location.href = this.viewUri.clone().extend( { + action: 'edit', + veswitched: 1 + } ).toString(); + } else { + this.serialize( + this.docToSave || ve.dm.converter.getDomFromModel( this.surface.getModel().getDocument() ), + ve.bind( this.submitWithSaveFields, this, { wpDiff: 1, veswitched: 1 } ) + ); + } +}; + +/** + * Resets the document opacity when we've decided to cancel switching to the wikitext editor. + */ +ve.init.mw.ViewPageTarget.prototype.resetDocumentOpacity = function () { + this.surface.getView().getDocument().getDocumentNode().$element.css( 'opacity', 1 ); +}; diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js index d6b06b2..7606ae0 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js @@ -63,9 +63,22 @@ * @inheritdoc */ ve.ui.MWWikitextSwitchConfirmDialog.prototype.getActionProcess = function ( action ) { - if ( action === 'switch' || action === 'discard' ) { + if ( action === 'switch' ) { + return new OO.ui.Process( function () { + this.getActions().setAbilities( { cancel: false, discard: false } ); + this.getActions().get()[1].pushPending(); + this.target.switchToWikitextEditor( false ); + }, this ); + } else if ( action === 'discard' ) { + return new OO.ui.Process( function () { + this.getActions().setAbilities( { cancel: false, switch: false } ); + this.getActions().get()[2].pushPending(); + this.target.switchToWikitextEditor( true ); + }, this ); + } else if ( action === 'cancel' ) { return new OO.ui.Process( function () { this.close( { action: action } ); + this.target.resetDocumentOpacity(); }, this ); } @@ -75,6 +88,16 @@ /** * @inheritdoc + **/ +ve.ui.MWWikitextSwitchConfirmDialog.prototype.setup = function ( data ) { + this.target = data.target; + + // Parent method + return ve.ui.MWWikitextSwitchConfirmDialog.super.prototype.setup.call( this, data ); +}; + +/** + * @inheritdoc */ ve.ui.MWWikitextSwitchConfirmDialog.prototype.getTeardownProcess = function ( data ) { data = data || {}; -- To view, visit https://gerrit.wikimedia.org/r/144505 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I65b5de4a1666a81b157a71f6fec490007689eb44 Gerrit-PatchSet: 12 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Alex Monk <kren...@wikimedia.org> Gerrit-Reviewer: Alex Monk <kren...@wikimedia.org> Gerrit-Reviewer: Catrope <roan.katt...@gmail.com> Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: Trevor Parscal <tpars...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits