2013-12-02 20:10:55 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWTemplatePlaceholderPage class.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2013-12-02 20:10:55 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki transclusion dialog placeholder page.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.PageLayout
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.dm.MWTemplatePlaceholderModel} placeholder Template placeholder
|
|
|
|
* @param {string} name Unique symbolic name of page
|
|
|
|
* @param {Object} [config] Configuration options
|
2018-04-04 20:37:32 +00:00
|
|
|
* @cfg {jQuery} [$overlay] Overlay to render dropdowns in
|
2013-12-02 20:10:55 +00:00
|
|
|
*/
|
2014-02-28 00:00:10 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage = function VeUiMWTemplatePlaceholderPage( placeholder, name, config ) {
|
2021-07-15 08:49:06 +00:00
|
|
|
var veConfig = mw.config.get( 'wgVisualEditorConfig' );
|
|
|
|
|
2014-04-25 23:50:21 +00:00
|
|
|
// Configuration initialization
|
|
|
|
config = ve.extendObject( {
|
2014-08-22 20:50:48 +00:00
|
|
|
scrollable: false
|
2014-04-25 23:50:21 +00:00
|
|
|
}, config );
|
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
// Parent constructor
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage.super.call( this, name, config );
|
2013-12-02 20:10:55 +00:00
|
|
|
|
|
|
|
// Properties
|
2014-02-12 21:45:37 +00:00
|
|
|
this.placeholder = placeholder;
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2015-04-10 20:28:38 +00:00
|
|
|
this.addTemplateInput = new ve.ui.MWTemplateTitleInputWidget( {
|
2015-06-15 10:25:44 +00:00
|
|
|
$overlay: config.$overlay,
|
2018-05-04 13:30:10 +00:00
|
|
|
showDescriptions: true,
|
|
|
|
api: ve.init.target.getContentApi()
|
2014-06-26 10:41:18 +00:00
|
|
|
} )
|
2013-12-02 20:10:55 +00:00
|
|
|
.connect( this, {
|
2014-08-22 20:50:48 +00:00
|
|
|
change: 'onTemplateInputChange',
|
|
|
|
enter: 'onAddTemplate'
|
2013-12-02 20:10:55 +00:00
|
|
|
} );
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2019-05-17 11:15:07 +00:00
|
|
|
this.addTemplateInput.getLookupMenu().connect( this, {
|
|
|
|
choose: 'onAddTemplate'
|
|
|
|
} );
|
|
|
|
|
2020-04-03 04:02:55 +00:00
|
|
|
this.addTemplateInput.$input.attr( 'aria-label', ve.msg( 'visualeditor-dialog-transclusion-add-template' ) );
|
|
|
|
|
2014-01-17 14:24:12 +00:00
|
|
|
this.addTemplateButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-transclusion-add-template' ),
|
2017-09-26 18:59:38 +00:00
|
|
|
flags: [ 'progressive' ],
|
2015-01-27 00:47:59 +00:00
|
|
|
classes: [ 've-ui-mwTransclusionDialog-addButton' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
disabled: true
|
2014-06-26 10:41:18 +00:00
|
|
|
} )
|
2014-08-22 20:50:48 +00:00
|
|
|
.connect( this, { click: 'onAddTemplate' } );
|
2014-06-26 10:41:18 +00:00
|
|
|
|
2021-06-21 08:10:27 +00:00
|
|
|
var addTemplateActionFieldLayout = new OO.ui.ActionFieldLayout(
|
2015-01-27 00:47:59 +00:00
|
|
|
this.addTemplateInput,
|
2018-07-03 18:13:28 +00:00
|
|
|
this.addTemplateButton,
|
|
|
|
{ align: 'top' }
|
2015-01-27 00:47:59 +00:00
|
|
|
);
|
|
|
|
|
2021-06-21 08:10:27 +00:00
|
|
|
var addTemplateFieldsetConfig = {
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-transclusion-placeholder' ),
|
2017-07-06 16:52:56 +00:00
|
|
|
icon: 'puzzle',
|
2014-08-22 20:50:48 +00:00
|
|
|
classes: [ 've-ui-mwTransclusionDialog-addTemplateFieldset' ],
|
2015-01-27 00:47:59 +00:00
|
|
|
items: [ addTemplateActionFieldLayout ]
|
2021-05-03 12:46:56 +00:00
|
|
|
};
|
2021-06-09 17:00:40 +00:00
|
|
|
|
2022-06-10 15:04:19 +00:00
|
|
|
var dialogTitle = this.placeholder.getTransclusion().isSingleTemplate() ?
|
|
|
|
'visualeditor-dialog-transclusion-template-search' :
|
|
|
|
'visualeditor-dialog-transclusion-add-template';
|
|
|
|
|
|
|
|
// TODO: Remove `mw.storage.remove` after a few months, let's say December 2022.
|
|
|
|
mw.storage.remove( 'mwe-visualeditor-hide-visualeditor-dialog-transclusion-feedback-message' );
|
|
|
|
|
|
|
|
addTemplateFieldsetConfig = ve.extendObject( addTemplateFieldsetConfig, {
|
|
|
|
// The following messages are used here:
|
|
|
|
// * visualeditor-dialog-transclusion-template-search
|
|
|
|
// * visualeditor-dialog-transclusion-add-template
|
|
|
|
label: ve.msg( dialogTitle ),
|
|
|
|
help: ve.msg( 'visualeditor-dialog-transclusion-template-search-help' ),
|
|
|
|
helpInline: true
|
|
|
|
} );
|
2021-05-03 12:46:56 +00:00
|
|
|
this.addTemplateFieldset = new OO.ui.FieldsetLayout( addTemplateFieldsetConfig );
|
2013-12-02 20:10:55 +00:00
|
|
|
|
|
|
|
// Initialization
|
2014-02-28 01:18:49 +00:00
|
|
|
this.$element
|
|
|
|
.addClass( 've-ui-mwTemplatePlaceholderPage' )
|
2021-07-15 08:49:06 +00:00
|
|
|
.append( this.addTemplateFieldset.$element );
|
|
|
|
|
|
|
|
if ( !veConfig.transclusionDialogNewSidebar ) {
|
|
|
|
this.removeButton = new OO.ui.ButtonWidget( {
|
|
|
|
framed: false,
|
|
|
|
icon: 'trash',
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-remove-template' ),
|
|
|
|
flags: [ 'destructive' ],
|
|
|
|
classes: [ 've-ui-mwTransclusionDialog-removeButton' ]
|
|
|
|
} )
|
|
|
|
.connect( this, { click: 'onRemoveButtonClick' } );
|
|
|
|
|
2021-10-06 15:57:10 +00:00
|
|
|
if ( this.placeholder.getTransclusion().isSingleTemplate() ) {
|
2021-07-15 08:49:06 +00:00
|
|
|
this.removeButton.toggle( false );
|
|
|
|
}
|
|
|
|
this.$element.append( this.removeButton.$element );
|
|
|
|
}
|
2013-12-02 20:10:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWTemplatePlaceholderPage, OO.ui.PageLayout );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2014-02-15 01:37:32 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2021-09-15 10:10:56 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage.prototype.setupOutlineItem = function () {
|
2022-06-10 15:04:19 +00:00
|
|
|
var dialogTitle = this.placeholder.getTransclusion().isSingleTemplate() ?
|
2021-05-11 10:49:06 +00:00
|
|
|
'visualeditor-dialog-transclusion-template-search' :
|
|
|
|
'visualeditor-dialog-transclusion-add-template';
|
|
|
|
|
2021-09-15 10:10:56 +00:00
|
|
|
this.outlineItem
|
|
|
|
.setIcon( 'puzzle' )
|
|
|
|
.setMovable( true )
|
|
|
|
.setRemovable( true )
|
|
|
|
.setFlags( [ 'placeholder' ] )
|
|
|
|
// The following messages are used here:
|
|
|
|
// * visualeditor-dialog-transclusion-template-search
|
|
|
|
// * visualeditor-dialog-transclusion-add-template
|
|
|
|
.setLabel( ve.msg( dialogTitle ) );
|
2014-02-15 01:37:32 +00:00
|
|
|
};
|
|
|
|
|
2021-09-17 09:29:50 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc OO.ui.PanelLayout
|
|
|
|
*/
|
2018-08-24 13:22:00 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage.prototype.focus = function () {
|
2021-06-10 16:27:01 +00:00
|
|
|
// The parent method would focus the first element, which might be the message widget
|
|
|
|
this.addTemplateInput.focus();
|
2018-08-24 13:22:00 +00:00
|
|
|
|
|
|
|
// HACK: Set the width of the lookupMenu to the width of the input
|
|
|
|
// TODO: This should be handled upstream in OOUI
|
|
|
|
this.addTemplateInput.lookupMenu.width = this.addTemplateInput.$input[ 0 ].clientWidth;
|
|
|
|
};
|
|
|
|
|
2021-09-17 09:29:50 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2013-12-02 20:10:55 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage.prototype.onAddTemplate = function () {
|
2021-06-21 08:10:27 +00:00
|
|
|
var transclusion = this.placeholder.getTransclusion(),
|
2014-04-30 21:32:38 +00:00
|
|
|
menu = this.addTemplateInput.getLookupMenu();
|
2013-12-02 20:10:55 +00:00
|
|
|
|
2014-04-30 21:32:38 +00:00
|
|
|
if ( menu.isVisible() ) {
|
2018-01-17 13:38:10 +00:00
|
|
|
menu.chooseItem( menu.findSelectedItem() );
|
2014-04-30 21:32:38 +00:00
|
|
|
}
|
2021-06-21 08:10:27 +00:00
|
|
|
var name = this.addTemplateInput.getMWTitle();
|
2017-03-29 15:53:17 +00:00
|
|
|
if ( !name ) {
|
|
|
|
// Invalid titles return null, so abort here.
|
|
|
|
return;
|
|
|
|
}
|
2020-12-11 15:09:45 +00:00
|
|
|
|
|
|
|
// TODO tracking will only be implemented temporarily to answer questions on
|
|
|
|
// template usage for the Technical Wishes topic area see T258917
|
2021-06-21 08:10:27 +00:00
|
|
|
var event = {
|
2020-12-11 15:09:45 +00:00
|
|
|
action: 'add-template',
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
template_names: [ name.getPrefixedText() ]
|
2021-01-21 12:17:03 +00:00
|
|
|
};
|
2021-06-21 08:10:27 +00:00
|
|
|
var editCountBucket = mw.config.get( 'wgUserEditCountBucket' );
|
2021-01-21 12:17:03 +00:00
|
|
|
if ( editCountBucket !== null ) {
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
event.user_edit_count_bucket = editCountBucket;
|
|
|
|
}
|
|
|
|
mw.track( 'event.VisualEditorTemplateDialogUse', event );
|
2020-12-11 15:09:45 +00:00
|
|
|
|
2021-06-21 08:10:27 +00:00
|
|
|
var part = ve.dm.MWTemplateModel.newFromName( transclusion, name );
|
2014-02-05 19:11:41 +00:00
|
|
|
transclusion.replacePart( this.placeholder, part );
|
2013-12-02 20:10:55 +00:00
|
|
|
this.addTemplateInput.pushPending();
|
2017-04-12 16:34:42 +00:00
|
|
|
// abort pending lookups, also, so the menu can't appear after we've left the page
|
|
|
|
this.addTemplateInput.closeLookupMenu();
|
2013-12-02 20:10:55 +00:00
|
|
|
this.addTemplateButton.setDisabled( true );
|
2021-07-15 08:49:06 +00:00
|
|
|
if ( this.removeButton ) {
|
|
|
|
this.removeButton.setDisabled( true );
|
|
|
|
}
|
2013-12-02 20:10:55 +00:00
|
|
|
};
|
|
|
|
|
2021-09-17 09:29:50 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2014-10-30 16:24:04 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage.prototype.onTemplateInputChange = function () {
|
2018-01-18 17:39:23 +00:00
|
|
|
this.addTemplateButton.setDisabled( this.addTemplateInput.getMWTitle() === null );
|
2013-12-02 20:10:55 +00:00
|
|
|
};
|
|
|
|
|
2021-09-17 09:29:50 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2013-12-02 20:10:55 +00:00
|
|
|
ve.ui.MWTemplatePlaceholderPage.prototype.onRemoveButtonClick = function () {
|
|
|
|
this.placeholder.remove();
|
|
|
|
};
|