MWSaveDialog: Make a FragmentDialog now that's available

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

Change-Id: I254b71f252adce064b9c2d2bf2cb6c8d0018e31f
This commit is contained in:
Ed Sanders 2015-07-31 13:15:31 +01:00 committed by Jforrester
parent e9b7f4c029
commit dc71b4849b
3 changed files with 51 additions and 34 deletions

View file

@ -68,7 +68,6 @@ ve.init.mw.DesktopArticleTarget = function VeInitMwDesktopArticleTarget( config
// Events // Events
this.connect( this, { this.connect( this, {
saveBegin: 'showSaveDialog',
save: 'onSave', save: 'onSave',
saveErrorEmpty: 'onSaveErrorEmpty', saveErrorEmpty: 'onSaveErrorEmpty',
saveErrorSpamBlacklist: 'onSaveErrorSpamBlacklist', saveErrorSpamBlacklist: 'onSaveErrorSpamBlacklist',
@ -1038,6 +1037,7 @@ ve.init.mw.DesktopArticleTarget.prototype.onSaveDialogResolveConflict = function
/** /**
* Get save form fields from the save dialog form. * Get save form fields from the save dialog form.
*
* @returns {Object} Form data for submission to the MediaWiki action=edit UI * @returns {Object} Form data for submission to the MediaWiki action=edit UI
*/ */
ve.init.mw.DesktopArticleTarget.prototype.getSaveFields = function () { ve.init.mw.DesktopArticleTarget.prototype.getSaveFields = function () {
@ -1064,6 +1064,7 @@ ve.init.mw.DesktopArticleTarget.prototype.getSaveFields = function () {
/** /**
* Invoke #submit with the data from #getSaveFields * Invoke #submit with the data from #getSaveFields
*
* @param {Object} fields Fields to add in addition to those from #getSaveFields * @param {Object} fields Fields to add in addition to those from #getSaveFields
* @param {string} wikitext Wikitext to submit * @param {string} wikitext Wikitext to submit
* @returns {boolean} Whether submission was started * @returns {boolean} Whether submission was started
@ -1074,10 +1075,12 @@ ve.init.mw.DesktopArticleTarget.prototype.submitWithSaveFields = function ( fiel
/** /**
* Get edit API options from the save dialog form. * Get edit API options from the save dialog form.
*
* @returns {Object} Save options for submission to the MediaWiki API * @returns {Object} Save options for submission to the MediaWiki API
*/ */
ve.init.mw.DesktopArticleTarget.prototype.getSaveOptions = function () { ve.init.mw.DesktopArticleTarget.prototype.getSaveOptions = function () {
var key, options = this.getSaveFields(), var key,
options = this.getSaveFields(),
fieldMap = { fieldMap = {
wpSummary: 'summary', wpSummary: 'summary',
wpMinoredit: 'minor', wpMinoredit: 'minor',
@ -1191,28 +1194,23 @@ ve.init.mw.DesktopArticleTarget.prototype.attachToolbarSaveButton = function ()
}; };
/** /**
* Show the save dialog. * @inheritdoc
*
* @fires saveWorkflowBegin * @fires saveWorkflowBegin
*/ */
ve.init.mw.DesktopArticleTarget.prototype.showSaveDialog = function () { ve.init.mw.DesktopArticleTarget.prototype.showSaveDialog = function () {
var target = this; var target = this,
this.emit( 'saveWorkflowBegin' ); windowAction = ve.ui.actionFactory.create( 'window', this.getSurface() );
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 this.emit( 'saveWorkflowBegin' );
if ( currentWindow ) {
currentWindow.close();
}
// Preload the serialization // Preload the serialization
if ( !target.docToSave ) { if ( !this.docToSave ) {
target.docToSave = target.getSurface().getDom(); this.docToSave = this.getSurface().getDom();
} }
target.prepareCacheKey( target.docToSave ); this.prepareCacheKey( this.docToSave );
// Connect events to save dialog
this.getSurface().getDialogs().getWindow( 'mwSave' ).done( function ( win ) {
if ( !target.saveDialog ) { if ( !target.saveDialog ) {
target.saveDialog = win; target.saveDialog = win;
@ -1221,21 +1219,19 @@ ve.init.mw.DesktopArticleTarget.prototype.showSaveDialog = function () {
save: 'saveDocument', save: 'saveDocument',
review: 'onSaveDialogReview', review: 'onSaveDialogReview',
resolve: 'onSaveDialogResolveConflict', 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( // Open the dialog
target.saveDialog, windowAction.open( 'mwSave', {
{ dir: target.getSurface().getModel().getDocument().getLang() } target: this,
).done( function ( opened ) { editSummary: this.initialEditSummary,
// Call onSaveDialogClose() when the save dialog starts closing $checkboxes: this.$checkboxes
opened.always( target.onSaveDialogClose.bind( target ) );
} );
} ); } );
}; };
/** /**
@ -1258,7 +1254,6 @@ ve.init.mw.DesktopArticleTarget.prototype.onSaveDialogClose = function () {
clear(); clear();
} }
this.getSurface().getModel().setSelection( this.origSelection );
this.emit( 'saveWorkflowEnd' ); this.emit( 'saveWorkflowEnd' );
}; };

View file

@ -1405,10 +1405,17 @@ ve.init.mw.Target.prototype.updateToolbarSaveButtonState = function () {
*/ */
ve.init.mw.Target.prototype.onToolbarSaveButtonClick = function () { ve.init.mw.Target.prototype.onToolbarSaveButtonClick = function () {
if ( this.edited || this.restoring ) { if ( this.edited || this.restoring ) {
this.showSaveDialog();
this.emit( 'saveBegin' ); 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. * Move the cursor in the editor to section specified by this.section.
* Do nothing if this.section is undefined. * Do nothing if this.section is undefined.

View file

@ -12,7 +12,7 @@
* noted otherwise. * noted otherwise.
* *
* @class * @class
* @extends OO.ui.ProcessDialog * @extends ve.ui.FragmentDialog
* *
* @constructor * @constructor
* @param {Object} [config] Config options * @param {Object} [config] Config options
@ -26,11 +26,12 @@ ve.ui.MWSaveDialog = function VeUiMWSaveDialog( config ) {
this.restoring = false; this.restoring = false;
this.messages = {}; this.messages = {};
this.setupDeferred = $.Deferred(); this.setupDeferred = $.Deferred();
this.target = null;
}; };
/* Inheritance */ /* Inheritance */
OO.inheritClass( ve.ui.MWSaveDialog, OO.ui.ProcessDialog ); OO.inheritClass( ve.ui.MWSaveDialog, ve.ui.FragmentDialog );
/* Static Properties */ /* Static Properties */
@ -470,6 +471,9 @@ ve.ui.MWSaveDialog.prototype.initialize = function () {
ve.ui.MWSaveDialog.prototype.getSetupProcess = function ( data ) { ve.ui.MWSaveDialog.prototype.getSetupProcess = function ( data ) {
return ve.ui.MWSaveDialog.super.prototype.getSetupProcess.call( this, data ) return ve.ui.MWSaveDialog.super.prototype.getSetupProcess.call( this, data )
.next( function () { .next( function () {
this.target = data.target;
this.setEditSummary( data.editSummary );
this.setupCheckboxes( data.$checkboxes );
// Old messages should not persist // Old messages should not persist
this.clearAllMessages(); this.clearAllMessages();
this.swapPanel( 'save' ); this.swapPanel( 'save' );
@ -498,6 +502,17 @@ ve.ui.MWSaveDialog.prototype.getReadyProcess = function ( data ) {
}, this ); }, this );
}; };
/**
* @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 * @inheritdoc
*/ */