mediawiki-extensions-Visual.../modules/ve-mw/ui/pages/ve.ui.MWParameterPage.js

380 lines
10 KiB
JavaScript
Raw Normal View History

Refactor Transclusion and Meta dialogs to use BookletLayout Use OOJS-UI's newly-extended paged dialogs (in e08eb2a03b) to refactor how the Transclusion and Meta dialogs work, splitting out the code for each of the panels into its own file and simplifying extensibility. The Meta dialog (ve.ui.MWMetaDialog) now has two self-managing panels: * ve.ui.MWCategoriesPage for categories and the default sort key * ve.ui.MWLanguagesPage for language links The Transclusion dialog (ve.ui.MWTransclusionDialog) now has four: * ve.ui.MWTemplatePage for a template's primary panel * ve.ui.MWTemplateParameterPage for each parameter of a template * ve.ui.MWTemplatePlaceholderPage for a placeholder to insert a template * ve.ui.MWTransclusionContentPage for non-template transclusion Additionally, the Transclusion dialog has been slightly cleaned up: * Replace add/remove events with replace events in transclusion model * Actually return and resolve a promise (as documented) * Get rid of "origin" info in template models * Add method for adding required parts TODO: * Decide how and when we will choose between advanced transclusion and template dialogs * Work out design issues with how template descriptions will be visible and how adding parameters will work if only showing parameters in outline * Add preview to template dialog * Consider ways to further improve pages for use in continuous mode WARNING: * Right now the template dialog gets overridden by the advanced transclusion dialog because they have the same symbolic name and the latter is registered later than the former. To test the template dialog, just change the symbolic name of the advanced transclusion dialog. Change-Id: I51e74b322aec9a4c3918e6f792bdb3d318060979
2013-12-02 20:10:55 +00:00
/*!
* VisualEditor user interface MWParameterPage class.
Refactor Transclusion and Meta dialogs to use BookletLayout Use OOJS-UI's newly-extended paged dialogs (in e08eb2a03b) to refactor how the Transclusion and Meta dialogs work, splitting out the code for each of the panels into its own file and simplifying extensibility. The Meta dialog (ve.ui.MWMetaDialog) now has two self-managing panels: * ve.ui.MWCategoriesPage for categories and the default sort key * ve.ui.MWLanguagesPage for language links The Transclusion dialog (ve.ui.MWTransclusionDialog) now has four: * ve.ui.MWTemplatePage for a template's primary panel * ve.ui.MWTemplateParameterPage for each parameter of a template * ve.ui.MWTemplatePlaceholderPage for a placeholder to insert a template * ve.ui.MWTransclusionContentPage for non-template transclusion Additionally, the Transclusion dialog has been slightly cleaned up: * Replace add/remove events with replace events in transclusion model * Actually return and resolve a promise (as documented) * Get rid of "origin" info in template models * Add method for adding required parts TODO: * Decide how and when we will choose between advanced transclusion and template dialogs * Work out design issues with how template descriptions will be visible and how adding parameters will work if only showing parameters in outline * Add preview to template dialog * Consider ways to further improve pages for use in continuous mode WARNING: * Right now the template dialog gets overridden by the advanced transclusion dialog because they have the same symbolic name and the latter is registered later than the former. To test the template dialog, just change the symbolic name of the advanced transclusion dialog. Change-Id: I51e74b322aec9a4c3918e6f792bdb3d318060979
2013-12-02 20:10:55 +00:00
*
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
Refactor Transclusion and Meta dialogs to use BookletLayout Use OOJS-UI's newly-extended paged dialogs (in e08eb2a03b) to refactor how the Transclusion and Meta dialogs work, splitting out the code for each of the panels into its own file and simplifying extensibility. The Meta dialog (ve.ui.MWMetaDialog) now has two self-managing panels: * ve.ui.MWCategoriesPage for categories and the default sort key * ve.ui.MWLanguagesPage for language links The Transclusion dialog (ve.ui.MWTransclusionDialog) now has four: * ve.ui.MWTemplatePage for a template's primary panel * ve.ui.MWTemplateParameterPage for each parameter of a template * ve.ui.MWTemplatePlaceholderPage for a placeholder to insert a template * ve.ui.MWTransclusionContentPage for non-template transclusion Additionally, the Transclusion dialog has been slightly cleaned up: * Replace add/remove events with replace events in transclusion model * Actually return and resolve a promise (as documented) * Get rid of "origin" info in template models * Add method for adding required parts TODO: * Decide how and when we will choose between advanced transclusion and template dialogs * Work out design issues with how template descriptions will be visible and how adding parameters will work if only showing parameters in outline * Add preview to template dialog * Consider ways to further improve pages for use in continuous mode WARNING: * Right now the template dialog gets overridden by the advanced transclusion dialog because they have the same symbolic name and the latter is registered later than the former. To test the template dialog, just change the symbolic name of the advanced transclusion dialog. Change-Id: I51e74b322aec9a4c3918e6f792bdb3d318060979
2013-12-02 20:10:55 +00:00
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* MediaWiki transclusion dialog template page.
*
* @class
* @extends OO.ui.PageLayout
*
* @constructor
* @param {ve.dm.MWParameterModel} parameter Template parameter
Refactor Transclusion and Meta dialogs to use BookletLayout Use OOJS-UI's newly-extended paged dialogs (in e08eb2a03b) to refactor how the Transclusion and Meta dialogs work, splitting out the code for each of the panels into its own file and simplifying extensibility. The Meta dialog (ve.ui.MWMetaDialog) now has two self-managing panels: * ve.ui.MWCategoriesPage for categories and the default sort key * ve.ui.MWLanguagesPage for language links The Transclusion dialog (ve.ui.MWTransclusionDialog) now has four: * ve.ui.MWTemplatePage for a template's primary panel * ve.ui.MWTemplateParameterPage for each parameter of a template * ve.ui.MWTemplatePlaceholderPage for a placeholder to insert a template * ve.ui.MWTransclusionContentPage for non-template transclusion Additionally, the Transclusion dialog has been slightly cleaned up: * Replace add/remove events with replace events in transclusion model * Actually return and resolve a promise (as documented) * Get rid of "origin" info in template models * Add method for adding required parts TODO: * Decide how and when we will choose between advanced transclusion and template dialogs * Work out design issues with how template descriptions will be visible and how adding parameters will work if only showing parameters in outline * Add preview to template dialog * Consider ways to further improve pages for use in continuous mode WARNING: * Right now the template dialog gets overridden by the advanced transclusion dialog because they have the same symbolic name and the latter is registered later than the former. To test the template dialog, just change the symbolic name of the advanced transclusion dialog. Change-Id: I51e74b322aec9a4c3918e6f792bdb3d318060979
2013-12-02 20:10:55 +00:00
* @param {string} name Unique symbolic name of page
* @param {Object} [config] Configuration options
*/
ve.ui.MWParameterPage = function VeUiMWParameterPage( parameter, name, config ) {
var paramName = parameter.getName();
// Configuration initialization
config = ve.extendObject( {
scrollable: false
}, config );
Refactor Transclusion and Meta dialogs to use BookletLayout Use OOJS-UI's newly-extended paged dialogs (in e08eb2a03b) to refactor how the Transclusion and Meta dialogs work, splitting out the code for each of the panels into its own file and simplifying extensibility. The Meta dialog (ve.ui.MWMetaDialog) now has two self-managing panels: * ve.ui.MWCategoriesPage for categories and the default sort key * ve.ui.MWLanguagesPage for language links The Transclusion dialog (ve.ui.MWTransclusionDialog) now has four: * ve.ui.MWTemplatePage for a template's primary panel * ve.ui.MWTemplateParameterPage for each parameter of a template * ve.ui.MWTemplatePlaceholderPage for a placeholder to insert a template * ve.ui.MWTransclusionContentPage for non-template transclusion Additionally, the Transclusion dialog has been slightly cleaned up: * Replace add/remove events with replace events in transclusion model * Actually return and resolve a promise (as documented) * Get rid of "origin" info in template models * Add method for adding required parts TODO: * Decide how and when we will choose between advanced transclusion and template dialogs * Work out design issues with how template descriptions will be visible and how adding parameters will work if only showing parameters in outline * Add preview to template dialog * Consider ways to further improve pages for use in continuous mode WARNING: * Right now the template dialog gets overridden by the advanced transclusion dialog because they have the same symbolic name and the latter is registered later than the former. To test the template dialog, just change the symbolic name of the advanced transclusion dialog. Change-Id: I51e74b322aec9a4c3918e6f792bdb3d318060979
2013-12-02 20:10:55 +00:00
// Parent constructor
ve.ui.MWParameterPage.super.call( this, name, config );
Refactor Transclusion and Meta dialogs to use BookletLayout Use OOJS-UI's newly-extended paged dialogs (in e08eb2a03b) to refactor how the Transclusion and Meta dialogs work, splitting out the code for each of the panels into its own file and simplifying extensibility. The Meta dialog (ve.ui.MWMetaDialog) now has two self-managing panels: * ve.ui.MWCategoriesPage for categories and the default sort key * ve.ui.MWLanguagesPage for language links The Transclusion dialog (ve.ui.MWTransclusionDialog) now has four: * ve.ui.MWTemplatePage for a template's primary panel * ve.ui.MWTemplateParameterPage for each parameter of a template * ve.ui.MWTemplatePlaceholderPage for a placeholder to insert a template * ve.ui.MWTransclusionContentPage for non-template transclusion Additionally, the Transclusion dialog has been slightly cleaned up: * Replace add/remove events with replace events in transclusion model * Actually return and resolve a promise (as documented) * Get rid of "origin" info in template models * Add method for adding required parts TODO: * Decide how and when we will choose between advanced transclusion and template dialogs * Work out design issues with how template descriptions will be visible and how adding parameters will work if only showing parameters in outline * Add preview to template dialog * Consider ways to further improve pages for use in continuous mode WARNING: * Right now the template dialog gets overridden by the advanced transclusion dialog because they have the same symbolic name and the latter is registered later than the former. To test the template dialog, just change the symbolic name of the advanced transclusion dialog. Change-Id: I51e74b322aec9a4c3918e6f792bdb3d318060979
2013-12-02 20:10:55 +00:00
// Properties
this.edited = false;
Refactor Transclusion and Meta dialogs to use BookletLayout Use OOJS-UI's newly-extended paged dialogs (in e08eb2a03b) to refactor how the Transclusion and Meta dialogs work, splitting out the code for each of the panels into its own file and simplifying extensibility. The Meta dialog (ve.ui.MWMetaDialog) now has two self-managing panels: * ve.ui.MWCategoriesPage for categories and the default sort key * ve.ui.MWLanguagesPage for language links The Transclusion dialog (ve.ui.MWTransclusionDialog) now has four: * ve.ui.MWTemplatePage for a template's primary panel * ve.ui.MWTemplateParameterPage for each parameter of a template * ve.ui.MWTemplatePlaceholderPage for a placeholder to insert a template * ve.ui.MWTransclusionContentPage for non-template transclusion Additionally, the Transclusion dialog has been slightly cleaned up: * Replace add/remove events with replace events in transclusion model * Actually return and resolve a promise (as documented) * Get rid of "origin" info in template models * Add method for adding required parts TODO: * Decide how and when we will choose between advanced transclusion and template dialogs * Work out design issues with how template descriptions will be visible and how adding parameters will work if only showing parameters in outline * Add preview to template dialog * Consider ways to further improve pages for use in continuous mode WARNING: * Right now the template dialog gets overridden by the advanced transclusion dialog because they have the same symbolic name and the latter is registered later than the former. To test the template dialog, just change the symbolic name of the advanced transclusion dialog. Change-Id: I51e74b322aec9a4c3918e6f792bdb3d318060979
2013-12-02 20:10:55 +00:00
this.parameter = parameter;
this.originalValue = parameter.getValue();
this.spec = parameter.getTemplate().getSpec();
this.defaultValue = parameter.getDefaultValue();
this.exampleValue = parameter.getExampleValue();
this.$info = $( '<div>' );
this.$actions = $( '<div>' );
this.$labelElement = $( '<div>' );
this.$field = $( '<div>' );
this.$more = $( '<div>' );
this.$description = $( '<div>' );
this.rawFallbackButton = new OO.ui.ButtonWidget( {
framed: false,
icon: 'wikiText',
title: ve.msg( 'visualeditor-dialog-transclusion-raw-fallback' )
} ).connect( this, { click: 'onRawFallbackButtonClick' } );
this.valueInput = this.createValueInput()
.setValue( this.parameter.getValue() )
.connect( this, { change: 'onValueInputChange' } );
this.removeButton = new OO.ui.ButtonWidget( {
framed: false,
icon: 'remove',
title: ve.msg( 'visualeditor-dialog-transclusion-remove-param' ),
flags: [ 'destructive' ],
classes: [ 've-ui-mwParameterPage-removeButton' ]
} )
.connect( this, { click: 'onRemoveButtonClick' } )
.toggle( !this.parameter.isRequired() );
this.infoButton = new OO.ui.PopupButtonWidget( {
framed: false,
icon: 'info',
title: ve.msg( 'visualeditor-dialog-transclusion-param-info' ),
classes: [ 've-ui-mwParameterPage-infoButton' ]
} );
this.addButton = new OO.ui.ButtonWidget( {
framed: false,
icon: 'parameter',
label: ve.msg( 'visualeditor-dialog-transclusion-add-param' ),
tabIndex: -1
} )
.connect( this, { click: 'onAddButtonFocus' } );
this.statusIndicator = new OO.ui.IndicatorWidget( {
classes: [ 've-ui-mwParameterPage-statusIndicator' ]
} );
Refactor Transclusion and Meta dialogs to use BookletLayout Use OOJS-UI's newly-extended paged dialogs (in e08eb2a03b) to refactor how the Transclusion and Meta dialogs work, splitting out the code for each of the panels into its own file and simplifying extensibility. The Meta dialog (ve.ui.MWMetaDialog) now has two self-managing panels: * ve.ui.MWCategoriesPage for categories and the default sort key * ve.ui.MWLanguagesPage for language links The Transclusion dialog (ve.ui.MWTransclusionDialog) now has four: * ve.ui.MWTemplatePage for a template's primary panel * ve.ui.MWTemplateParameterPage for each parameter of a template * ve.ui.MWTemplatePlaceholderPage for a placeholder to insert a template * ve.ui.MWTransclusionContentPage for non-template transclusion Additionally, the Transclusion dialog has been slightly cleaned up: * Replace add/remove events with replace events in transclusion model * Actually return and resolve a promise (as documented) * Get rid of "origin" info in template models * Add method for adding required parts TODO: * Decide how and when we will choose between advanced transclusion and template dialogs * Work out design issues with how template descriptions will be visible and how adding parameters will work if only showing parameters in outline * Add preview to template dialog * Consider ways to further improve pages for use in continuous mode WARNING: * Right now the template dialog gets overridden by the advanced transclusion dialog because they have the same symbolic name and the latter is registered later than the former. To test the template dialog, just change the symbolic name of the advanced transclusion dialog. Change-Id: I51e74b322aec9a4c3918e6f792bdb3d318060979
2013-12-02 20:10:55 +00:00
// Events
this.$labelElement.on( 'click', this.onLabelClick.bind( this ) );
Refactor Transclusion and Meta dialogs to use BookletLayout Use OOJS-UI's newly-extended paged dialogs (in e08eb2a03b) to refactor how the Transclusion and Meta dialogs work, splitting out the code for each of the panels into its own file and simplifying extensibility. The Meta dialog (ve.ui.MWMetaDialog) now has two self-managing panels: * ve.ui.MWCategoriesPage for categories and the default sort key * ve.ui.MWLanguagesPage for language links The Transclusion dialog (ve.ui.MWTransclusionDialog) now has four: * ve.ui.MWTemplatePage for a template's primary panel * ve.ui.MWTemplateParameterPage for each parameter of a template * ve.ui.MWTemplatePlaceholderPage for a placeholder to insert a template * ve.ui.MWTransclusionContentPage for non-template transclusion Additionally, the Transclusion dialog has been slightly cleaned up: * Replace add/remove events with replace events in transclusion model * Actually return and resolve a promise (as documented) * Get rid of "origin" info in template models * Add method for adding required parts TODO: * Decide how and when we will choose between advanced transclusion and template dialogs * Work out design issues with how template descriptions will be visible and how adding parameters will work if only showing parameters in outline * Add preview to template dialog * Consider ways to further improve pages for use in continuous mode WARNING: * Right now the template dialog gets overridden by the advanced transclusion dialog because they have the same symbolic name and the latter is registered later than the former. To test the template dialog, just change the symbolic name of the advanced transclusion dialog. Change-Id: I51e74b322aec9a4c3918e6f792bdb3d318060979
2013-12-02 20:10:55 +00:00
// Initialization
this.$info
.addClass( 've-ui-mwParameterPage-info' )
.append( this.$labelElement, this.statusIndicator.$element );
this.$actions
.addClass( 've-ui-mwParameterPage-actions' )
.append(
this.rawFallbackButton.$element,
this.infoButton.$element,
this.removeButton.$element
);
this.$labelElement
.addClass( 've-ui-mwParameterPage-label' )
.text( this.spec.getParameterLabel( paramName ) );
this.$field
.addClass( 've-ui-mwParameterPage-field' )
.append(
this.valueInput.$element
);
this.$more
.addClass( 've-ui-mwParameterPage-more' )
.append( this.addButton.$element );
this.$element
.addClass( 've-ui-mwParameterPage' )
.append( this.$info, this.$field, this.$actions, this.$more );
this.$description
.addClass( 've-ui-mwParameterPage-description' )
.append( $( '<p>' ).text( this.spec.getParameterDescription( paramName ) || '' ) );
if ( this.parameter.isRequired() ) {
this.statusIndicator
.setIndicator( 'required' )
.setIndicatorTitle(
ve.msg( 'visualeditor-dialog-transclusion-required-parameter' )
);
this.$description.append(
$( '<p>' )
.addClass( 've-ui-mwParameterPage-description-required' )
.text(
ve.msg( 'visualeditor-dialog-transclusion-required-parameter-description' )
)
);
} else if ( this.parameter.isDeprecated() ) {
this.statusIndicator
.setIndicator( 'alert' )
.setIndicatorTitle(
ve.msg( 'visualeditor-dialog-transclusion-deprecated-parameter' )
);
this.$description.append(
$( '<p>' )
.addClass( 've-ui-mwParameterPage-description-deprecated' )
.text(
ve.msg(
'visualeditor-dialog-transclusion-deprecated-parameter-description',
this.spec.getParameterDeprecationDescription( paramName )
)
)
);
}
if ( this.defaultValue ) {
this.$description.append(
$( '<p>' )
.addClass( 've-ui-mwParameterPage-description-default' )
.text(
ve.msg( 'visualeditor-dialog-transclusion-param-default', this.defaultValue )
)
);
}
if ( this.exampleValue ) {
this.$description.append(
$( '<p>' )
.addClass( 've-ui-mwParameterPage-description-example' )
.text(
ve.msg( 'visualeditor-dialog-transclusion-param-example', this.exampleValue )
)
);
}
if ( this.$description.text().trim() === '' ) {
this.infoButton
.setDisabled( true )
.setTitle(
ve.msg( 'visualeditor-dialog-transclusion-param-info-missing' )
);
} else {
this.infoButton.getPopup().$body.append( this.$description );
}
Refactor Transclusion and Meta dialogs to use BookletLayout Use OOJS-UI's newly-extended paged dialogs (in e08eb2a03b) to refactor how the Transclusion and Meta dialogs work, splitting out the code for each of the panels into its own file and simplifying extensibility. The Meta dialog (ve.ui.MWMetaDialog) now has two self-managing panels: * ve.ui.MWCategoriesPage for categories and the default sort key * ve.ui.MWLanguagesPage for language links The Transclusion dialog (ve.ui.MWTransclusionDialog) now has four: * ve.ui.MWTemplatePage for a template's primary panel * ve.ui.MWTemplateParameterPage for each parameter of a template * ve.ui.MWTemplatePlaceholderPage for a placeholder to insert a template * ve.ui.MWTransclusionContentPage for non-template transclusion Additionally, the Transclusion dialog has been slightly cleaned up: * Replace add/remove events with replace events in transclusion model * Actually return and resolve a promise (as documented) * Get rid of "origin" info in template models * Add method for adding required parts TODO: * Decide how and when we will choose between advanced transclusion and template dialogs * Work out design issues with how template descriptions will be visible and how adding parameters will work if only showing parameters in outline * Add preview to template dialog * Consider ways to further improve pages for use in continuous mode WARNING: * Right now the template dialog gets overridden by the advanced transclusion dialog because they have the same symbolic name and the latter is registered later than the former. To test the template dialog, just change the symbolic name of the advanced transclusion dialog. Change-Id: I51e74b322aec9a4c3918e6f792bdb3d318060979
2013-12-02 20:10:55 +00:00
};
/* Inheritance */
OO.inheritClass( ve.ui.MWParameterPage, OO.ui.PageLayout );
Refactor Transclusion and Meta dialogs to use BookletLayout Use OOJS-UI's newly-extended paged dialogs (in e08eb2a03b) to refactor how the Transclusion and Meta dialogs work, splitting out the code for each of the panels into its own file and simplifying extensibility. The Meta dialog (ve.ui.MWMetaDialog) now has two self-managing panels: * ve.ui.MWCategoriesPage for categories and the default sort key * ve.ui.MWLanguagesPage for language links The Transclusion dialog (ve.ui.MWTransclusionDialog) now has four: * ve.ui.MWTemplatePage for a template's primary panel * ve.ui.MWTemplateParameterPage for each parameter of a template * ve.ui.MWTemplatePlaceholderPage for a placeholder to insert a template * ve.ui.MWTransclusionContentPage for non-template transclusion Additionally, the Transclusion dialog has been slightly cleaned up: * Replace add/remove events with replace events in transclusion model * Actually return and resolve a promise (as documented) * Get rid of "origin" info in template models * Add method for adding required parts TODO: * Decide how and when we will choose between advanced transclusion and template dialogs * Work out design issues with how template descriptions will be visible and how adding parameters will work if only showing parameters in outline * Add preview to template dialog * Consider ways to further improve pages for use in continuous mode WARNING: * Right now the template dialog gets overridden by the advanced transclusion dialog because they have the same symbolic name and the latter is registered later than the former. To test the template dialog, just change the symbolic name of the advanced transclusion dialog. Change-Id: I51e74b322aec9a4c3918e6f792bdb3d318060979
2013-12-02 20:10:55 +00:00
/* Methods */
/**
* Get default configuration for an input widget.
*
* @private
* @return {Object}
*/
ve.ui.MWParameterPage.prototype.getDefaultInputConfig = function () {
var required = this.parameter.isRequired(),
valueInputConfig = {
autosize: true,
required: required,
validate: required ? 'non-empty' : null
};
if ( this.defaultValue ) {
valueInputConfig.placeholder = ve.msg(
'visualeditor-dialog-transclusion-param-default',
this.defaultValue
);
} else if ( this.exampleValue ) {
valueInputConfig.placeholder = ve.msg(
'visualeditor-dialog-transclusion-param-example',
this.exampleValue
);
}
return valueInputConfig;
};
/**
* Create a value input widget based on the parameter type and whether it is
* required or not.
*
* @return {OO.ui.InputWidget}
*/
ve.ui.MWParameterPage.prototype.createValueInput = function () {
var type = this.parameter.getType(),
value = this.parameter.getValue(),
valueInputConfig = this.getDefaultInputConfig();
this.rawValueInput = false;
delete valueInputConfig.validate;
// TODO:
// * wiki-file-name
// * date - T100206
// * number - T124850
// * unbalanced-wikitext/content - T106242
// * string? - T124917
if (
type === 'wiki-page-name' &&
( value === '' || mw.Title.newFromText( value ) )
) {
return new mw.widgets.TitleInputWidget( valueInputConfig );
} else if (
type === 'wiki-user-name' &&
( value === '' || mw.Title.newFromText( value ) )
) {
valueInputConfig.validate = function ( value ) {
// TODO: Check against wgMaxNameChars
// TODO: Check against unicode blacklist regex from MW core's User::isValidUserName
return !!mw.Title.newFromText( value );
};
return new mw.widgets.UserInputWidget( valueInputConfig );
} else if (
type === 'wiki-template-name' &&
( value === '' || mw.Title.newFromText( value ) )
) {
return new mw.widgets.TitleInputWidget( $.extend( {}, valueInputConfig, {
namespace: mw.config.get( 'wgNamespaceIds' ).template
} ) );
} else if ( type === 'boolean' && ( value === '1' || value === '0' ) ) {
return new ve.ui.MWParameterCheckboxInputWidget( valueInputConfig );
} else if (
type === 'url' &&
(
value === '' ||
ve.init.platform.getExternalLinkUrlProtocolsRegExp().exec( value.trim() )
)
) {
return ve.ui.MWExternalLinkAnnotationWidget.static.createExternalLinkInputWidget( valueInputConfig );
} else if ( type !== 'line' ) {
this.rawValueInput = true;
valueInputConfig.multiline = true;
this.rawFallbackButton.$element.detach();
}
return new OO.ui.TextInputWidget( valueInputConfig );
};
/**
* Check if the parameter is empty
*
* @return {boolean} The parameter is empty
*/
ve.ui.MWParameterPage.prototype.isEmpty = function () {
return this.valueInput.getValue() === '' && this.defaultValue === '';
};
/**
* Handle change events from the value input
*
* @param {string} value Value
*/
ve.ui.MWParameterPage.prototype.onValueInputChange = function () {
var value = this.valueInput.getValue();
this.edited = true;
this.parameter.setValue( value );
if ( this.outlineItem ) {
this.outlineItem.setFlags( { empty: this.isEmpty() } );
}
};
/**
* Handle click events from the remove button
*/
ve.ui.MWParameterPage.prototype.onRemoveButtonClick = function () {
this.parameter.remove();
};
/**
* Handle click events from the raw fallback button
*/
ve.ui.MWParameterPage.prototype.onRawFallbackButtonClick = function () {
this.valueInput.$element.detach();
if ( this.rawValueInput ) {
this.valueInput = this.createValueInput()
.setValue( this.valueInput.getValue() );
} else {
this.valueInput = new OO.ui.TextInputWidget( this.getDefaultInputConfig() )
.setValue( this.edited ? this.valueInput.getValue() : this.originalValue );
this.valueInput.$input.addClass( 've-ui-mwParameter-wikitextFallbackInput' );
this.rawValueInput = true;
}
this.valueInput.connect( this, { change: 'onValueInputChange' } );
this.$field.append( this.valueInput.$element );
};
/**
* Handle click events from the add button
*/
ve.ui.MWParameterPage.prototype.onAddButtonFocus = function () {
var template = this.parameter.getTemplate();
template.addParameter( new ve.dm.MWParameterModel( template ) );
};
/**
* Handle click events from the label element
*
* @param {jQuery.Event} e Click event
*/
ve.ui.MWParameterPage.prototype.onLabelClick = function () {
this.valueInput.simulateLabelClick();
};
/**
* @inheritdoc
*/
ve.ui.MWParameterPage.prototype.setOutlineItem = function () {
// Parent method
ve.ui.MWParameterPage.super.prototype.setOutlineItem.apply( this, arguments );
if ( this.outlineItem ) {
this.outlineItem
.setIcon( 'parameter' )
.setMovable( false )
.setRemovable( true )
.setLevel( 1 )
.setFlags( { empty: this.isEmpty() } )
.setLabel( this.spec.getParameterLabel( this.parameter.getName() ) );
if ( this.parameter.isRequired() ) {
this.outlineItem
.setIndicator( 'required' )
.setIndicatorTitle(
ve.msg( 'visualeditor-dialog-transclusion-required-parameter' )
);
}
if ( this.parameter.isDeprecated() ) {
this.outlineItem
.setIndicator( 'alert' )
.setIndicatorTitle(
ve.msg( 'visualeditor-dialog-transclusion-deprecated-parameter' )
);
}
}
};
/**
* @inheritdoc
*/
ve.ui.MWParameterPage.prototype.focus = function () {
this.valueInput.focus();
};