mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-27 09:43:30 +00:00
CommentController: Merge (mode, hideErrors, suppressNotifications) into options
Change-Id: Ib8b75fd44fcf560d30e2a6a6f79a9e833c0e5200
This commit is contained in:
parent
70f3c2a1e4
commit
31dc9b4e1c
|
@ -109,15 +109,18 @@ CommentController.static.initType = 'page';
|
||||||
/**
|
/**
|
||||||
* Create and setup the reply widget
|
* Create and setup the reply widget
|
||||||
*
|
*
|
||||||
* @param {string} [mode] Optionally force a mode, 'visual' or 'source'
|
* @param {Object} [options]
|
||||||
* @param {boolean} [hideErrors] Suppress errors, e.g. when restoring auto-save
|
* @param {string} [options.mode] Optionally force a mode, 'visual' or 'source'
|
||||||
* @param {boolean} [suppressNotifications] Don't notify the user if recovering auto-save
|
* @param {boolean} [options.hideErrors] Suppress errors, e.g. when restoring auto-save
|
||||||
|
* @param {boolean} [options.suppressNotifications] Don't notify the user if recovering auto-save
|
||||||
*/
|
*/
|
||||||
CommentController.prototype.setup = function ( mode, hideErrors, suppressNotifications ) {
|
CommentController.prototype.setup = function ( options ) {
|
||||||
const threadItem = this.getThreadItem();
|
const threadItem = this.getThreadItem();
|
||||||
|
|
||||||
if ( mode === undefined ) {
|
options = options || {};
|
||||||
mode = mw.user.options.get( 'discussiontools-editmode' ) ||
|
|
||||||
|
if ( options.mode === undefined ) {
|
||||||
|
options.mode = mw.user.options.get( 'discussiontools-editmode' ) ||
|
||||||
( defaultVisual ? 'visual' : 'source' );
|
( defaultVisual ? 'visual' : 'source' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,17 +130,17 @@ CommentController.prototype.setup = function ( mode, hideErrors, suppressNotific
|
||||||
mechanism: 'click',
|
mechanism: 'click',
|
||||||
integration: 'discussiontools',
|
integration: 'discussiontools',
|
||||||
// eslint-disable-next-line camelcase
|
// eslint-disable-next-line camelcase
|
||||||
editor_interface: mode === 'visual' ? 'visualeditor' :
|
editor_interface: options.mode === 'visual' ? 'visualeditor' :
|
||||||
( enable2017Wikitext ? 'wikitext-2017' : 'wikitext' )
|
( enable2017Wikitext ? 'wikitext-2017' : 'wikitext' )
|
||||||
} );
|
} );
|
||||||
|
|
||||||
if ( !this.replyWidgetPromise ) {
|
if ( !this.replyWidgetPromise ) {
|
||||||
this.replyWidgetPromise = this.getTranscludedFromSource().then(
|
this.replyWidgetPromise = this.getTranscludedFromSource().then(
|
||||||
( commentDetails ) => this.createReplyWidget( commentDetails, { mode: mode } ),
|
( commentDetails ) => this.createReplyWidget( commentDetails, { mode: options.mode } ),
|
||||||
( code, data ) => {
|
( code, data ) => {
|
||||||
this.onReplyWidgetTeardown();
|
this.onReplyWidgetTeardown();
|
||||||
|
|
||||||
if ( !hideErrors ) {
|
if ( !options.hideErrors ) {
|
||||||
OO.ui.alert(
|
OO.ui.alert(
|
||||||
code instanceof Error ? code.toString() : controller.getApi().getErrorMessage( data ),
|
code instanceof Error ? code.toString() : controller.getApi().getErrorMessage( data ),
|
||||||
{ size: 'medium' }
|
{ size: 'medium' }
|
||||||
|
@ -205,7 +208,7 @@ CommentController.prototype.setup = function ( mode, hideErrors, suppressNotific
|
||||||
}
|
}
|
||||||
$( this.newListItem ).empty().append( replyWidget.$element );
|
$( this.newListItem ).empty().append( replyWidget.$element );
|
||||||
|
|
||||||
this.setupReplyWidget( replyWidget, {}, suppressNotifications );
|
this.setupReplyWidget( replyWidget, {}, options.suppressNotifications );
|
||||||
|
|
||||||
this.showAndFocus();
|
this.showAndFocus();
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ NewTopicController.static.suppressedEditNotices = [
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
NewTopicController.prototype.setup = function ( mode ) {
|
NewTopicController.prototype.setup = function () {
|
||||||
const rootScrollable = OO.ui.Element.static.getRootScrollableElement( document.body );
|
const rootScrollable = OO.ui.Element.static.getRootScrollableElement( document.body );
|
||||||
|
|
||||||
// Insert directly after the page content on already existing pages
|
// Insert directly after the page content on already existing pages
|
||||||
|
@ -82,7 +82,7 @@ NewTopicController.prototype.setup = function ( mode ) {
|
||||||
this.$pageContainer.append( this.container.$element );
|
this.$pageContainer.append( this.container.$element );
|
||||||
}
|
}
|
||||||
|
|
||||||
NewTopicController.super.prototype.setup.call( this, mode );
|
NewTopicController.super.prototype.setup.apply( this, arguments );
|
||||||
|
|
||||||
if ( this.threadItem.preloadtitle ) {
|
if ( this.threadItem.preloadtitle ) {
|
||||||
this.sectionTitle.setValue( this.threadItem.preloadtitle );
|
this.sectionTitle.setValue( this.threadItem.preloadtitle );
|
||||||
|
|
|
@ -347,17 +347,18 @@ function init( $container, state ) {
|
||||||
*
|
*
|
||||||
* @param {ThreadItem} comment
|
* @param {ThreadItem} comment
|
||||||
* @param {jQuery} $link Add section link for new topic controller
|
* @param {jQuery} $link Add section link for new topic controller
|
||||||
* @param {string} [mode] Optionally force a mode, 'visual' or 'source'
|
* @param {Object} [options] Options, see CommentController
|
||||||
* @param {boolean} [hideErrors] Suppress errors, e.g. when restoring auto-save
|
* @param {string} [options.mode] Optionally force a mode, 'visual' or 'source'
|
||||||
* @param {boolean} [suppressNotifications] Don't notify the user if recovering auto-save
|
* @param {boolean} [options.hideErrors] Suppress errors, e.g. when restoring auto-save
|
||||||
|
* @param {boolean} [options.suppressNotifications] Don't notify the user if recovering auto-save
|
||||||
* @param {MemoryStorage} [storage] Storage object for autosave
|
* @param {MemoryStorage} [storage] Storage object for autosave
|
||||||
*/
|
*/
|
||||||
function setupController( comment, $link, mode, hideErrors, suppressNotifications, storage ) {
|
function setupController( comment, $link, options, storage ) {
|
||||||
let commentController, $addSectionLink;
|
|
||||||
|
|
||||||
if ( !storage ) {
|
if ( !storage ) {
|
||||||
storage = new MemoryStorage( mw.storage, 'mw-ext-DiscussionTools-reply/' + comment.id, STORAGE_EXPIRY );
|
storage = new MemoryStorage( mw.storage, 'mw-ext-DiscussionTools-reply/' + comment.id, STORAGE_EXPIRY );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let commentController, $addSectionLink;
|
||||||
if ( comment.id === utils.NEW_TOPIC_COMMENT_ID ) {
|
if ( comment.id === utils.NEW_TOPIC_COMMENT_ID ) {
|
||||||
// eslint-disable-next-line no-jquery/no-global-selector
|
// eslint-disable-next-line no-jquery/no-global-selector
|
||||||
$addSectionLink = $( '#ca-addsection' ).find( 'a' );
|
$addSectionLink = $( '#ca-addsection' ).find( 'a' );
|
||||||
|
@ -396,7 +397,7 @@ function init( $container, state ) {
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
commentController.setup( mode, hideErrors, suppressNotifications );
|
commentController.setup( options );
|
||||||
if ( lastControllerScrollOffset ) {
|
if ( lastControllerScrollOffset ) {
|
||||||
$( document.documentElement ).scrollTop(
|
$( document.documentElement ).scrollTop(
|
||||||
$( document.documentElement ).scrollTop() +
|
$( document.documentElement ).scrollTop() +
|
||||||
|
@ -486,7 +487,11 @@ function init( $container, state ) {
|
||||||
}
|
}
|
||||||
// Wait for the 'hashchange' event to be handled by the mobile code
|
// Wait for the 'hashchange' event to be handled by the mobile code
|
||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
setupController( comment, $link, mode, true, !state.firstLoad, replyStorage );
|
setupController( comment, $link, {
|
||||||
|
mode: mode,
|
||||||
|
hideErrors: true,
|
||||||
|
suppressNotifications: !state.firstLoad
|
||||||
|
}, replyStorage );
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
return false;
|
return false;
|
||||||
|
@ -496,7 +501,11 @@ function init( $container, state ) {
|
||||||
const newTopicStorage = new MemoryStorage( mw.storage, 'mw-ext-DiscussionTools-reply/' + utils.NEW_TOPIC_COMMENT_ID, STORAGE_EXPIRY );
|
const newTopicStorage = new MemoryStorage( mw.storage, 'mw-ext-DiscussionTools-reply/' + utils.NEW_TOPIC_COMMENT_ID, STORAGE_EXPIRY );
|
||||||
if ( newTopicStorage.get( 'saveable' ) || newTopicStorage.get( 'title' ) ) {
|
if ( newTopicStorage.get( 'saveable' ) || newTopicStorage.get( 'title' ) ) {
|
||||||
const mode = newTopicStorage.get( 'mode' );
|
const mode = newTopicStorage.get( 'mode' );
|
||||||
setupController( newTopicComment(), $( [] ), mode, true, !state.firstLoad, newTopicStorage );
|
setupController( newTopicComment(), $( [] ), {
|
||||||
|
mode: mode,
|
||||||
|
hideErrors: true,
|
||||||
|
suppressNotifications: !state.firstLoad
|
||||||
|
}, newTopicStorage );
|
||||||
} else if ( mw.config.get( 'wgDiscussionToolsStartNewTopicTool' ) ) {
|
} else if ( mw.config.get( 'wgDiscussionToolsStartNewTopicTool' ) ) {
|
||||||
const data = linksController.parseNewTopicLink( location.href );
|
const data = linksController.parseNewTopicLink( location.href );
|
||||||
setupController( newTopicComment( data ), $( [] ) );
|
setupController( newTopicComment( data ), $( [] ) );
|
||||||
|
|
Loading…
Reference in a new issue