2021-07-09 13:48:08 +00:00
|
|
|
/**
|
|
|
|
* Common base class for top-level items (a.k.a. "parts") in the template editor sidebar. Subclasses
|
|
|
|
* should exist for all subclasses of {@see ve.dm.MWTransclusionPartModel}:
|
|
|
|
* - {@see ve.dm.MWTemplateModel}
|
|
|
|
* - {@see ve.dm.MWTemplatePlaceholderModel}
|
|
|
|
* - {@see ve.dm.MWTransclusionContentModel}
|
|
|
|
*
|
2021-07-09 14:47:01 +00:00
|
|
|
* This is inspired by and meant to replace {@see OO.ui.DecoratedOptionWidget} in the context of the
|
|
|
|
* template dialog. Also see {@see OO.ui.ButtonWidget} for inspiration.
|
|
|
|
*
|
2021-07-09 13:48:08 +00:00
|
|
|
* @abstract
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.Widget
|
|
|
|
*
|
|
|
|
* @constructor
|
2021-07-13 07:27:22 +00:00
|
|
|
* @param {ve.dm.MWTransclusionPartModel} part
|
2021-07-13 09:00:57 +00:00
|
|
|
* @param {Object} config
|
2021-09-11 08:05:31 +00:00
|
|
|
* @cfg {string} [icon=''] Symbolic name of an icon, e.g. "puzzle" or "wikiText"
|
2021-07-13 09:00:57 +00:00
|
|
|
* @cfg {string} label
|
2021-07-09 13:48:08 +00:00
|
|
|
*/
|
2021-07-13 07:27:22 +00:00
|
|
|
ve.ui.MWTransclusionOutlinePartWidget = function VeUiMWTransclusionOutlinePartWidget( part, config ) {
|
2021-09-22 09:49:44 +00:00
|
|
|
this.part = part;
|
|
|
|
|
2021-07-09 13:48:08 +00:00
|
|
|
// Parent constructor
|
2021-08-10 15:01:49 +00:00
|
|
|
ve.ui.MWTransclusionOutlinePartWidget.super.call( this, ve.extendObject( config, {
|
2021-09-10 19:18:59 +00:00
|
|
|
classes: [ 've-ui-mwTransclusionOutlinePartWidget' ],
|
2021-08-10 15:01:49 +00:00
|
|
|
data: part.getId()
|
|
|
|
} ) );
|
2021-07-09 14:47:01 +00:00
|
|
|
|
2021-08-27 16:22:37 +00:00
|
|
|
this.header = new ve.ui.MWTransclusionOutlineButtonWidget( config )
|
2021-09-02 16:09:30 +00:00
|
|
|
.connect( this, {
|
2021-09-22 09:49:44 +00:00
|
|
|
keyPressed: 'onHeaderKeyPressed',
|
2021-09-09 12:11:36 +00:00
|
|
|
click: 'onHeaderClick'
|
2021-09-02 16:09:30 +00:00
|
|
|
} );
|
2021-07-13 09:00:57 +00:00
|
|
|
|
2021-07-09 14:47:01 +00:00
|
|
|
this.$element
|
2021-08-27 16:22:37 +00:00
|
|
|
.append( this.header.$element );
|
2021-07-09 13:48:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2021-07-09 15:04:14 +00:00
|
|
|
OO.inheritClass( ve.ui.MWTransclusionOutlinePartWidget, OO.ui.Widget );
|
2021-07-13 07:27:22 +00:00
|
|
|
|
2021-07-13 11:02:26 +00:00
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
2021-09-02 16:09:30 +00:00
|
|
|
* "Soft" selection with space.
|
|
|
|
*
|
|
|
|
* @event transclusionPartSoftSelected
|
|
|
|
* @param {string} partId Unique id of the {@see ve.dm.MWTransclusionPartModel}, e.g. something like
|
|
|
|
* "part_1".
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "Hard" selection with enter or mouse click.
|
|
|
|
*
|
2021-08-31 08:05:25 +00:00
|
|
|
* @event transclusionPartSelected
|
2021-09-16 08:42:13 +00:00
|
|
|
* @param {string} pageName Unique id of the {@see OO.ui.BookletLayout} page, e.g. something like
|
|
|
|
* "part_1" or "part_1/param1".
|
2021-07-13 11:02:26 +00:00
|
|
|
*/
|
2021-08-27 16:22:37 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2021-09-22 09:49:44 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {number} key Note that some keys only make it here when Ctrl or Ctrl+Shift is pressed
|
|
|
|
* @fires transclusionPartSoftSelected
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlinePartWidget.prototype.onHeaderKeyPressed = function ( key ) {
|
|
|
|
switch ( key ) {
|
|
|
|
case OO.ui.Keys.SPACE:
|
|
|
|
this.emit( 'transclusionPartSoftSelected', this.getData() );
|
|
|
|
break;
|
|
|
|
case OO.ui.Keys.UP:
|
|
|
|
case OO.ui.Keys.DOWN:
|
|
|
|
// Modelled after {@see ve.ui.MWTransclusionDialog.onOutlineControlsMove}
|
|
|
|
var transclusion = this.part.getTransclusion(),
|
|
|
|
parts = transclusion.getParts(),
|
|
|
|
offset = key === OO.ui.Keys.UP ? -1 : 1,
|
|
|
|
newIndex = parts.indexOf( this.part ) + offset;
|
|
|
|
if ( newIndex >= 0 && newIndex < parts.length ) {
|
|
|
|
transclusion.addPart( this.part, newIndex );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OO.ui.Keys.DELETE:
|
|
|
|
this.part.remove();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-09 12:11:36 +00:00
|
|
|
/**
|
|
|
|
* @protected
|
|
|
|
* @fires transclusionPartSelected
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlinePartWidget.prototype.onHeaderClick = function () {
|
|
|
|
this.emit( 'transclusionPartSelected', this.getData() );
|
|
|
|
};
|
|
|
|
|
2021-08-27 16:22:37 +00:00
|
|
|
/**
|
|
|
|
* Convenience method, modelled after {@see OO.ui.OptionWidget}, but this isn't one.
|
|
|
|
*
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlinePartWidget.prototype.isSelected = function () {
|
|
|
|
return this.header.isSelected();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method, modelled after {@see OO.ui.OptionWidget}, but this isn't one.
|
|
|
|
*
|
|
|
|
* @param {boolean} state
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlinePartWidget.prototype.setSelected = function ( state ) {
|
|
|
|
this.header
|
|
|
|
.setSelected( state )
|
|
|
|
.setFlags( { progressive: state } );
|
|
|
|
};
|