Alex Monk has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/247484

Change subject: Make the wikitext switch confirmation dialog indepedent of the 
target
......................................................................

Make the wikitext switch confirmation dialog indepedent of the target

I don't remember why I did this but it was horrible.
Might have been something to do with the window management system at the time.

Also change 'switch' to 'keep'.

Change-Id: I4cfb336fab77755f71c8c5bfefee10fcc131c2bd
---
M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
M modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js
2 files changed, 18 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/84/247484/1

diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js 
b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
index 4f95f68..b3129e2 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
@@ -757,6 +757,7 @@
  * @inheritdoc
  */
 ve.init.mw.DesktopArticleTarget.prototype.editSource = function () {
+       var target = this;
        if ( !this.getSurface().getModel().hasBeenModified() ) {
                this.switchToWikitextEditor( true, false );
                return;
@@ -764,7 +765,19 @@
 
        
this.getSurface().getView().getDocument().getDocumentNode().$element.css( 
'opacity', 0.5 );
 
-       this.getSurface().getDialogs().openWindow( 'wikitextswitchconfirm', { 
target: this } );
+       this.getSurface().getDialogs().openWindow( 'wikitextswitchconfirm' 
).done( function ( opened ) {
+               opened.done( function ( closing ) {
+                       closing.done( function ( data ) {
+                               if ( data && data.action === 'keep' ) {
+                                       target.switchToWikitextEditor( false, 
true );
+                               } else if ( data && data.action === 'discard' ) 
{
+                                       target.switchToWikitextEditor( true, 
true );
+                               } else { // cancel
+                                       target.resetDocumentOpacity();
+                               }
+                       } );
+               } );
+       } );
 };
 
 /**
diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js 
b/modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js
index 226301b..2bf9f6d 100644
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWWikitextSwitchConfirmDialog.js
@@ -41,12 +41,11 @@
 
 ve.ui.MWWikitextSwitchConfirmDialog.static.actions = [
        {
-               action: 'cancel',
                label: OO.ui.deferMsg( 
'visualeditor-mweditmodesource-warning-cancel' ),
                flags: [ 'safe', 'back' ]
        },
        {
-               action: 'switch',
+               action: 'keep',
                label: OO.ui.deferMsg( 
'visualeditor-mweditmodesource-warning-switch' ),
                flags: [ 'progressive', 'primary' ]
        },
@@ -63,53 +62,22 @@
  * @inheritdoc
  */
 ve.ui.MWWikitextSwitchConfirmDialog.prototype.getActionProcess = function ( 
action ) {
-       if ( action === 'switch' ) {
+       if ( action === 'keep' ) {
                return new OO.ui.Process( function () {
                        this.getActions().setAbilities( { cancel: false, 
discard: false } );
                        this.getActions().get()[ 1 ].pushPending();
-                       this.target.switchToWikitextEditor( false, true );
+                       this.close( { action: 'keep' } );
                }, 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, true );
-               }, this );
-       } else if ( action === 'cancel' ) {
-               return new OO.ui.Process( function () {
-                       this.close( { action: action } );
-                       this.target.resetDocumentOpacity();
+                       this.close( { action: 'discard' } );
                }, this );
        }
 
        // Parent method
        return 
ve.ui.MWWikitextSwitchConfirmDialog.super.prototype.getActionProcess.call( 
this, action );
-};
-
-/**
- * @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 || {};
-       return 
ve.ui.MWWikitextSwitchConfirmDialog.super.prototype.getTeardownProcess.call( 
this, data )
-               .first( function () {
-                       // EVIL HACK - we shouldn't be reaching into the 
manager for these promises
-                       if ( data.action === 'switch' || data.action === 
'discard' ) {
-                               this.manager.closing.resolve( data );
-                       } else {
-                               this.manager.closing.reject( data );
-                       }
-               }, this );
 };
 
 /* Registration */

-- 
To view, visit https://gerrit.wikimedia.org/r/247484
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4cfb336fab77755f71c8c5bfefee10fcc131c2bd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to