Catrope has uploaded a new change for review. https://gerrit.wikimedia.org/r/95564
Change subject: Make save dialog ready for async initialization ...................................................................... Make save dialog ready for async initialization initialize() is currently called synchronously, but once the CSS transplantation code is fixed and it goes back to being async, that'll cause problems. * Add this.setupDeferred and use it to defer setupCheckboxes() until after initialization * Move code populating the edit summary from ViewPageTarget into MWSaveDialog and use .setValue() rather than manipulating the TextInputWidget's DOM. Defer this until after init as well Bonus: * Document events * Get rid of onFooButtonClick handlers in favor of array syntax Change-Id: Idcdae5e013340f4519db4387bab507e714d47941 --- M modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js M modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js 2 files changed, 66 insertions(+), 40 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/64/95564/1 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 623e7d4..a70a7cc 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js @@ -1232,7 +1232,7 @@ if ( viewPage.section ) { sectionTitle = viewPage.$document.find( 'h1, h2, h3, h4, h5, h6' ).eq( viewPage.section - 1 ).text(); sectionTitle = '/* ' + ve.graphemeSafeSubstring( sectionTitle, 0, 244 ) + ' */ '; - viewPage.saveDialog.editSummaryInput.$input.val( sectionTitle ); + viewPage.saveDialog.setEditSummary( sectionTitle ); viewPage.sectionTitleRestored = true; if ( viewPage.sectionPositionRestored ) { viewPage.onSectionRestored(); diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js index db1a07f..dbf8165 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js @@ -10,6 +10,9 @@ /** * Dialog for saving MediaWiki articles. * + * Note that most methods are not safe to call before the dialog has initialized, except where + * noted otherwise. + * * @class * @extends ve.ui.MWDialog * @@ -29,6 +32,7 @@ this.editSummaryByteLimit = 255; this.restoring = false; this.messages = {}; + this.setupDeferred = $.Deferred(); }; /* Inheritance */ @@ -41,26 +45,27 @@ ve.ui.MWSaveDialog.static.titleMessage = 'visualeditor-savedialog-title-save'; -/* Methods */ - -ve.ui.MWSaveDialog.prototype.onSaveButtonClick = function () { - this.emit( 'save' ); -}; - -ve.ui.MWSaveDialog.prototype.onReviewButtonClick = function () { - this.emit( 'review' ); -}; - -ve.ui.MWSaveDialog.prototype.onReviewGoodButtonClick = function () { - this.swapPanel( 'save' ); -}; - -ve.ui.MWSaveDialog.prototype.onResolveConflictButtonClick = function () { - this.emit( 'resolve' ); -}; +/* Events */ /** - * Set review content and show review panel + * @event save + * Emitted when the user clicks the save button + */ + +/** + * @event review + * Emitted when the user clicks the review changes button + */ + +/** + * @event resolve + * Emitted when the user clicks the resolve conflict button + */ + +/* Methods */ + +/** + * Set review content and show review panel. * * @param {string} content Diff HTML or wikitext */ @@ -224,27 +229,46 @@ }; /** - * Initialize MediaWiki page specific checkboxes + * Initialize MediaWiki page specific checkboxes. + * + * This method is safe to call even when the dialog hasn't been initialized yet. * * @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 + var saveDialog = this; + this.setupDeferred.done( function () { + saveDialog.$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 + } ); +}; + +/** + * 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 ) { + var saveDialog = this; + this.setupDeferred.done( function () { + saveDialog.editSummaryInput.setValue( summary ); + } ); }; /** @@ -341,26 +365,26 @@ ), 'flags': ['constructive'] } ); - this.saveButton.connect( this, { 'click': 'onSaveButtonClick' } ); + this.saveButton.connect( this, { 'click': [ 'emit', 'save' ] } ); // Review button for "save" panel this.reviewButton = new OO.ui.PushButtonWidget( { 'label': ve.msg( 'visualeditor-savedialog-label-review' ) } ); - this.reviewButton.connect( this, { 'click': 'onReviewButtonClick' } ); + this.reviewButton.connect( this, { 'click': [ 'emit', 'review' ] } ); // Review good button on "review" panel this.reviewGoodButton = new OO.ui.PushButtonWidget( { 'label': ve.msg( 'visualeditor-savedialog-label-review-good' ), 'flags': ['constructive'] } ); - this.reviewGoodButton.connect( this, { 'click': 'onReviewGoodButtonClick' } ); + this.reviewGoodButton.connect( this, { 'click': [ 'swapPanel', 'save' ] } ); // Resolve conflict this.resolveConflictButton = new OO.ui.PushButtonWidget( { 'label': ve.msg( 'visualeditor-savedialog-label-resolve-conflict' ), 'flags': ['constructive'] } ); - this.resolveConflictButton.connect( this, { 'click': 'onResolveConflictButtonClick' } ); + this.resolveConflictButton.connect( this, { 'click': [ 'emit', 'resolve' ] } ); this.$loadingIcon = this.$( '<div>' ).addClass( 've-ui-mwSaveDialog-working' ); @@ -373,6 +397,8 @@ this.resolveConflictButton.$element, this.$loadingIcon ); + + this.setupDeferred.resolve(); }; /* Registration */ -- To view, visit https://gerrit.wikimedia.org/r/95564 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idcdae5e013340f4519db4387bab507e714d47941 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Catrope <roan.katt...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits