Move setting of minor/watch defaults from MWSaveDialog to Target

It looks like it also came from there originally, because it uses
this.pageExists which doesn't even exist in MWSaveDialog. This caused
all pages, even existing pages, to be watched when 'watchcreations'
was set.

This logic really belongs server-side, though.

Bug: 56206
Change-Id: Idf500383b27a93136dc0cfdd60a2e7b2607af95c
This commit is contained in:
Roan Kattouw 2013-11-15 13:31:40 -08:00
parent c9b31e2d7e
commit 72b0d2a19c
3 changed files with 21 additions and 20 deletions

View file

@ -907,9 +907,8 @@ ve.init.mw.ViewPageTarget.prototype.getSaveOptions = function () {
// Firefox has Object.prototype.watch
options.watch = undefined;
}
this.saveDialog.$saveOptions
.find( '.ve-ui-mwSaveDialog-checkboxes' )
.find( 'input:not(#wpMinoredit, #wpWatchthis)' )
this.$checkboxes
.not( '#wpMinoredit, #wpWatchthis' )
.each( function () {
var $this = $( this );
// We can't just use $this.val() because .val() always returns the value attribute of
@ -1219,7 +1218,7 @@ ve.init.mw.ViewPageTarget.prototype.setupSaveDialog = function () {
} );
// Setup edit summary and checkboxes
this.saveDialog.setEditSummary( this.initialEditSummary );
this.saveDialog.setupCheckboxes( ve.getObjectValues( this.checkboxes ).join( '\n' ) );
this.saveDialog.setupCheckboxes( this.$checkboxes );
};
/**

View file

@ -68,7 +68,7 @@ ve.init.mw.Target = function VeInitMwTarget( $container, pageName, revisionId )
this.startTimeStamp = null;
this.doc = null;
this.editNotices = null;
this.checkboxes = null;
this.$checkboxes = null;
this.remoteNotices = [];
this.localNoticeMessages = [];
this.isMobileDevice = (
@ -190,7 +190,18 @@ ve.init.mw.Target.onLoad = function ( response ) {
this.doc = ve.createDocumentFromHtml( this.originalHtml );
this.remoteNotices = ve.getObjectValues( data.notices );
this.checkboxes = data.checkboxes;
this.$checkboxes = $( ve.getObjectValues( data.checkboxes ).join( '' ) );
// Populate checkboxes with default values for minor and watch
this.$checkboxes
.filter( '#wpMinoredit' )
.prop( 'checked', mw.user.options.get( 'minordefault' ) )
.end()
.filter( '#wpWatchthis' )
.prop( 'checked',
mw.user.options.get( 'watchdefault' ) ||
( mw.user.options.get( 'watchcreations' ) && !this.pageExists ) ||
mw.config.get( 'wgVisualEditor' ).isPageWatched
);
this.baseTimeStamp = data.basetimestamp;
this.startTimeStamp = data.starttimestamp;

View file

@ -240,27 +240,18 @@ ve.ui.MWSaveDialog.prototype.reset = function () {
*
* This method is safe to call even when the dialog hasn't been initialized yet.
*
* @param {string} checkboxes Multiline HTML
* @param {jQuery} $checkboxes jQuery collection of checkboxes
*/
ve.ui.MWSaveDialog.prototype.setupCheckboxes = function ( checkboxes ) {
ve.ui.MWSaveDialog.prototype.setupCheckboxes = function ( $checkboxes ) {
var saveDialog = this;
this.setupDeferred.done( function () {
saveDialog.$saveOptions.find( '.ve-ui-mwSaveDialog-checkboxes' )
.html( 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
.find( 'input' )
.prop( 'tabIndex', 0 );
} );
};