2021-05-17 15:43:49 +00:00
|
|
|
/*!
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Container for template, as rendered in the template dialog sidebar.
|
|
|
|
*
|
|
|
|
* @class
|
2021-07-09 15:04:14 +00:00
|
|
|
* @extends ve.ui.MWTransclusionOutlinePartWidget
|
2021-05-17 15:43:49 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2021-07-09 15:33:16 +00:00
|
|
|
* @param {ve.dm.MWTemplateModel} template
|
2022-02-22 10:37:21 +00:00
|
|
|
* @param {boolean} [replacesPlaceholder]
|
2022-02-08 17:11:51 +00:00
|
|
|
* @property {ve.dm.MWTemplateModel} templateModel
|
|
|
|
* @property {ve.ui.MWTransclusionOutlineParameterSelectWidget} parameterList
|
2021-05-17 15:43:49 +00:00
|
|
|
*/
|
2022-02-22 10:37:21 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget = function VeUiMWTransclusionOutlineTemplateWidget( template, replacesPlaceholder ) {
|
2021-08-04 14:34:54 +00:00
|
|
|
var spec = template.getSpec();
|
|
|
|
|
2021-07-13 09:00:57 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.super.call( this, template, {
|
2021-07-09 14:47:01 +00:00
|
|
|
icon: 'puzzle',
|
2021-10-27 09:39:03 +00:00
|
|
|
label: spec.getLabel(),
|
2021-11-15 10:01:52 +00:00
|
|
|
ariaDescriptionUnselected: ve.msg( 'visualeditor-dialog-transclusion-template-widget-aria' ),
|
2021-10-27 09:39:03 +00:00
|
|
|
ariaDescriptionSelected: ve.msg( 'visualeditor-dialog-transclusion-template-widget-aria-selected' ),
|
2022-01-14 16:18:00 +00:00
|
|
|
ariaDescriptionSelectedSingle: ve.msg( 'visualeditor-dialog-transclusion-template-widget-aria-selected-single' )
|
2021-07-13 09:00:57 +00:00
|
|
|
} );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
|
|
|
// Initialization
|
2021-07-09 15:33:16 +00:00
|
|
|
this.templateModel = template.connect( this, {
|
2021-08-26 14:29:42 +00:00
|
|
|
add: 'onParameterAddedToTemplateModel',
|
|
|
|
remove: 'onParameterRemovedFromTemplateModel'
|
2021-06-17 11:20:50 +00:00
|
|
|
} );
|
2021-05-17 15:43:49 +00:00
|
|
|
|
2022-02-08 17:11:51 +00:00
|
|
|
var initiallyHideUnused = !replacesPlaceholder && !this.transclusionModel.isSingleTemplate();
|
|
|
|
this.initializeParameterList( initiallyHideUnused );
|
|
|
|
this.toggleFilters( initiallyHideUnused );
|
2022-01-14 16:39:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWTransclusionOutlineTemplateWidget, ve.ui.MWTransclusionOutlinePartWidget );
|
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event focusTemplateParameterById
|
|
|
|
* @param {string} pageName Unique id of the {@see OO.ui.BookletLayout} page, e.g. something like
|
|
|
|
* "part_1" or "part_1/param1".
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggered when the user uses the search widget at the top to filter the list of parameters.
|
|
|
|
*
|
|
|
|
* @event filterParametersById
|
|
|
|
* @param {Object.<string,boolean>} visibility Keyed by unique id of the parameter, e.g. something
|
|
|
|
* like "part_1/param1". Note this lists only parameters that are currently shown as a checkbox.
|
|
|
|
* The spec might contain more parameters (e.g. deprecated).
|
|
|
|
*/
|
|
|
|
|
2022-01-21 14:47:31 +00:00
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Minimum number of parameters required before search and filter options appear.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @property {number}
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.static.searchableParameterCount = 4;
|
|
|
|
|
2022-01-14 16:39:09 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
2022-02-08 17:11:51 +00:00
|
|
|
* @param {boolean} [initiallyHideUnused=false]
|
2022-01-14 16:39:09 +00:00
|
|
|
*/
|
2022-02-08 17:11:51 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.initializeParameterList = function ( initiallyHideUnused ) {
|
2022-01-21 14:47:31 +00:00
|
|
|
if ( this.parameterList ) {
|
2022-01-14 16:39:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-08 17:11:51 +00:00
|
|
|
var parameterNames = this.getRelevantTemplateParameters( initiallyHideUnused ? 'used' : 'all' );
|
2022-01-14 16:39:09 +00:00
|
|
|
if ( !parameterNames.length ) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-21 14:19:03 +00:00
|
|
|
|
2021-10-31 10:08:13 +00:00
|
|
|
var $parametersAriaDescription = $( '<span>' )
|
|
|
|
.text( ve.msg( 'visualeditor-dialog-transclusion-param-selection-aria-description' ) )
|
|
|
|
.addClass( 've-ui-mwTransclusionOutline-ariaHidden' );
|
|
|
|
|
2022-01-21 14:47:31 +00:00
|
|
|
this.parameterList = new ve.ui.MWTransclusionOutlineParameterSelectWidget( {
|
2021-10-31 10:08:13 +00:00
|
|
|
items: parameterNames.map( this.createCheckbox.bind( this ) ),
|
2022-02-08 17:11:51 +00:00
|
|
|
ariaLabel: ve.msg( 'visualeditor-dialog-transclusion-param-selection-aria-label', this.templateModel.getSpec().getLabel() ),
|
2022-01-12 14:05:07 +00:00
|
|
|
$ariaDescribedBy: $parametersAriaDescription
|
|
|
|
} ).connect( this, {
|
|
|
|
choose: 'onTemplateParameterChoose',
|
|
|
|
templateParameterSelectionChanged: 'onTemplateParameterSelectionChanged',
|
|
|
|
change: 'onParameterWidgetListChanged'
|
|
|
|
} );
|
2021-07-20 10:36:23 +00:00
|
|
|
|
|
|
|
this.$element.append(
|
2021-10-31 10:08:13 +00:00
|
|
|
$parametersAriaDescription,
|
2022-01-21 14:47:31 +00:00
|
|
|
this.parameterList.$element
|
2021-07-20 10:36:23 +00:00
|
|
|
);
|
2021-05-17 15:43:49 +00:00
|
|
|
};
|
|
|
|
|
2022-02-08 17:11:51 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.createAllParameterCheckboxes = function () {
|
|
|
|
if ( !this.parameterListComplete ) {
|
|
|
|
var self = this;
|
|
|
|
this.initializeParameterList();
|
|
|
|
this.getRelevantTemplateParameters().forEach( function ( paramName ) {
|
|
|
|
if ( !self.parameterList.findItemFromData( paramName ) ) {
|
|
|
|
self.parameterList.addItems(
|
|
|
|
[ self.createCheckbox( paramName ) ],
|
|
|
|
self.findCanonicalPosition( paramName )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
this.parameterListComplete = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {string} [filter='all'] Either "used", "unused", or "all"
|
|
|
|
* @return {string[]}
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.getRelevantTemplateParameters = function ( filter ) {
|
|
|
|
var parameterNames,
|
|
|
|
template = this.templateModel;
|
|
|
|
|
|
|
|
switch ( filter ) {
|
|
|
|
case 'used':
|
|
|
|
parameterNames = template.getOrderedParameterNames();
|
|
|
|
break;
|
|
|
|
case 'unused':
|
|
|
|
parameterNames = template.getAllParametersOrdered().filter( function ( name ) {
|
|
|
|
return !( name in template.getParameters() );
|
|
|
|
} );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
parameterNames = template.getAllParametersOrdered();
|
|
|
|
}
|
|
|
|
|
|
|
|
return parameterNames.filter( function ( name ) {
|
|
|
|
// Don't offer deprecated parameters, unless they are already used
|
|
|
|
if ( template.getSpec().isParameterDeprecated( name ) && !template.hasParameter( name ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Never create a checkbox for a ve.ui.MWParameterPlaceholderPage placeholder
|
|
|
|
return !!name;
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2021-06-29 19:45:09 +00:00
|
|
|
/**
|
2021-08-13 14:41:48 +00:00
|
|
|
* @private
|
2021-09-03 14:26:43 +00:00
|
|
|
* @param {string} paramName Parameter name or alias as used in the model
|
2021-08-26 14:29:42 +00:00
|
|
|
* @return {OO.ui.OptionWidget}
|
2021-06-29 19:45:09 +00:00
|
|
|
*/
|
2021-07-13 19:01:30 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.createCheckbox = function ( paramName ) {
|
|
|
|
var spec = this.templateModel.getSpec();
|
2021-08-26 14:29:42 +00:00
|
|
|
return ve.ui.MWTransclusionOutlineParameterSelectWidget.static.createItem( {
|
2021-07-13 19:01:30 +00:00
|
|
|
required: spec.isParameterRequired( paramName ),
|
|
|
|
label: spec.getParameterLabel( paramName ),
|
|
|
|
data: paramName,
|
|
|
|
selected: this.templateModel.hasParameter( paramName )
|
2021-06-17 11:20:50 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2021-08-06 13:05:54 +00:00
|
|
|
/**
|
2021-08-13 14:41:48 +00:00
|
|
|
* @private
|
2021-08-26 14:29:42 +00:00
|
|
|
* @param {string} paramName
|
|
|
|
* @return {number}
|
2021-08-06 13:05:54 +00:00
|
|
|
*/
|
2021-08-26 14:29:42 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.findCanonicalPosition = function ( paramName ) {
|
|
|
|
var insertAt = 0,
|
2021-08-06 13:05:54 +00:00
|
|
|
// Note this might include parameters that don't have a checkbox, e.g. deprecated
|
|
|
|
allParamNames = this.templateModel.getAllParametersOrdered();
|
|
|
|
for ( var i = 0; i < allParamNames.length; i++ ) {
|
2022-01-21 14:47:31 +00:00
|
|
|
if ( allParamNames[ i ] === paramName || !this.parameterList.items[ insertAt ] ) {
|
2021-08-06 13:05:54 +00:00
|
|
|
break;
|
2022-01-21 14:47:31 +00:00
|
|
|
} else if ( this.parameterList.items[ insertAt ].getData() === allParamNames[ i ] ) {
|
2021-08-06 13:05:54 +00:00
|
|
|
insertAt++;
|
|
|
|
}
|
|
|
|
}
|
2021-08-26 14:29:42 +00:00
|
|
|
return insertAt;
|
2021-08-06 13:05:54 +00:00
|
|
|
};
|
|
|
|
|
2021-09-01 09:15:37 +00:00
|
|
|
/**
|
2021-09-23 11:26:25 +00:00
|
|
|
* @param {string} [paramName] Parameter name to highlight, e.g. "param1". Omit for no highlight.
|
2021-09-01 09:15:37 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.highlightParameter = function ( paramName ) {
|
2022-01-21 14:47:31 +00:00
|
|
|
if ( this.parameterList ) {
|
|
|
|
this.parameterList.highlightParameter( paramName );
|
2022-01-14 16:39:09 +00:00
|
|
|
}
|
2021-09-01 09:15:37 +00:00
|
|
|
};
|
|
|
|
|
2021-09-23 11:26:25 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.setSelected = function ( state ) {
|
2022-01-21 14:47:31 +00:00
|
|
|
if ( !state && this.isSelected() && this.parameterList ) {
|
|
|
|
this.parameterList.highlightItem();
|
2021-09-23 11:26:25 +00:00
|
|
|
}
|
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.super.prototype.setSelected.call( this, state );
|
2021-09-09 12:11:36 +00:00
|
|
|
};
|
|
|
|
|
2021-06-29 19:45:09 +00:00
|
|
|
/**
|
2021-08-13 14:41:48 +00:00
|
|
|
* @private
|
2021-07-13 19:01:30 +00:00
|
|
|
* @param {ve.dm.MWParameterModel} param
|
2021-06-29 19:45:09 +00:00
|
|
|
*/
|
2021-08-26 14:29:42 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onParameterAddedToTemplateModel = function ( param ) {
|
2021-08-05 10:11:40 +00:00
|
|
|
var paramName = param.getName();
|
|
|
|
// The placeholder (currently) doesn't get a corresponding item in the sidebar
|
|
|
|
if ( !paramName ) {
|
|
|
|
return;
|
|
|
|
}
|
2021-07-13 19:01:30 +00:00
|
|
|
|
2022-01-21 14:47:31 +00:00
|
|
|
this.initializeParameterList();
|
2022-01-14 16:39:09 +00:00
|
|
|
|
2021-07-13 19:01:30 +00:00
|
|
|
// All parameters known via the spec already have a checkbox
|
2022-01-21 14:47:31 +00:00
|
|
|
var item = this.parameterList.findItemFromData( paramName );
|
2022-02-03 12:30:29 +00:00
|
|
|
if ( item ) {
|
|
|
|
// Reset the "hide unused" filter for this field, it's going to be used
|
|
|
|
item.toggle( true );
|
|
|
|
} else {
|
2021-08-26 14:29:42 +00:00
|
|
|
item = this.createCheckbox( paramName );
|
2022-01-21 14:47:31 +00:00
|
|
|
this.parameterList.addItems( [ item ], this.findCanonicalPosition( paramName ) );
|
2021-08-26 14:29:42 +00:00
|
|
|
|
2022-01-21 14:47:31 +00:00
|
|
|
this.toggleFilters();
|
2022-01-20 12:05:09 +00:00
|
|
|
|
2021-08-05 10:11:40 +00:00
|
|
|
// Make sure an active filter is applied to the new checkbox as well
|
2022-01-14 16:18:00 +00:00
|
|
|
var filter = this.searchWidget && this.searchWidget.getValue();
|
2021-08-05 10:11:40 +00:00
|
|
|
if ( filter ) {
|
2021-08-06 13:05:54 +00:00
|
|
|
this.filterParameters( filter );
|
2021-08-05 10:11:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-26 14:29:42 +00:00
|
|
|
item.setSelected( true, true );
|
2021-08-05 10:11:40 +00:00
|
|
|
|
|
|
|
// Reset filter, but only if it hides the relevant checkbox
|
2021-08-26 14:29:42 +00:00
|
|
|
if ( !item.isVisible() ) {
|
2021-07-20 10:36:23 +00:00
|
|
|
this.searchWidget.setValue( '' );
|
2021-06-18 15:23:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-29 19:45:09 +00:00
|
|
|
/**
|
2021-08-13 14:41:48 +00:00
|
|
|
* @private
|
2021-07-13 19:01:30 +00:00
|
|
|
* @param {ve.dm.MWParameterModel} param
|
2021-06-29 19:45:09 +00:00
|
|
|
*/
|
2021-08-26 14:29:42 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onParameterRemovedFromTemplateModel = function ( param ) {
|
2022-01-21 14:47:31 +00:00
|
|
|
this.parameterList.markParameterAsUnused( param.getName() );
|
2021-06-18 15:23:35 +00:00
|
|
|
};
|
|
|
|
|
2021-06-29 19:45:09 +00:00
|
|
|
/**
|
2021-08-13 14:41:48 +00:00
|
|
|
* @private
|
2021-08-26 14:29:42 +00:00
|
|
|
* @param {OO.ui.OptionWidget} item
|
2021-08-17 06:35:13 +00:00
|
|
|
* @param {boolean} selected
|
2021-09-07 15:53:37 +00:00
|
|
|
* @fires focusTemplateParameterById
|
2021-06-29 19:45:09 +00:00
|
|
|
*/
|
2021-08-31 08:05:25 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onTemplateParameterChoose = function ( item, selected ) {
|
2021-09-07 15:53:37 +00:00
|
|
|
this.onTemplateParameterSelectionChanged( item, selected );
|
|
|
|
|
|
|
|
var param = this.templateModel.getParameter( item.getData() );
|
2021-10-20 14:39:43 +00:00
|
|
|
if ( param && selected ) {
|
2021-09-07 15:53:37 +00:00
|
|
|
this.emit( 'focusTemplateParameterById', param.getId() );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {OO.ui.OptionWidget} item
|
|
|
|
* @param {boolean} selected
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onTemplateParameterSelectionChanged = function ( item, selected ) {
|
2021-08-26 14:29:42 +00:00
|
|
|
var paramName = item.getData(),
|
2021-08-16 16:17:14 +00:00
|
|
|
param = this.templateModel.getParameter( paramName );
|
2021-08-17 06:35:13 +00:00
|
|
|
if ( !selected ) {
|
2021-07-13 19:01:30 +00:00
|
|
|
this.templateModel.removeParameter( param );
|
|
|
|
} else if ( !param ) {
|
2021-09-10 14:20:51 +00:00
|
|
|
param = new ve.dm.MWParameterModel( this.templateModel, paramName );
|
|
|
|
this.templateModel.addParameter( param );
|
2021-07-13 19:01:30 +00:00
|
|
|
}
|
2022-02-04 11:06:54 +00:00
|
|
|
|
|
|
|
this.updateUnusedParameterToggleState();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.updateUnusedParameterToggleState = function () {
|
|
|
|
if ( this.toggleUnusedWidget ) {
|
2022-02-08 17:11:51 +00:00
|
|
|
this.toggleUnusedWidget.setDisabled( !this.getRelevantTemplateParameters( 'unused' ).length );
|
2022-02-04 11:06:54 +00:00
|
|
|
}
|
2021-07-13 19:01:30 +00:00
|
|
|
};
|
2021-06-18 15:23:35 +00:00
|
|
|
|
2021-07-20 10:36:23 +00:00
|
|
|
/**
|
2021-08-13 14:41:48 +00:00
|
|
|
* @private
|
2021-07-20 10:36:23 +00:00
|
|
|
* @param {OO.ui.Element[]} items
|
|
|
|
*/
|
2022-01-21 14:47:31 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onParameterWidgetListChanged = function () {
|
|
|
|
this.toggleFilters();
|
2022-01-14 16:18:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
2022-02-03 12:30:29 +00:00
|
|
|
* @param {boolean} [initiallyHideUnused=false]
|
2022-01-14 16:18:00 +00:00
|
|
|
*/
|
2022-02-03 12:30:29 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.toggleFilters = function ( initiallyHideUnused ) {
|
2022-02-08 17:11:51 +00:00
|
|
|
var numParams = this.getRelevantTemplateParameters().length,
|
2022-01-21 14:47:31 +00:00
|
|
|
visible = numParams >= this.constructor.static.searchableParameterCount;
|
2022-01-20 12:05:09 +00:00
|
|
|
if ( this.searchWidget ) {
|
|
|
|
this.searchWidget.toggle( visible );
|
|
|
|
this.toggleUnusedWidget.toggle( visible );
|
|
|
|
} else if ( visible ) {
|
|
|
|
this.initializeFilters();
|
2022-02-04 11:06:54 +00:00
|
|
|
this.updateUnusedParameterToggleState();
|
2022-02-08 17:11:51 +00:00
|
|
|
if ( initiallyHideUnused ) {
|
2022-02-03 12:30:29 +00:00
|
|
|
this.toggleUnusedWidget.toggleUnusedParameters( false );
|
|
|
|
}
|
2022-01-20 12:05:09 +00:00
|
|
|
}
|
2022-01-14 16:39:09 +00:00
|
|
|
};
|
2022-01-14 16:18:00 +00:00
|
|
|
|
2022-01-14 16:39:09 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2022-01-20 12:05:09 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.initializeFilters = function () {
|
2022-01-14 16:39:09 +00:00
|
|
|
this.searchWidget = new OO.ui.SearchInputWidget( {
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-filter-title', this.templateModel.getSpec().getLabel() ),
|
|
|
|
placeholder: ve.msg( 'visualeditor-dialog-transclusion-filter-placeholder' ),
|
|
|
|
classes: [ 've-ui-mwTransclusionOutlineTemplateWidget-searchWidget' ]
|
|
|
|
} ).connect( this, {
|
|
|
|
change: 'filterParameters'
|
|
|
|
} );
|
|
|
|
this.searchWidget.$element.attr( 'role', 'search' );
|
2022-01-14 16:18:00 +00:00
|
|
|
|
2022-01-14 16:39:09 +00:00
|
|
|
this.toggleUnusedWidget = new ve.ui.MWTransclusionOutlineToggleUnusedWidget();
|
|
|
|
this.toggleUnusedWidget.connect( this, {
|
|
|
|
toggleUnusedFields: 'onToggleUnusedFields'
|
|
|
|
} );
|
2022-01-14 16:18:00 +00:00
|
|
|
|
2022-01-14 16:39:09 +00:00
|
|
|
this.infoWidget = new OO.ui.LabelWidget( {
|
|
|
|
label: ve.msg( 'visualeditor-dialog-transclusion-filter-no-match' ),
|
|
|
|
classes: [ 've-ui-mwTransclusionOutlineTemplateWidget-no-match' ]
|
|
|
|
} ).toggle( false );
|
|
|
|
|
2022-01-20 12:05:09 +00:00
|
|
|
var $stickyHeader = $( '<div>' )
|
2022-01-14 16:39:09 +00:00
|
|
|
.addClass( 've-ui-mwTransclusionOutlineTemplateWidget-sticky' )
|
|
|
|
.append(
|
|
|
|
this.header.$element,
|
|
|
|
this.searchWidget.$element,
|
|
|
|
this.toggleUnusedWidget.$element
|
2022-01-14 16:18:00 +00:00
|
|
|
);
|
2022-01-14 16:39:09 +00:00
|
|
|
|
|
|
|
this.$element.prepend(
|
2022-01-20 12:05:09 +00:00
|
|
|
$stickyHeader,
|
2022-01-14 16:39:09 +00:00
|
|
|
this.infoWidget.$element
|
|
|
|
);
|
2021-07-20 10:36:23 +00:00
|
|
|
};
|
|
|
|
|
2021-07-12 15:00:04 +00:00
|
|
|
/**
|
2021-07-14 07:31:42 +00:00
|
|
|
* Narrows the list of checkboxes down to parameters that match the user's input. The search
|
|
|
|
* algorithm is modelled after {@see ve.ui.MWParameterSearchWidget.buildIndex}. We search the
|
|
|
|
* parameter's primary name, aliases, label, and description. But not e.g. the example value.
|
2021-07-12 15:00:04 +00:00
|
|
|
*
|
2021-08-13 14:41:48 +00:00
|
|
|
* @private
|
2021-07-14 07:31:42 +00:00
|
|
|
* @param {string} query user input
|
2021-08-31 08:05:25 +00:00
|
|
|
* @fires filterParametersById
|
2021-07-12 15:00:04 +00:00
|
|
|
*/
|
2021-08-06 13:05:54 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.filterParameters = function ( query ) {
|
2022-02-14 09:07:10 +00:00
|
|
|
var template = this.templateModel,
|
2021-08-05 12:36:10 +00:00
|
|
|
spec = this.templateModel.getSpec(),
|
2021-08-11 06:06:22 +00:00
|
|
|
visibility = {},
|
2021-07-14 07:31:42 +00:00
|
|
|
nothingFound = true;
|
|
|
|
|
|
|
|
query = query.trim().toLowerCase();
|
2022-02-08 17:11:51 +00:00
|
|
|
this.createAllParameterCheckboxes();
|
2021-07-14 07:31:42 +00:00
|
|
|
|
|
|
|
// Note: We can't really cache this because the list of know parameters can change any time
|
2022-01-21 14:47:31 +00:00
|
|
|
this.parameterList.items.forEach( function ( item ) {
|
2021-08-26 14:29:42 +00:00
|
|
|
var paramName = item.getData(),
|
2021-08-05 10:11:40 +00:00
|
|
|
placesToSearch = [
|
|
|
|
spec.getPrimaryParameterName( paramName ),
|
|
|
|
spec.getParameterLabel( paramName ),
|
|
|
|
spec.getParameterDescription( paramName )
|
|
|
|
].concat( spec.getParameterAliases( paramName ) );
|
2021-07-14 07:31:42 +00:00
|
|
|
|
|
|
|
var foundSomeMatch = placesToSearch.some( function ( term ) {
|
2021-12-09 13:16:02 +00:00
|
|
|
// Aliases missed validation for a long time and aren't guaranteed to be strings
|
|
|
|
return term && typeof term === 'string' && term.toLowerCase().indexOf( query ) !== -1;
|
2021-07-14 07:31:42 +00:00
|
|
|
} );
|
2021-07-12 15:00:04 +00:00
|
|
|
|
2021-08-26 14:29:42 +00:00
|
|
|
item.toggle( foundSomeMatch );
|
2021-08-11 06:06:22 +00:00
|
|
|
|
2021-07-14 07:31:42 +00:00
|
|
|
nothingFound = nothingFound && !foundSomeMatch;
|
2021-08-05 12:36:10 +00:00
|
|
|
|
|
|
|
var param = template.getParameter( paramName );
|
|
|
|
if ( param ) {
|
2021-08-11 06:06:22 +00:00
|
|
|
visibility[ param.getId() ] = foundSomeMatch;
|
2021-08-05 12:36:10 +00:00
|
|
|
}
|
2021-07-12 15:00:04 +00:00
|
|
|
} );
|
|
|
|
|
2022-02-03 12:30:29 +00:00
|
|
|
this.toggleUnusedWidget.toggle( !query );
|
2021-07-14 07:31:42 +00:00
|
|
|
this.infoWidget.toggle( nothingFound );
|
2022-02-14 09:07:10 +00:00
|
|
|
this.emit( 'filterParametersById', visibility );
|
2022-01-12 14:05:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {boolean} visibility
|
2022-03-04 11:01:58 +00:00
|
|
|
* @param {boolean} fromClick
|
2022-01-12 14:05:07 +00:00
|
|
|
*/
|
2022-03-04 11:01:58 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onToggleUnusedFields = function ( visibility, fromClick ) {
|
2022-02-08 17:11:51 +00:00
|
|
|
if ( visibility ) {
|
|
|
|
this.createAllParameterCheckboxes();
|
|
|
|
}
|
2022-03-04 11:01:58 +00:00
|
|
|
|
2022-02-08 17:11:51 +00:00
|
|
|
if ( this.parameterList ) {
|
|
|
|
this.parameterList.items.forEach( function ( item ) {
|
|
|
|
item.toggle( visibility || item.isSelected() );
|
|
|
|
} );
|
|
|
|
}
|
2022-03-04 11:01:58 +00:00
|
|
|
|
|
|
|
if ( !visibility && fromClick ) {
|
2022-03-11 11:29:21 +00:00
|
|
|
this.scrollTopIntoView();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.scrollTopIntoView = function () {
|
|
|
|
this.header.scrollElementIntoView();
|
|
|
|
|
|
|
|
if ( this.parameterList ) {
|
|
|
|
var firstSelected = this.parameterList.findFirstSelectedItem();
|
2022-03-04 11:01:58 +00:00
|
|
|
if ( firstSelected ) {
|
|
|
|
// make sure parameters ( if any ) are still visible and scrolled underneath the sticky
|
|
|
|
firstSelected.scrollElementIntoView( { padding: { top: 110 } } );
|
|
|
|
}
|
2022-03-11 11:29:21 +00:00
|
|
|
|
2022-03-04 11:01:58 +00:00
|
|
|
}
|
2021-07-12 15:00:04 +00:00
|
|
|
};
|