Esanders has uploaded a new change for review.

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

Change subject: Save dialog improvments
......................................................................

Save dialog improvments

* Make save a FragmentDialog and open with WindowActions so
  the selection is restored automatically.
* Pass in some information in setup data.

Change-Id: I254b71f252adce064b9c2d2bf2cb6c8d0018e31f
---
M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
M modules/ve-mw/init/ve.init.mw.Target.js
M modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js
3 files changed, 51 insertions(+), 34 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/76/228276/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 1711ed2..53a2827 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js
@@ -68,7 +68,6 @@
 
        // Events
        this.connect( this, {
-               saveBegin: 'showSaveDialog',
                save: 'onSave',
                saveErrorEmpty: 'onSaveErrorEmpty',
                saveErrorSpamBlacklist: 'onSaveErrorSpamBlacklist',
@@ -1038,6 +1037,7 @@
 
 /**
  * Get save form fields from the save dialog form.
+ *
  * @returns {Object} Form data for submission to the MediaWiki action=edit UI
  */
 ve.init.mw.DesktopArticleTarget.prototype.getSaveFields = function () {
@@ -1064,6 +1064,7 @@
 
 /**
  * Invoke #submit with the data from #getSaveFields
+ *
  * @param {Object} fields Fields to add in addition to those from 
#getSaveFields
  * @param {string} wikitext Wikitext to submit
  * @returns {boolean} Whether submission was started
@@ -1074,10 +1075,12 @@
 
 /**
  * Get edit API options from the save dialog form.
+ *
  * @returns {Object} Save options for submission to the MediaWiki API
  */
 ve.init.mw.DesktopArticleTarget.prototype.getSaveOptions = function () {
-       var key, options = this.getSaveFields(),
+       var key,
+               options = this.getSaveFields(),
                fieldMap = {
                        wpSummary: 'summary',
                        wpMinoredit: 'minor',
@@ -1191,28 +1194,23 @@
 };
 
 /**
- * Show the save dialog.
- *
+ * @inheritdoc
  * @fires saveWorkflowBegin
  */
 ve.init.mw.DesktopArticleTarget.prototype.showSaveDialog = function () {
-       var target = this;
+       var target = this,
+               windowAction = ve.ui.actionFactory.create( 'window', 
this.getSurface() );
+
        this.emit( 'saveWorkflowBegin' );
+
+       // Preload the serialization
+       if ( !this.docToSave ) {
+               this.docToSave = this.getSurface().getDom();
+       }
+       this.prepareCacheKey( this.docToSave );
+
+       // Connect events to save dialog
        this.getSurface().getDialogs().getWindow( 'mwSave' ).done( function ( 
win ) {
-               var currentWindow = 
target.getSurface().getContext().getInspectors().getCurrentWindow();
-               target.origSelection = 
target.getSurface().getModel().getSelection();
-
-               // Make sure any open inspectors are closed
-               if ( currentWindow ) {
-                       currentWindow.close();
-               }
-
-               // Preload the serialization
-               if ( !target.docToSave ) {
-                       target.docToSave = target.getSurface().getDom();
-               }
-               target.prepareCacheKey( target.docToSave );
-
                if ( !target.saveDialog ) {
                        target.saveDialog = win;
 
@@ -1221,21 +1219,19 @@
                                save: 'saveDocument',
                                review: 'onSaveDialogReview',
                                resolve: 'onSaveDialogResolveConflict',
-                               retry: 'onSaveRetry'
+                               retry: 'onSaveRetry',
+                               close: 'onSaveDialogClose'
                        } );
-                       // Setup edit summary and checkboxes
-                       target.saveDialog.setEditSummary( 
target.initialEditSummary );
-                       target.saveDialog.setupCheckboxes( target.$checkboxes );
                }
-
-               target.getSurface().getDialogs().openWindow(
-                       target.saveDialog,
-                       { dir: 
target.getSurface().getModel().getDocument().getLang() }
-               ).done( function ( opened ) {
-                       // Call onSaveDialogClose() when the save dialog starts 
closing
-                       opened.always( target.onSaveDialogClose.bind( target ) 
);
-               } );
        } );
+
+       // Open the dialog
+       windowAction.open( 'mwSave', {
+               target: this,
+               editSummary: this.initialEditSummary,
+               $checkboxes: this.$checkboxes
+       } );
+
 };
 
 /**
@@ -1258,7 +1254,6 @@
                clear();
        }
 
-       this.getSurface().getModel().setSelection( this.origSelection );
        this.emit( 'saveWorkflowEnd' );
 };
 
diff --git a/modules/ve-mw/init/ve.init.mw.Target.js 
b/modules/ve-mw/init/ve.init.mw.Target.js
index 8cca347..f675744 100644
--- a/modules/ve-mw/init/ve.init.mw.Target.js
+++ b/modules/ve-mw/init/ve.init.mw.Target.js
@@ -1405,11 +1405,18 @@
  */
 ve.init.mw.Target.prototype.onToolbarSaveButtonClick = function () {
        if ( this.edited || this.restoring ) {
+               this.showSaveDialog();
                this.emit( 'saveBegin' );
        }
 };
 
 /**
+ * Show a save dialog
+ */
+ve.init.mw.Target.prototype.showSaveDialog = function () {
+};
+
+/**
  * Move the cursor in the editor to section specified by this.section.
  * Do nothing if this.section is undefined.
  *
diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js 
b/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js
index 8ce1118..6cce409 100644
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js
@@ -12,7 +12,7 @@
  * noted otherwise.
  *
  * @class
- * @extends OO.ui.ProcessDialog
+ * @extends ve.ui.FragmentDialog
  *
  * @constructor
  * @param {Object} [config] Config options
@@ -26,11 +26,12 @@
        this.restoring = false;
        this.messages = {};
        this.setupDeferred = $.Deferred();
+       this.target = null;
 };
 
 /* Inheritance */
 
-OO.inheritClass( ve.ui.MWSaveDialog, OO.ui.ProcessDialog );
+OO.inheritClass( ve.ui.MWSaveDialog, ve.ui.FragmentDialog );
 
 /* Static Properties */
 
@@ -470,6 +471,9 @@
 ve.ui.MWSaveDialog.prototype.getSetupProcess = function ( data ) {
        return ve.ui.MWSaveDialog.super.prototype.getSetupProcess.call( this, 
data )
                .next( function () {
+                       this.target = data.target;
+                       this.setEditSummary( data.editSummary );
+                       this.setupCheckboxes( data.$checkboxes );
                        // Old messages should not persist
                        this.clearAllMessages();
                        this.swapPanel( 'save' );
@@ -501,6 +505,17 @@
 /**
  * @inheritdoc
  */
+ve.ui.MWSaveDialog.prototype.getTeardownProcess = function ( data ) {
+       return ve.ui.MWSaveDialog.super.prototype.getTeardownProcess.call( 
this, data )
+               .next( function () {
+                       this.emit( 'close' );
+                       this.target = null;
+               }, this );
+};
+
+/**
+ * @inheritdoc
+ */
 ve.ui.MWSaveDialog.prototype.getActionProcess = function ( action ) {
        if ( action === 'save' ) {
                return new OO.ui.Process( function () {

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

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

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

Reply via email to