/*! * VisualEditor UserInterface MWSaveDialog class. * * @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt * @license The MIT License (MIT); see LICENSE.txt */ /*global mw */ /** * Dialog for saving MediaWiki articles. * * @class * @extends ve.ui.MWDialog * * @constructor * @param {ve.ui.SurfaceWindowSet} windowSet Window set this dialog is part of * @param {Object} [config] Config options */ ve.ui.MWSaveDialog = function VeUiMWSaveDialog( windowSet, config ) { // Configuration initialization config = ve.extendObject( { 'small': true }, config ); // Parent constructor ve.ui.MWDialog.call( this, windowSet, config ); // Properties this.sanityCheckVerified = false; this.editSummaryByteLimit = 255; this.restoring = false; this.messages = {}; }; /* Inheritance */ OO.inheritClass( ve.ui.MWSaveDialog, ve.ui.MWDialog ); /* Static Properties */ ve.ui.MWSaveDialog.static.name = 'mwSave'; ve.ui.MWSaveDialog.static.titleMessage = 'visualeditor-savedialog-title-save'; /* Methods */ /** * @inheritdoc */ ve.ui.MWSaveDialog.prototype.initialize = function () { var saveDialog = this; // Parent method ve.ui.MWDialog.prototype.initialize.call( this ); // Properties this.savePanel = new ve.ui.PanelLayout( { '$$': this.frame.$$, 'scrollable': true } ); // Save panel this.$editSummaryLabel = this.frame.$$( '
' ).addClass( 've-ui-mwSaveDialog-license' ) .html( ve.init.platform.getParsedMessage( 'copyrightwarning' ) ) ); this.savePanel.$.append( this.$editSummaryLabel, this.editSummaryInput.$, this.$saveOptions, this.$saveMessages, this.$saveActions, this.$saveFoot ); // Review panel this.reviewPanel = new ve.ui.PanelLayout( { '$$': this.frame.$$, 'scrollable': true } ); this.$reviewViewer = this.frame.$$( '
').append( // visualeditor-savedialog-label-error // visualeditor-savedialog-label-warning $( '' ).text( mw.msg( 'visualeditor-savedialog-label-' + options.wrap ) ), 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 this.editSummaryInput.$input.val( '' ); // Uncheck minoredit this.$saveOptions.find( '.ve-ui-mwSaveDialog-checkboxes' ) .find( '#wpMinoredit' ).prop( 'checked', false ); // Clear the diff this.$reviewViewer.empty(); }; /** * Initialize MediaWiki page specific checkboxes * * @param {string} checkboxes Multiline HTML */ ve.ui.MWSaveDialog.prototype.setupCheckboxes = function ( checkboxes ) { this.$saveOptions.find( '.ve-ui-mwSaveDialog-checkboxes' ) .html( checkboxes ) .find( 'a' ) .attr( 'target', '_blank' ) .end() .find( '#wpMinoredit' ) .prop( 'checked', mw.user.options.get( 'minordefault' ) ) .prop( 'tabIndex', 0 ) .end() .find( '#wpWatchthis' ) .prop( 'checked', mw.user.options.get( 'watchdefault' ) || ( mw.user.options.get( 'watchcreations' ) && !this.pageExists ) || mw.config.get( 'wgVisualEditor' ).isPageWatched ).prop( 'tabIndex', 0 ); // TODO: Need to set all checkboxes provided by api tabindex to 0 for proper accessibility }; /** * Set review content and show review panel * * @param {string} content Diff HTML or wikitext */ ve.ui.MWSaveDialog.prototype.setDiffAndReview = function ( content ) { this.$reviewViewer.empty().append( content ); this.reviewGoodButton.setDisabled( false ); this.$loadingIcon.hide(); this.swapPanel( 'review' ); }; /** * Set sanity check flag * * @param {boolean} verified Status of sanity check */ ve.ui.MWSaveDialog.prototype.setSanityCheck = function ( verified ) { this.sanityCheckVerified = !!verified; }; /* Registration */ ve.ui.dialogFactory.register( ve.ui.MWSaveDialog );