Alex Monk has uploaded a new change for review.

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

Change subject: Swap from using native confirm() to using an OOUI dialog when 
cancelling
......................................................................

Swap from using native confirm() to using an OOUI dialog when cancelling

Bug: 50955
Change-Id: I98f9a03d780556b360b57c018c05a27cc1b3862e
---
M VisualEditor.php
M modules/ve-mw/i18n/en.json
M modules/ve-mw/i18n/qqq.json
M modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
A modules/ve-mw/ui/dialogs/ve.ui.MWConfirmationDialog.js
5 files changed, 178 insertions(+), 45 deletions(-)


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

diff --git a/VisualEditor.php b/VisualEditor.php
index 520951e..e24ac03 100644
--- a/VisualEditor.php
+++ b/VisualEditor.php
@@ -626,6 +626,7 @@
                        'modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js',
                        'modules/ve-mw/ui/dialogs/ve.ui.MWBetaWelcomeDialog.js',
                        'modules/ve-mw/ui/dialogs/ve.ui.MWCommandHelpDialog.js',
+                       
'modules/ve-mw/ui/dialogs/ve.ui.MWConfirmationDialog.js',
 
                        'modules/ve-mw/ui/tools/ve.ui.MWEditModeTool.js',
                        
'modules/ve-mw/ui/tools/ve.ui.MWCommandHelpDialogTool.js',
@@ -660,6 +661,7 @@
                        'visualeditor-dialog-beta-welcome-action-continue',
                        'visualeditor-dialog-beta-welcome-content',
                        'visualeditor-dialog-beta-welcome-title',
+                       'visualeditor-dialog-confirm-title',
                        'visualeditor-diff-nochanges',
                        'visualeditor-differror',
                        'visualeditor-editconflict',
@@ -698,6 +700,8 @@
                        'visualeditor-toolbar-savedialog',
                        'visualeditor-toolbar-style-tooltip',
                        'visualeditor-viewpage-savewarning',
+                       'visualeditor-viewpage-savewarning-yes',
+                       'visualeditor-viewpage-savewarning-no',
                        'visualeditor-wikitext-warning-title',
                        'visualeditor-window-title',
                        'toc',
diff --git a/modules/ve-mw/i18n/en.json b/modules/ve-mw/i18n/en.json
index 20ea544..a237d6c 100644
--- a/modules/ve-mw/i18n/en.json
+++ b/modules/ve-mw/i18n/en.json
@@ -45,6 +45,7 @@
     "visualeditor-dialog-beta-welcome-content": "This is our new, easier way 
to edit. It's still in beta, which means you might find parts of the page you 
can't edit, or encounter issues that need to be fixed. We encourage you to 
review your changes, and we welcome reports about any issues you might 
encounter in using VisualEditor (click the \"{{int:visualeditor-help-tool}}\" 
button to submit feedback). You can keep using the wikitext editor by clicking 
the \"$1\" tab instead – unsaved changes will be lost.",
     "visualeditor-dialog-beta-welcome-title": "{{GENDER:$1|Welcome}} to 
VisualEditor",
     "visualeditor-dialog-citation-insert-citation": "Insert citation",
+    "visualeditor-dialog-confirm-title": "Confirm",
     "visualeditor-dialog-media-alttext-section": "Alternative text",
     "visualeditor-dialog-media-content-section": "Caption",
     "visualeditor-dialog-media-insert-button": "Insert media",
@@ -235,6 +236,8 @@
     "visualeditor-toolbar-style-tooltip": "Style text",
     "visualeditor-usernamespacepagelink": "Project:User namespace",
     "visualeditor-viewpage-savewarning": "Are you sure you want to go back to 
view mode without saving first?",
+    "visualeditor-viewpage-savewarning-yes": "Discard edits",
+    "visualeditor-viewpage-savewarning-no": "Continue editing",
     "visualeditor-wikitext-warning": "You are using VisualEditor - 
[[{{MediaWiki:visualeditor-wikitext-warning-link}}|wikitext]] does not work 
here. Click \"{{int:visualeditor-ca-editsource}}\" to edit the page in wikitext 
mode – unsaved changes will be lost.",
     "visualeditor-wikitext-warning-link": "Help:Wiki markup",
     "visualeditor-wikitext-warning-title": "Wikitext markup detected"
diff --git a/modules/ve-mw/i18n/qqq.json b/modules/ve-mw/i18n/qqq.json
index 356c415..7c6fb88 100644
--- a/modules/ve-mw/i18n/qqq.json
+++ b/modules/ve-mw/i18n/qqq.json
@@ -50,6 +50,7 @@
        "visualeditor-dialog-beta-welcome-content": "Text explaining 
VisualEditor is in beta.\n\nRefers to 
{{msg-mw|Visualeditor-help-tool}}.\n\nParameters:\n* $1 - {{msg-mw|Edit}}",
        "visualeditor-dialog-beta-welcome-title": "Title of the beta welcome 
dialog. Parameters:\n* $1 - username or empty string, for GENDER support",
        "visualeditor-dialog-citation-insert-citation": "Label for button that 
closes the citation insertion dialog and inserts the citation",
+       "visualeditor-dialog-confirm-title": "Title of the dialog used to 
confirm things such as whether the user wants to cancel VE or not.",
        "visualeditor-dialog-media-alttext-section": "Label for the image 
alternative text sub-section.",
        "visualeditor-dialog-media-content-section": "Label for the image 
content sub-section.\n{{Identical|Caption}}",
        "visualeditor-dialog-media-insert-button": "Used as label for the 
button.\n{{Identical|Insert media}}",
@@ -240,6 +241,8 @@
        "visualeditor-toolbar-style-tooltip": "Tooltip text for the text 
styling menu which has the following items:\n* 
{{msg-mw|Visualeditor-annotationbutton-bold-tooltip}}\n* 
{{msg-mw|Visualeditor-annotationbutton-code-tooltip}}\n* 
{{msg-mw|Visualeditor-annotationbutton-italic-tooltip}}\n* 
{{msg-mw|Visualeditor-annotationbutton-language-tooltip}}\n* 
{{msg-mw|Visualeditor-annotationbutton-link-tooltip}}\n* 
{{msg-mw|Visualeditor-annotationbutton-strikethrough-tooltip}}\n* 
{{msg-mw|Visualeditor-annotationbutton-subscript-tooltip}}\n* 
{{msg-mw|Visualeditor-annotationbutton-superscript-tooltip}}\n* 
{{msg-mw|Visualeditor-annotationbutton-underline-tooltip}}",
        "visualeditor-usernamespacepagelink": "Name of a page describing the 
user namespace (NS2) in this project.\n{{doc-important|Do not translate 
\"Project\"; it is automatically converted to the wiki's project namespace.}}",
        "visualeditor-viewpage-savewarning": "Text shown when the user tries to 
leave the editor without saving their changes",
+       "visualeditor-viewpage-savewarning-yes": "Text shown on the button 
which closes VE and discards changes when the user confirms that they want to 
leave the editor.",
+       "visualeditor-viewpage-savewarning-no": "Text shown on the button which 
does not do anything when the user decides that they do not want to leave the 
editor.",
        "visualeditor-wikitext-warning": "Contents of notification displayed 
when Wikitext has been detected.\n\nRefers to:\n* 
{{msg-mw|Visualeditor-wikitext-warning-link}}\n* 
{{msg-mw|Visualeditor-ca-editsource}}",
        "visualeditor-wikitext-warning-link": "Link to page describing what 
Wikitext is.\n\nUsed in:\n* {{msg-mw|Visualeditor-wikitext-warning}}.",
        "visualeditor-wikitext-warning-title": "Title of notification displayed 
when Wikitext has been detected"
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 9d4d55d..a5e1869 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
@@ -257,61 +257,78 @@
 };
 
 /**
- * Switch to view mode.
+ * Determines whether we want to switch to view mode or not (displaying a 
dialog if necessary)
+ * Then, if we do, actually switches to view mode.
  *
  * @method
  */
 ve.init.mw.ViewPageTarget.prototype.deactivate = function ( override ) {
        if ( override || ( this.active && !this.deactivating ) ) {
-               if (
-                       override ||
-                       !this.edited ||
-                       confirm( ve.msg( 'visualeditor-viewpage-savewarning' ) )
-               ) {
-                       this.deactivating = true;
-                       // User interface changes
-                       if ( this.elementsThatHadOurAccessKey ) {
-                               this.elementsThatHadOurAccessKey.attr( 
'accesskey', ve.msg( 'accesskey-save' ) );
-                       }
-                       this.restorePage();
-                       this.hideSpinner();
-                       this.showTableOfContents();
-
-                       if ( this.toolbarCancelButton ) {
-                               // If deactivate is called before a successful 
load, then
-                               // setupToolbarButtons has not been called yet 
and as such tearDownToolbarButtons
-                               // would throw an error when trying call 
methods on the button property (bug 46456)
-                               this.tearDownToolbarButtons();
-                               this.detachToolbarButtons();
-                       }
-
-                       // Check we got as far as setting up the surface
-                       if ( this.active ) {
-                               // If we got as far as setting up the surface, 
tear that down
-                               this.tearDownSurface();
-                       }
-
-                       // Show/restore components that are otherwise handled 
by tearDownSurface
-                       this.showPageContent();
-                       this.restorePageTitle();
-
-                       // If there is a load in progress, abort it
-                       if ( this.loading ) {
-                               this.loading.abort();
-                       }
-
-                       this.clearState();
-                       this.docToSave = null;
-                       this.initialEditSummary = '';
-
-                       this.deactivating = false;
-
-                       mw.hook( 've.deactivationComplete' ).fire( this.edited 
);
+               if ( override || !this.edited ) {
+                       this.cancel();
+               } else {
+                       this.surface.getDialogs().getWindow( 'confirm' 
).confirm(
+                               this.surface,
+                               ve.msg( 'visualeditor-viewpage-savewarning' ),
+                               ve.msg( 'visualeditor-viewpage-savewarning-yes' 
),
+                               ve.msg( 'visualeditor-viewpage-savewarning-no' )
+                       ).connect( this, {
+                               'yes': function () {
+                                       this.cancel();
+                               }
+                       } );
                }
        }
 };
 
 /**
+ * Switch to view mode
+ *
+ * @method
+ */
+ve.init.mw.ViewPageTarget.prototype.cancel = function () {
+       this.deactivating = true;
+       // User interface changes
+       if ( this.elementsThatHadOurAccessKey ) {
+               this.elementsThatHadOurAccessKey.attr( 'accesskey', ve.msg( 
'accesskey-save' ) );
+       }
+       this.restorePage();
+       this.hideSpinner();
+       this.showTableOfContents();
+
+       if ( this.toolbarCancelButton ) {
+               // If deactivate is called before a successful load, then
+               // setupToolbarButtons has not been called yet and as such 
tearDownToolbarButtons
+                       // would throw an error when trying call methods on the 
button property (bug 46456)
+               this.tearDownToolbarButtons();
+               this.detachToolbarButtons();
+       }
+
+       // Check we got as far as setting up the surface
+       if ( this.active ) {
+               // If we got as far as setting up the surface, tear that down
+               this.tearDownSurface();
+       }
+
+       // Show/restore components that are otherwise handled by tearDownSurface
+       this.showPageContent();
+       this.restorePageTitle();
+
+       // If there is a load in progress, abort it
+       if ( this.loading ) {
+               this.loading.abort();
+       }
+
+       this.clearState();
+       this.docToSave = null;
+       this.initialEditSummary = '';
+
+       this.deactivating = false;
+
+       mw.hook( 've.deactivationComplete' ).fire( this.edited );
+}
+
+/**
  * Handle failed DOM load event.
  *
  * @method
diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWConfirmationDialog.js 
b/modules/ve-mw/ui/dialogs/ve.ui.MWConfirmationDialog.js
new file mode 100644
index 0000000..cf57471
--- /dev/null
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWConfirmationDialog.js
@@ -0,0 +1,106 @@
+/*!
+ * VisualEditor UserInterface ConfirmationDialog class.
+ *
+ * @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+
+/**
+ * Dialog for showing a confirmation/warning message.
+ *
+ * @class
+ * @extends ve.ui.Dialog
+ *
+ * @constructor
+ * @param {Object} [config] Configuration options
+ */
+ve.ui.ConfirmationDialog = function VeUiConfirmationDialog( config ) {
+       // Configuration initialization
+       config = ve.extendObject( { 'size': 'small' }, config );
+
+       // Parent constructor
+       ve.ui.Dialog.call( this, config );
+
+       this.setupDeferred = $.Deferred();
+};
+
+/* Inheritance */
+
+OO.inheritClass( ve.ui.ConfirmationDialog, ve.ui.Dialog );
+
+/* Static Properties */
+
+ve.ui.ConfirmationDialog.static.name = 'confirm';
+
+ve.ui.ConfirmationDialog.static.title = OO.ui.deferMsg( 
'visualeditor-dialog-confirm-title' );
+
+/* Methods */
+
+/**
+ * @inheritdoc
+ */
+ve.ui.ConfirmationDialog.prototype.initialize = function () {
+       // Parent method
+       ve.ui.Dialog.prototype.initialize.call( this );
+
+       // Set up the layout
+       var contentLayout = new OO.ui.PanelLayout( {
+               '$': this.$,
+               'padded': true
+       } );
+
+       this.$container = this.$( '<div>' ).addClass( 
've-ui-confirmationDialog-container' );
+
+       // Make the buttons
+       contentLayout.$element.append( this.$container );
+       this.$body.append( contentLayout.$element );
+
+       this.noButton = new OO.ui.ButtonWidget( {
+               'flags': [ 'destructive' ]
+       } );
+
+       this.yesButton = new OO.ui.ButtonWidget( {
+               'flags': [ 'constructive' ]
+       } );
+
+       this.$foot.append(
+               this.noButton.$element,
+               this.yesButton.$element
+       );
+
+       // Done
+       this.setupDeferred.resolve();
+};
+
+/*
+ * Open a confirmation dialog.
+ *
+ * @param {ve.ui.Surface} surface
+ * @param {string} prompt
+ * @param {string} yesText
+ * @param {string} noText
+ * @chainable
+ */
+ve.ui.ConfirmationDialog.prototype.confirm = function ( surface, prompt, 
yesText, noText ) {
+       var confirmDialog = this;
+
+       this.connect( this, { 'yes': 'close', 'no': 'close' } );
+
+       this.setupDeferred.done( function () {
+               confirmDialog.$container.text( prompt );
+               confirmDialog.yesButton
+                       .setLabel( yesText )
+                       .connect( confirmDialog, { 'click': [ 'emit', 'yes' ] } 
);
+               confirmDialog.noButton
+                       .setLabel( noText )
+                       .connect( confirmDialog, { 'click': [ 'emit', 'no' ] } 
);
+       } );
+
+       this.open( surface.getModel().getFragment(), { 'dir': 
surface.getModel().getDocument().getLang() } );
+
+       return this;
+}
+
+/* Registration */
+
+ve.ui.windowFactory.register( ve.ui.ConfirmationDialog );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I98f9a03d780556b360b57c018c05a27cc1b3862e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <kren...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to