2021-05-17 15:43:49 +00:00
|
|
|
/**
|
2022-07-12 09:55:54 +00:00
|
|
|
* Container for a template as rendered in the template dialog sidebar.
|
|
|
|
* Contains search and visibility inputs, and a list of parameters when available.
|
2021-05-17 15:43:49 +00:00
|
|
|
*
|
|
|
|
* @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-03-22 13:55:46 +00:00
|
|
|
* @param {boolean} [replacesPlaceholder=false]
|
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
|
|
|
|
2022-07-08 05:33:08 +00:00
|
|
|
this.$element.addClass( 've-ui-mwTransclusionOutlineTemplateWidget' );
|
|
|
|
|
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-08-02 10:13:06 +00:00
|
|
|
var canFilter = this.shouldFiltersBeShown(),
|
2022-03-22 13:55:46 +00:00
|
|
|
initiallyHideUnused = canFilter && !replacesPlaceholder && !this.transclusionModel.isSingleTemplate();
|
|
|
|
|
|
|
|
var parameterNames = this.getRelevantTemplateParameters( initiallyHideUnused ? 'used' : 'all' );
|
|
|
|
if ( parameterNames.length ) {
|
|
|
|
this.initializeParameterList();
|
|
|
|
this.parameterList.addItems( parameterNames.map( this.createCheckbox.bind( this ) ) );
|
2022-08-02 09:41:07 +00:00
|
|
|
} else if ( !canFilter ) {
|
2022-04-28 11:54:33 +00:00
|
|
|
this.$noParametersNote = $( '<div>' )
|
|
|
|
.text( ve.msg( 'visualeditor-dialog-transclusion-no-template-parameters' ) )
|
2022-07-08 05:33:08 +00:00
|
|
|
.addClass( 've-ui-mwTransclusionOutlineTemplateWidget-no-template-parameters' );
|
2022-04-28 11:54:33 +00:00
|
|
|
this.$element.append( this.$noParametersNote );
|
2022-03-22 13:55:46 +00:00
|
|
|
}
|
|
|
|
|
2022-08-02 10:13:06 +00:00
|
|
|
this.toggleFilters();
|
2022-03-22 13:55:46 +00:00
|
|
|
if ( initiallyHideUnused ) {
|
|
|
|
// This is only to update the label of the "Hide unused" button
|
|
|
|
this.toggleUnusedWidget.toggleUnusedParameters( false );
|
|
|
|
}
|
2022-01-14 16:39:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWTransclusionOutlineTemplateWidget, ve.ui.MWTransclusionOutlinePartWidget );
|
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-03-22 13:55:46 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.initializeParameterList = function () {
|
2022-01-21 14:47:31 +00:00
|
|
|
if ( this.parameterList ) {
|
2022-01-14 16:39:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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( {
|
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',
|
2022-08-30 10:15:43 +00:00
|
|
|
templateParameterSpaceDown: 'onTemplateParameterSpaceDown'
|
2022-01-12 14:05:07 +00:00
|
|
|
} );
|
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;
|
|
|
|
}
|
2022-06-16 15:26:15 +00:00
|
|
|
// Never create a checkbox for a not yet named parameter placeholder
|
2022-02-08 17:11:51 +00:00
|
|
|
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 ) {
|
2022-06-15 14:47:54 +00:00
|
|
|
var spec = this.templateModel.getSpec(),
|
|
|
|
parameterModel = this.templateModel.getParameter( paramName );
|
|
|
|
|
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,
|
2022-06-15 14:47:54 +00:00
|
|
|
selected: !!parameterModel,
|
|
|
|
hasValue: !!parameterModel && !!parameterModel.getValue()
|
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
|
|
|
/**
|
2022-07-09 06:54:35 +00:00
|
|
|
* @param {string} [paramName] Parameter name to set, e.g. "param1". Omit to remove setting.
|
2021-09-01 09:15:37 +00:00
|
|
|
*/
|
2022-07-09 06:54:35 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.setParameter = function ( paramName ) {
|
2022-01-21 14:47:31 +00:00
|
|
|
if ( this.parameterList ) {
|
2022-07-18 14:52:20 +00:00
|
|
|
this.parameterList.setActiveParameter( paramName );
|
2022-01-14 16:39:09 +00:00
|
|
|
}
|
2021-09-01 09:15:37 +00:00
|
|
|
};
|
|
|
|
|
2022-06-15 14:47:54 +00:00
|
|
|
/**
|
|
|
|
* @param {string} paramName
|
|
|
|
* @param {boolean} hasValue
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.toggleHasValue = function ( paramName, hasValue ) {
|
|
|
|
if ( this.parameterList ) {
|
|
|
|
var item = this.parameterList.findItemFromData( paramName );
|
|
|
|
if ( item ) {
|
|
|
|
item.toggleHasValue( hasValue );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-23 11:26:25 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.setSelected = function ( state ) {
|
2022-07-15 13:40:15 +00:00
|
|
|
// FIXME: This is a super-specific hack; should be replaced with a more generic solution
|
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-04-28 11:54:33 +00:00
|
|
|
if ( this.$noParametersNote ) {
|
|
|
|
this.$noParametersNote.remove();
|
|
|
|
delete this.$noParametersNote;
|
|
|
|
}
|
|
|
|
|
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-06-29 19:45:09 +00:00
|
|
|
*/
|
2021-08-31 08:05:25 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onTemplateParameterChoose = function ( item, selected ) {
|
2022-07-04 08:41:37 +00:00
|
|
|
this.toggleParameter( item, selected, false );
|
2021-09-07 15:53:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {OO.ui.OptionWidget} item
|
|
|
|
* @param {boolean} selected
|
|
|
|
*/
|
2022-07-15 12:16:34 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onTemplateParameterSpaceDown = function ( item, selected ) {
|
2022-07-04 08:41:37 +00:00
|
|
|
this.toggleParameter( item, selected, true );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {OO.ui.OptionWidget} item
|
|
|
|
* @param {boolean} selected
|
|
|
|
* @param {boolean} soft If true, focus should stay in the sidebar.
|
2022-07-18 12:55:52 +00:00
|
|
|
* @fires transclusionOutlineItemSelected
|
2022-07-04 08:41:37 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.toggleParameter = function ( item, selected, soft ) {
|
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();
|
2022-07-04 08:41:37 +00:00
|
|
|
|
|
|
|
if ( param && selected ) {
|
2022-07-18 12:55:52 +00:00
|
|
|
this.emit( 'transclusionOutlineItemSelected', param.getId(), soft );
|
2022-07-04 08:41:37 +00:00
|
|
|
}
|
2022-02-04 11:06:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
2022-01-14 16:18:00 +00:00
|
|
|
/**
|
|
|
|
* @private
|
2022-08-02 10:13:06 +00:00
|
|
|
* @return {boolean}
|
2022-01-14 16:18:00 +00:00
|
|
|
*/
|
2022-08-02 10:13:06 +00:00
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.shouldFiltersBeShown = function () {
|
2022-08-02 09:08:23 +00:00
|
|
|
var min = this.constructor.static.searchableParameterCount,
|
|
|
|
existingParameterWidgets = this.parameterList && this.parameterList.getItemCount();
|
|
|
|
// Avoid expensive calls when there are already enough items in the parameter list
|
|
|
|
return existingParameterWidgets >= min || this.getRelevantTemplateParameters().length >= min;
|
2022-08-02 10:13:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.toggleFilters = function () {
|
|
|
|
var visible = this.shouldFiltersBeShown();
|
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-08-02 09:08:23 +00:00
|
|
|
}
|
|
|
|
|
2022-08-17 11:48:14 +00:00
|
|
|
this.recalculateStickyHeaderHeight();
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.recalculateStickyHeaderHeight = function () {
|
|
|
|
// A template with no used parameters might have a sticky header, but no paramater list yet
|
|
|
|
if ( this.$stickyHeader && this.parameterList ) {
|
|
|
|
this.parameterList.stickyHeaderHeight = Math.floor( this.$stickyHeader.outerHeight() );
|
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-08-17 11:48:14 +00:00
|
|
|
this.$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-08-17 11:48:14 +00:00
|
|
|
this.$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
|
|
|
/**
|
2022-06-16 15:55:20 +00:00
|
|
|
* Narrows the list of checkboxes down to parameters that match the user's input. We search the
|
2021-07-14 07:31:42 +00:00
|
|
|
* 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-07-08 11:59:37 +00:00
|
|
|
this.parameterList.setTabIndex( nothingFound ? -1 : 0 );
|
2022-08-17 11:48:14 +00:00
|
|
|
// The "hide unused" button might be hidden now, which changes the height of the sticky header
|
|
|
|
this.recalculateStickyHeaderHeight();
|
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-07-12 18:10:02 +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-08-02 11:23:34 +00:00
|
|
|
var self = this;
|
|
|
|
this.header.scrollElementIntoView().then( function () {
|
|
|
|
if ( self.parameterList ) {
|
|
|
|
self.parameterList.ensureVisibilityOfFirstCheckedParameter();
|
|
|
|
}
|
|
|
|
} );
|
2022-03-04 11:01:58 +00:00
|
|
|
}
|
2021-07-12 15:00:04 +00:00
|
|
|
};
|