From 72b0d2a19c1f6510df6f108827673dcbbb65b8c9 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Fri, 15 Nov 2013 13:31:40 -0800 Subject: [PATCH] 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 --- .../init/targets/ve.init.mw.ViewPageTarget.js | 7 +++---- modules/ve-mw/init/ve.init.mw.Target.js | 15 +++++++++++++-- .../ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js | 19 +++++-------------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js index 27f3df55d7..24fead74ab 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js @@ -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 ); }; /** diff --git a/modules/ve-mw/init/ve.init.mw.Target.js b/modules/ve-mw/init/ve.init.mw.Target.js index 3d2c58895e..a1e9faa328 100644 --- a/modules/ve-mw/init/ve.init.mw.Target.js +++ b/modules/ve-mw/init/ve.init.mw.Target.js @@ -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; diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js index 40efb00377..4b0fb2f521 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js @@ -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 ); } ); };