2021-05-17 15:43:49 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWTemplateOutlineTemplateWidget class.
|
|
|
|
*
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Container for template, as rendered in the template dialog sidebar.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.Widget
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateOutlineTemplateWidget = function VeUiMWTemplateOutlineTemplateWidget( config ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWTemplateOutlineTemplateWidget.super.call( this, config );
|
|
|
|
|
|
|
|
// Initialization
|
2021-06-17 11:20:50 +00:00
|
|
|
this.templateModel = config.templateModel.connect( this, {
|
|
|
|
add: 'onAddParameter'
|
|
|
|
// remove: 'onRemoveParameter'
|
|
|
|
} );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
2021-06-21 14:19:03 +00:00
|
|
|
var widget = this;
|
|
|
|
var checkboxes = this.templateModel.getAllParametersOrdered().filter( function ( parameter ) {
|
|
|
|
return parameter !== '';
|
|
|
|
} ).map( function ( parameter ) {
|
|
|
|
return widget.createCheckbox( parameter );
|
|
|
|
} );
|
|
|
|
|
|
|
|
var addParameterButton = new OO.ui.ButtonWidget( {
|
|
|
|
framed: false,
|
|
|
|
icon: 'parameter',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-transclusion-add-param' ),
|
|
|
|
classes: [ 've-ui-templateOutlineItem' ]
|
|
|
|
} );
|
|
|
|
|
2021-06-21 10:35:50 +00:00
|
|
|
var templateLabel = new OO.ui.Layout( {
|
|
|
|
classes: [ 've-ui-templateOutlineTemplateLabel' ],
|
|
|
|
content: [
|
|
|
|
new OO.ui.IconWidget( {
|
|
|
|
icon: 'puzzle'
|
|
|
|
} ),
|
|
|
|
new OO.ui.LabelWidget( {
|
|
|
|
label: config.templateModel.getSpec().getLabel()
|
|
|
|
} )
|
|
|
|
]
|
|
|
|
} );
|
|
|
|
|
2021-06-21 09:20:03 +00:00
|
|
|
this.parameters = new OO.ui.FieldsetLayout( {
|
2021-06-17 11:20:50 +00:00
|
|
|
items: checkboxes
|
2021-05-17 15:43:49 +00:00
|
|
|
} );
|
|
|
|
var layout = new OO.ui.Layout( {
|
|
|
|
// TODO: template title and icon
|
2021-06-17 11:20:50 +00:00
|
|
|
items: [ this.parameters ]
|
2021-05-17 15:43:49 +00:00
|
|
|
} );
|
|
|
|
layout.$element
|
2021-06-21 10:35:50 +00:00
|
|
|
.append( templateLabel.$element, this.parameters.$element, addParameterButton.$element );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
|
|
|
this.$element
|
|
|
|
.append( layout.$element )
|
|
|
|
.addClass( 've-ui-mwTemplateDialogOutlineTemplate' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWTemplateOutlineTemplateWidget, OO.ui.Widget );
|
2021-06-17 11:20:50 +00:00
|
|
|
|
|
|
|
ve.ui.MWTemplateOutlineTemplateWidget.prototype.createCheckbox = function ( name ) {
|
|
|
|
var parameterModel = this.templateModel.getParameter( name );
|
|
|
|
var isPresent = !!parameterModel;
|
|
|
|
if ( !parameterModel ) {
|
|
|
|
// TODO: Streamline, don't create a temporary parameter model?
|
|
|
|
parameterModel = new ve.dm.MWParameterModel( this.templateModel, name );
|
|
|
|
}
|
|
|
|
return new ve.ui.MWTemplateOutlineParameterCheckboxLayout( {
|
|
|
|
required: parameterModel.isRequired(),
|
|
|
|
label: parameterModel.getName(),
|
|
|
|
selected: isPresent
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWTemplateOutlineTemplateWidget.prototype.onAddParameter = function ( /* parameter */ ) {
|
|
|
|
// Note: this is not called when initially populating the template, we attach to its events too late.
|
|
|
|
};
|