2013-10-07 10:01:43 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWSaveDialog class.
|
|
|
|
*
|
2015-01-08 23:54:03 +00:00
|
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
2013-10-07 10:01:43 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-07-14 21:32:49 +00:00
|
|
|
* Dialog for saving MediaWiki pages.
|
2013-10-07 10:01:43 +00:00
|
|
|
*
|
2013-11-14 23:14:16 +00:00
|
|
|
* Note that most methods are not safe to call before the dialog has initialized, except where
|
|
|
|
* noted otherwise.
|
|
|
|
*
|
2013-10-07 10:01:43 +00:00
|
|
|
* @class
|
2014-07-14 21:32:49 +00:00
|
|
|
* @extends OO.ui.ProcessDialog
|
2013-10-07 10:01:43 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Config options
|
|
|
|
*/
|
2014-08-21 00:50:54 +00:00
|
|
|
ve.ui.MWSaveDialog = function VeUiMWSaveDialog( config ) {
|
2013-10-07 10:01:43 +00:00
|
|
|
// Parent constructor
|
2014-08-21 00:50:54 +00:00
|
|
|
ve.ui.MWSaveDialog.super.call( this, config );
|
2013-10-07 10:01:43 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.editSummaryByteLimit = 255;
|
|
|
|
this.restoring = false;
|
|
|
|
this.messages = {};
|
2013-11-14 23:14:16 +00:00
|
|
|
this.setupDeferred = $.Deferred();
|
2013-10-07 10:01:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
OO.inheritClass( ve.ui.MWSaveDialog, OO.ui.ProcessDialog );
|
2013-10-07 10:01:43 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWSaveDialog.static.name = 'mwSave';
|
|
|
|
|
2014-02-12 21:45:37 +00:00
|
|
|
ve.ui.MWSaveDialog.static.title =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-savedialog-title-save' );
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
ve.ui.MWSaveDialog.static.actions = [
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'save',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-apply' ),
|
|
|
|
flags: [ 'primary', 'constructive' ],
|
2014-12-15 21:06:09 +00:00
|
|
|
modes: 'save',
|
|
|
|
accessKey: 's'
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-09-11 18:52:21 +00:00
|
|
|
label: OO.ui.deferMsg( 'visualeditor-savedialog-label-resume-editing' ),
|
2014-08-22 20:50:48 +00:00
|
|
|
flags: 'safe',
|
2014-08-27 01:04:22 +00:00
|
|
|
modes: [ 'save', 'conflict' ]
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'review',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-savedialog-label-review' ),
|
|
|
|
modes: 'save'
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'approve',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-savedialog-label-review-good' ),
|
2014-12-11 22:49:51 +00:00
|
|
|
flags: [ 'progressive', 'primary' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
modes: 'review'
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'resolve',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-savedialog-label-resolve-conflict' ),
|
|
|
|
flags: [ 'primary', 'constructive' ],
|
|
|
|
modes: 'conflict'
|
2014-07-14 21:32:49 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2013-11-14 23:14:16 +00:00
|
|
|
/* Events */
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2013-11-14 23:14:16 +00:00
|
|
|
/**
|
|
|
|
* @event save
|
2014-05-28 22:05:17 +00:00
|
|
|
* @param {jQuery.Deferred} saveDeferred Deferred object to resolve/reject when the save
|
|
|
|
* succeeds/fails.
|
2013-11-14 23:14:16 +00:00
|
|
|
* Emitted when the user clicks the save button
|
|
|
|
*/
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2013-11-14 23:14:16 +00:00
|
|
|
/**
|
|
|
|
* @event review
|
|
|
|
* Emitted when the user clicks the review changes button
|
|
|
|
*/
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2013-11-14 23:14:16 +00:00
|
|
|
/**
|
|
|
|
* @event resolve
|
|
|
|
* Emitted when the user clicks the resolve conflict button
|
|
|
|
*/
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2014-10-30 00:36:02 +00:00
|
|
|
/**
|
|
|
|
* @event retry
|
|
|
|
* Emitted when the user clicks the retry/continue save button after an error.
|
|
|
|
*/
|
|
|
|
|
2013-11-14 23:14:16 +00:00
|
|
|
/* Methods */
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
2013-11-14 23:14:16 +00:00
|
|
|
* Set review content and show review panel.
|
2013-11-05 00:29:50 +00:00
|
|
|
*
|
|
|
|
* @param {string} content Diff HTML or wikitext
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.setDiffAndReview = function ( content ) {
|
|
|
|
this.$reviewViewer.empty().append( content );
|
2014-08-22 20:50:48 +00:00
|
|
|
this.actions.setAbilities( { approve: true } );
|
2014-04-18 20:32:25 +00:00
|
|
|
this.popPending();
|
2013-11-05 00:29:50 +00:00
|
|
|
this.swapPanel( 'review' );
|
|
|
|
};
|
|
|
|
|
2014-11-05 23:23:48 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.pushPending = function () {
|
|
|
|
this.getActions().setAbilities( { review: false } );
|
|
|
|
return ve.ui.MWSaveDialog.super.prototype.pushPending.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.popPending = function () {
|
|
|
|
var ret = ve.ui.MWSaveDialog.super.prototype.popPending.call( this );
|
|
|
|
if ( !this.isPending() ) {
|
|
|
|
this.getActions().setAbilities( { review: true } );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
2013-11-14 23:14:16 +00:00
|
|
|
/**
|
|
|
|
* Clear the diff displayed in the review panel, if any.
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.clearDiff = function () {
|
|
|
|
this.$reviewViewer.empty();
|
|
|
|
};
|
|
|
|
|
2013-10-07 10:01:43 +00:00
|
|
|
/**
|
|
|
|
* Swap state in the save dialog.
|
|
|
|
*
|
|
|
|
* @param {string} panel One of 'save', 'review', 'conflict' or 'nochanges'
|
|
|
|
* @returns {jQuery} The now active panel
|
|
|
|
* @throws {Error} Unknown saveDialog panel
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.swapPanel = function ( panel ) {
|
2014-02-10 18:33:13 +00:00
|
|
|
var currentEditSummaryWikitext,
|
|
|
|
dialog = this,
|
2013-10-07 10:01:43 +00:00
|
|
|
panelObj = dialog[panel + 'Panel'];
|
|
|
|
|
|
|
|
if ( ve.indexOf( panel, [ 'save', 'review', 'conflict', 'nochanges' ] ) === -1 ) {
|
|
|
|
throw new Error( 'Unknown saveDialog panel: ' + panel );
|
|
|
|
}
|
|
|
|
|
2014-06-12 00:35:46 +00:00
|
|
|
this.setSize( 'medium' );
|
|
|
|
|
2013-10-07 10:01:43 +00:00
|
|
|
// Update the window title
|
2014-07-28 12:08:39 +00:00
|
|
|
// The following messages can be used here:
|
|
|
|
// visualeditor-savedialog-title-save
|
|
|
|
// visualeditor-savedialog-title-reviews
|
|
|
|
// visualeditor-savedialog-title-conflict
|
|
|
|
// visualeditor-savedialog-title-nochanges
|
2014-07-14 21:32:49 +00:00
|
|
|
this.title.setLabel( ve.msg( 'visualeditor-savedialog-title-' + panel ) );
|
2013-10-07 10:01:43 +00:00
|
|
|
|
|
|
|
// Reset save button if we disabled it for e.g. unrecoverable spam error
|
2014-08-22 20:50:48 +00:00
|
|
|
this.actions.setAbilities( { save: true } );
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2013-12-06 02:34:44 +00:00
|
|
|
switch ( panel ) {
|
2013-10-07 10:01:43 +00:00
|
|
|
case 'save':
|
2014-07-14 21:32:49 +00:00
|
|
|
this.actions.setMode( 'save' );
|
2014-06-06 13:18:22 +00:00
|
|
|
// HACK: FF needs *another* defer
|
2013-10-17 13:29:03 +00:00
|
|
|
setTimeout( function () {
|
2014-10-08 20:54:16 +00:00
|
|
|
// FIXME we need to add features to OO.ui.TextInputWidget so we don't need to access .$input
|
2014-11-11 19:52:36 +00:00
|
|
|
ve.selectEnd( dialog.editSummaryInput.$input[0] );
|
2013-10-17 13:29:03 +00:00
|
|
|
} );
|
2013-10-07 10:01:43 +00:00
|
|
|
break;
|
|
|
|
case 'conflict':
|
2014-07-14 21:32:49 +00:00
|
|
|
this.actions
|
2014-08-22 20:50:48 +00:00
|
|
|
.setAbilities( { save: false } )
|
2014-08-27 01:04:22 +00:00
|
|
|
.setMode( 'conflict' );
|
2013-10-07 10:01:43 +00:00
|
|
|
break;
|
|
|
|
case 'review':
|
2015-01-17 00:04:05 +00:00
|
|
|
this.setSize( 'larger' );
|
2014-02-10 18:33:13 +00:00
|
|
|
currentEditSummaryWikitext = this.editSummaryInput.getValue();
|
|
|
|
if ( this.lastEditSummaryWikitext === undefined || this.lastEditSummaryWikitext !== currentEditSummaryWikitext ) {
|
|
|
|
if ( this.editSummaryXhr ) {
|
|
|
|
this.editSummaryXhr.abort();
|
|
|
|
}
|
|
|
|
this.lastEditSummaryWikitext = currentEditSummaryWikitext;
|
2014-08-03 02:12:25 +00:00
|
|
|
this.$reviewEditSummary.empty();
|
|
|
|
|
|
|
|
if ( !currentEditSummaryWikitext || currentEditSummaryWikitext.trim() === '' ) {
|
|
|
|
// Don't bother with an API request for an empty summary
|
2015-01-29 23:09:47 +00:00
|
|
|
this.$reviewEditSummary.parent().addClass( 'oo-ui-element-hidden' );
|
2014-08-03 02:12:25 +00:00
|
|
|
} else {
|
2015-01-29 23:09:47 +00:00
|
|
|
this.$reviewEditSummary.parent()
|
|
|
|
.removeClass( 'oo-ui-element-hidden' )
|
|
|
|
.addClass( 'mw-ajax-loader' );
|
2014-08-03 02:12:25 +00:00
|
|
|
this.editSummaryXhr = new mw.Api().post( {
|
|
|
|
action: 'parse',
|
|
|
|
summary: currentEditSummaryWikitext
|
|
|
|
} ).done( function ( result ) {
|
|
|
|
if ( result.parse.parsedsummary['*'] === '' ) {
|
2015-01-29 23:09:47 +00:00
|
|
|
dialog.$reviewEditSummary.parent().addClass( 'oo-ui-element-hidden' );
|
2014-08-03 02:12:25 +00:00
|
|
|
} else {
|
|
|
|
dialog.$reviewEditSummary.html( ve.msg( 'parentheses', result.parse.parsedsummary['*'] ) );
|
|
|
|
}
|
|
|
|
} ).fail( function () {
|
2015-01-29 23:09:47 +00:00
|
|
|
dialog.$reviewEditSummary.parent().addClass( 'oo-ui-element-hidden' );
|
2014-08-03 02:12:25 +00:00
|
|
|
} ).always( function () {
|
|
|
|
dialog.$reviewEditSummary.parent().removeClass( 'mw-ajax-loader' );
|
|
|
|
} );
|
|
|
|
}
|
2014-02-10 18:33:13 +00:00
|
|
|
}
|
2013-10-07 10:01:43 +00:00
|
|
|
/* falls through */
|
|
|
|
case 'nochanges':
|
2014-07-14 21:32:49 +00:00
|
|
|
this.actions.setMode( 'review' );
|
2013-10-07 10:01:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show the target panel
|
2014-07-14 21:32:49 +00:00
|
|
|
this.panels.setItem( panelObj );
|
2013-10-07 10:01:43 +00:00
|
|
|
|
|
|
|
mw.hook( 've.saveDialog.stateChanged' ).fire();
|
|
|
|
|
|
|
|
return dialog;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a message in the save dialog.
|
|
|
|
*
|
|
|
|
* @param {string} name Message's unique name
|
|
|
|
* @param {string|jQuery|Array} message Message content (string of HTML, jQuery object or array of
|
|
|
|
* Node objects)
|
|
|
|
* @param {Object} [options]
|
|
|
|
* @param {boolean} [options.wrap="warning"] Whether to wrap the message in a paragraph and if
|
|
|
|
* so, how. One of "warning", "error" or false.
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.showMessage = function ( name, message, options ) {
|
|
|
|
var $message;
|
|
|
|
if ( !this.messages[name] ) {
|
|
|
|
options = options || {};
|
|
|
|
if ( options.wrap === undefined ) {
|
|
|
|
options.wrap = 'warning';
|
|
|
|
}
|
2013-11-01 19:45:59 +00:00
|
|
|
$message = this.$( '<div class="ve-ui-mwSaveDialog-message"></div>' );
|
2013-10-07 10:01:43 +00:00
|
|
|
if ( options.wrap !== false ) {
|
2015-01-31 00:41:37 +00:00
|
|
|
$message.append( this.$( '<p>' ).append(
|
2014-05-15 16:12:43 +00:00
|
|
|
// visualeditor-savedialog-label-error
|
|
|
|
// visualeditor-savedialog-label-warning
|
2013-11-01 19:45:59 +00:00
|
|
|
this.$( '<strong>' ).text( mw.msg( 'visualeditor-savedialog-label-' + options.wrap ) ),
|
2013-10-07 10:01:43 +00:00
|
|
|
document.createTextNode( mw.msg( 'colon-separator' ) ),
|
|
|
|
message
|
|
|
|
) );
|
|
|
|
} else {
|
|
|
|
$message.append( message );
|
|
|
|
}
|
|
|
|
this.$saveMessages.append( $message );
|
|
|
|
|
|
|
|
this.messages[name] = $message;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a message from the save dialog.
|
|
|
|
* @param {string} name Message's unique name
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.clearMessage = function ( name ) {
|
|
|
|
if ( this.messages[name] ) {
|
|
|
|
this.messages[name].remove();
|
|
|
|
delete this.messages[name];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all messages from the save dialog.
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.clearAllMessages = function () {
|
|
|
|
this.$saveMessages.empty();
|
|
|
|
this.messages = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the fields of the save dialog.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.reset = function () {
|
|
|
|
// Reset summary input
|
2014-10-08 20:14:53 +00:00
|
|
|
this.editSummaryInput.setValue( '' );
|
2013-10-07 10:01:43 +00:00
|
|
|
// Uncheck minoredit
|
|
|
|
this.$saveOptions.find( '.ve-ui-mwSaveDialog-checkboxes' )
|
|
|
|
.find( '#wpMinoredit' ).prop( 'checked', false );
|
|
|
|
// Clear the diff
|
|
|
|
this.$reviewViewer.empty();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-11-14 23:14:16 +00:00
|
|
|
* Initialize MediaWiki page specific checkboxes.
|
|
|
|
*
|
|
|
|
* This method is safe to call even when the dialog hasn't been initialized yet.
|
2013-10-07 10:01:43 +00:00
|
|
|
*
|
2013-11-15 21:31:40 +00:00
|
|
|
* @param {jQuery} $checkboxes jQuery collection of checkboxes
|
2013-10-07 10:01:43 +00:00
|
|
|
*/
|
2013-11-15 21:31:40 +00:00
|
|
|
ve.ui.MWSaveDialog.prototype.setupCheckboxes = function ( $checkboxes ) {
|
2014-12-16 21:14:01 +00:00
|
|
|
var dialog = this;
|
2013-11-14 23:14:16 +00:00
|
|
|
this.setupDeferred.done( function () {
|
2014-12-16 21:14:01 +00:00
|
|
|
dialog.$saveOptions.find( '.ve-ui-mwSaveDialog-checkboxes' )
|
|
|
|
.empty()
|
|
|
|
.append( $checkboxes )
|
2013-11-14 23:14:16 +00:00
|
|
|
.find( 'a' )
|
|
|
|
.attr( 'target', '_blank' )
|
|
|
|
.end()
|
2013-11-15 21:31:40 +00:00
|
|
|
.find( 'input' )
|
|
|
|
.prop( 'tabIndex', 0 );
|
2014-12-16 21:14:01 +00:00
|
|
|
} );
|
2013-11-14 23:14:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the edit summary prefilled in the save dialog.
|
|
|
|
*
|
|
|
|
* This method is safe to call even when the dialog hasn't been initialized yet.
|
|
|
|
*
|
|
|
|
* @param {string} summary Edit summary to prefill
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.setEditSummary = function ( summary ) {
|
2014-12-16 21:14:01 +00:00
|
|
|
var dialog = this;
|
2013-11-14 23:14:16 +00:00
|
|
|
this.setupDeferred.done( function () {
|
2014-12-16 21:14:01 +00:00
|
|
|
dialog.editSummaryInput.setValue( summary );
|
|
|
|
} );
|
2013-10-07 10:01:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-11-05 00:29:50 +00:00
|
|
|
* @inheritdoc
|
2013-10-07 10:01:43 +00:00
|
|
|
*/
|
2013-11-05 00:29:50 +00:00
|
|
|
ve.ui.MWSaveDialog.prototype.initialize = function () {
|
2014-12-16 21:14:01 +00:00
|
|
|
var saveAccessKey,
|
|
|
|
dialog = this;
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
// Parent method
|
2014-05-31 04:47:08 +00:00
|
|
|
ve.ui.MWSaveDialog.super.prototype.initialize.call( this );
|
2013-10-07 10:01:43 +00:00
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
// Properties
|
2014-08-22 20:50:48 +00:00
|
|
|
this.panels = new OO.ui.StackLayout( { $: this.$, scrollable: true } );
|
2014-05-19 17:41:06 +00:00
|
|
|
this.savePanel = new OO.ui.PanelLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
$: this.$,
|
|
|
|
scrollable: true,
|
2015-01-31 02:14:07 +00:00
|
|
|
padded: true,
|
2014-08-22 20:50:48 +00:00
|
|
|
classes: ['ve-ui-mwSaveDialog-savePanel']
|
2014-05-19 17:41:06 +00:00
|
|
|
} );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
2014-10-09 20:52:51 +00:00
|
|
|
// Byte counter in edit summary
|
2015-01-05 21:05:42 +00:00
|
|
|
this.editSummaryCountLabel = new OO.ui.LabelWidget( {
|
2014-10-09 20:52:51 +00:00
|
|
|
$: this.$,
|
|
|
|
classes: [ 've-ui-mwSaveDialog-editSummary-count' ],
|
2014-10-09 22:37:52 +00:00
|
|
|
label: String( this.editSummaryByteLimit ),
|
|
|
|
title: ve.msg( 'visualeditor-editsummary-bytes-remaining' )
|
2014-10-09 20:52:51 +00:00
|
|
|
} );
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
// Save panel
|
|
|
|
this.$editSummaryLabel = this.$( '<div>' ).addClass( 've-ui-mwSaveDialog-summaryLabel' )
|
|
|
|
.html( ve.init.platform.getParsedMessage( 'summary' ) )
|
|
|
|
.find( 'a' ).attr( 'target', '_blank' ).end();
|
|
|
|
this.editSummaryInput = new OO.ui.TextInputWidget(
|
2014-08-22 20:50:48 +00:00
|
|
|
{ $: this.$, multiline: true, placeholder: ve.msg( 'visualeditor-editsummary' ) }
|
2013-11-05 00:29:50 +00:00
|
|
|
);
|
|
|
|
this.editSummaryInput.$element.addClass( 've-ui-mwSaveDialog-summary' );
|
|
|
|
this.editSummaryInput.$input
|
|
|
|
.byteLimit( this.editSummaryByteLimit )
|
|
|
|
.prop( 'tabIndex', 0 );
|
2013-11-19 07:50:55 +00:00
|
|
|
this.editSummaryInput.on( 'change', function () {
|
2013-11-05 00:29:50 +00:00
|
|
|
// TODO: This looks a bit weird, there is no unit in the UI, just numbers
|
|
|
|
// Users likely assume characters but then it seems to count down quicker
|
|
|
|
// than expected. Facing users with the word "byte" is bad? (bug 40035)
|
2014-12-16 21:14:01 +00:00
|
|
|
dialog.editSummaryCountLabel.setLabel(
|
|
|
|
String( dialog.editSummaryByteLimit - $.byteLength( dialog.editSummaryInput.getValue() ) )
|
2013-11-19 07:50:55 +00:00
|
|
|
);
|
2014-12-16 21:14:01 +00:00
|
|
|
} );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
this.$saveOptions = this.$( '<div>' ).addClass( 've-ui-mwSaveDialog-options' ).append(
|
|
|
|
this.$( '<div>' ).addClass( 've-ui-mwSaveDialog-checkboxes' ),
|
2014-10-09 20:52:51 +00:00
|
|
|
this.editSummaryCountLabel.$element
|
2013-11-05 00:29:50 +00:00
|
|
|
);
|
|
|
|
this.$saveMessages = this.$( '<div>' );
|
2014-07-25 18:39:03 +00:00
|
|
|
this.$saveActions = this.$( '<div>' );
|
2013-11-05 00:29:50 +00:00
|
|
|
this.$saveFoot = this.$( '<div>' ).addClass( 've-ui-mwSaveDialog-foot' ).append(
|
|
|
|
this.$( '<p>' ).addClass( 've-ui-mwSaveDialog-license' )
|
|
|
|
.html( ve.init.platform.getParsedMessage( 'copyrightwarning' ) )
|
|
|
|
.find( 'a' ).attr( 'target', '_blank' ).end()
|
|
|
|
);
|
|
|
|
this.savePanel.$element.append(
|
|
|
|
this.$editSummaryLabel,
|
|
|
|
this.editSummaryInput.$element,
|
|
|
|
this.$saveOptions,
|
|
|
|
this.$saveMessages,
|
|
|
|
this.$saveActions,
|
|
|
|
this.$saveFoot
|
|
|
|
);
|
|
|
|
|
|
|
|
// Review panel
|
2015-01-31 02:14:07 +00:00
|
|
|
this.reviewPanel = new OO.ui.PanelLayout( {
|
|
|
|
$: this.$,
|
|
|
|
scrollable: true,
|
|
|
|
padded: true
|
|
|
|
} );
|
2013-11-05 00:29:50 +00:00
|
|
|
this.$reviewViewer = this.$( '<div>' ).addClass( 've-ui-mwSaveDialog-viewer' );
|
2014-02-10 18:33:13 +00:00
|
|
|
this.$reviewEditSummary = this.$( '<span>' ).addClass( 've-ui-mwSaveDialog-summaryPreview' ).addClass( 'comment' );
|
2013-11-05 00:29:50 +00:00
|
|
|
this.$reviewActions = this.$( '<div>' ).addClass( 've-ui-mwSaveDialog-actions' );
|
2014-02-10 18:33:13 +00:00
|
|
|
this.reviewPanel.$element.append(
|
|
|
|
$( '<br>' ),
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 'mw-summary-preview' )
|
|
|
|
.text( ve.msg( 'summary-preview' ) )
|
|
|
|
.append( $( '<br>' ), this.$reviewEditSummary ),
|
|
|
|
this.$reviewViewer,
|
|
|
|
this.$reviewActions
|
|
|
|
);
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Conflict panel
|
2015-01-31 02:14:07 +00:00
|
|
|
this.conflictPanel = new OO.ui.PanelLayout( {
|
|
|
|
$: this.$,
|
|
|
|
scrollable: true,
|
|
|
|
padded: true
|
|
|
|
} );
|
2013-11-05 00:29:50 +00:00
|
|
|
this.$conflict = this.$( '<div>' ).addClass( 've-ui-mwSaveDialog-conflict' )
|
|
|
|
.html( ve.init.platform.getParsedMessage( 'visualeditor-editconflict' ) )
|
|
|
|
.find( 'a' ).attr( 'target', '_blank' ).end();
|
|
|
|
this.conflictPanel.$element.append( this.$conflict );
|
|
|
|
|
|
|
|
// No changes panel
|
2015-01-31 02:14:07 +00:00
|
|
|
this.nochangesPanel = new OO.ui.PanelLayout( {
|
|
|
|
$: this.$,
|
|
|
|
scrollable: true,
|
|
|
|
padded: true
|
|
|
|
} );
|
2013-11-05 00:29:50 +00:00
|
|
|
this.$noChanges = this.$( '<div>' ).addClass( 've-ui-mwSaveDialog-nochanges' )
|
|
|
|
.html( ve.init.platform.getParsedMessage( 'visualeditor-diff-nochanges' ) )
|
|
|
|
.find( 'a' ).attr( 'target', '_blank' ).end();
|
|
|
|
this.nochangesPanel.$element.append( this.$noChanges );
|
|
|
|
|
|
|
|
// Panel stack
|
2014-07-14 21:32:49 +00:00
|
|
|
this.panels.addItems( [
|
|
|
|
this.savePanel,
|
|
|
|
this.reviewPanel,
|
|
|
|
this.conflictPanel,
|
|
|
|
this.nochangesPanel
|
|
|
|
] );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Save button for "save" panel
|
2014-07-14 21:32:49 +00:00
|
|
|
saveAccessKey = ve.msg( 'accesskey-save' );
|
|
|
|
if ( saveAccessKey !== '-' && saveAccessKey !== '' ) {
|
2014-08-22 20:50:48 +00:00
|
|
|
this.actions.forEach( { actions: 'save' }, function ( action ) {
|
2014-07-14 21:32:49 +00:00
|
|
|
action.setAccessKey( saveAccessKey );
|
|
|
|
} );
|
2014-01-30 19:33:30 +00:00
|
|
|
}
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Initialization
|
2014-07-14 21:32:49 +00:00
|
|
|
this.$body.append( this.panels.$element );
|
2013-11-14 23:14:16 +00:00
|
|
|
|
|
|
|
this.setupDeferred.resolve();
|
|
|
|
};
|
|
|
|
|
2014-06-12 00:35:46 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.getSetupProcess = function ( data ) {
|
|
|
|
return ve.ui.MWSaveDialog.super.prototype.getSetupProcess.call( this, data )
|
2014-07-14 21:32:49 +00:00
|
|
|
.next( function () {
|
2014-07-25 18:39:03 +00:00
|
|
|
// Old messages should not persist
|
2014-06-12 00:35:46 +00:00
|
|
|
this.clearAllMessages();
|
2014-07-25 18:39:03 +00:00
|
|
|
this.swapPanel( 'save' );
|
2014-07-14 21:32:49 +00:00
|
|
|
// Update save button label
|
2014-08-22 20:50:48 +00:00
|
|
|
this.actions.forEach( { actions: 'save' }, function ( action ) {
|
2014-07-14 21:32:49 +00:00
|
|
|
action.setLabel(
|
|
|
|
ve.msg(
|
2014-12-27 22:50:54 +00:00
|
|
|
// TODO: Actually populate this.restoring with information. Right now it is
|
|
|
|
// always false because of an oversight when migrating this code from init.
|
|
|
|
// Possible messages:
|
2014-07-14 21:32:49 +00:00
|
|
|
// visualeditor-savedialog-label-restore, visualeditor-savedialog-label-save
|
|
|
|
'visualeditor-savedialog-label-' + ( this.restoring ? 'restore' : 'save' )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} );
|
2014-06-12 00:35:46 +00:00
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
2015-01-06 00:51:38 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.getReadyProcess = function ( data ) {
|
|
|
|
return ve.ui.MWSaveDialog.super.prototype.getReadyProcess.call( this, data )
|
|
|
|
.next( function () {
|
|
|
|
this.editSummaryInput.focus();
|
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
2014-05-28 22:05:17 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-07-14 21:32:49 +00:00
|
|
|
ve.ui.MWSaveDialog.prototype.getActionProcess = function ( action ) {
|
|
|
|
if ( action === 'save' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
|
|
|
var saveDeferred = $.Deferred();
|
|
|
|
this.emit( 'save', saveDeferred );
|
|
|
|
return saveDeferred.promise();
|
|
|
|
}, this );
|
|
|
|
}
|
|
|
|
if ( action === 'review' || action === 'resolve' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
|
|
|
this.emit( action );
|
|
|
|
}, this );
|
|
|
|
}
|
|
|
|
if ( action === 'approve' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
|
|
|
this.swapPanel( 'save' );
|
|
|
|
}, this );
|
|
|
|
}
|
2014-05-28 22:05:17 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
return ve.ui.MWSaveDialog.super.prototype.getActionProcess.call( this, action );
|
2014-05-28 22:05:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-07-14 21:32:49 +00:00
|
|
|
ve.ui.MWSaveDialog.prototype.getBodyHeight = function () {
|
|
|
|
// Don't vary the height when the foot is made visible or not
|
|
|
|
return 350 - this.$foot.outerHeight( true );
|
2014-05-28 22:05:17 +00:00
|
|
|
};
|
|
|
|
|
2014-10-30 00:36:02 +00:00
|
|
|
/**
|
|
|
|
* Handle retry button click events.
|
|
|
|
*
|
|
|
|
* Hides errors and then tries again.
|
|
|
|
*/
|
|
|
|
ve.ui.MWSaveDialog.prototype.onRetryButtonClick = function () {
|
|
|
|
this.emit( 'retry' );
|
|
|
|
ve.ui.MWSaveDialog.super.prototype.onRetryButtonClick.apply( this, arguments );
|
|
|
|
};
|
|
|
|
|
2013-10-07 10:01:43 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2014-04-21 22:31:21 +00:00
|
|
|
ve.ui.windowFactory.register( ve.ui.MWSaveDialog );
|