2022-06-22 11:59:22 +00:00
|
|
|
/**
|
2022-07-12 09:55:54 +00:00
|
|
|
* Toolbar at the bottom of the template dialog sidebar. Provides buttons to
|
|
|
|
* reorder and delete top-level parts, and buttons to add templates or raw
|
|
|
|
* wikitext.
|
|
|
|
*
|
|
|
|
* When there is only one template in the transclusion, the sidebar may be
|
|
|
|
* hidden.
|
|
|
|
*
|
2022-06-22 11:59:22 +00:00
|
|
|
* @class
|
|
|
|
* @extends OO.ui.Widget
|
|
|
|
* @mixins OO.ui.mixin.GroupElement
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
2022-06-27 14:46:08 +00:00
|
|
|
ve.ui.MWTransclusionOutlineControlsWidget = function OoUiOutlineControlsWidget( config ) {
|
2022-06-22 11:59:22 +00:00
|
|
|
// Configuration initialization
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWTransclusionOutlineControlsWidget.super.call( this, config );
|
|
|
|
|
|
|
|
// Mixin constructors
|
|
|
|
OO.ui.mixin.GroupElement.call( this, config );
|
|
|
|
|
|
|
|
// Properties
|
2022-06-28 14:10:12 +00:00
|
|
|
this.addTemplateButton = new OO.ui.ButtonWidget( {
|
|
|
|
framed: false,
|
|
|
|
icon: 'puzzle',
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-add-template' )
|
|
|
|
} );
|
|
|
|
this.addWikitextButton = new OO.ui.ButtonWidget( {
|
|
|
|
framed: false,
|
|
|
|
icon: 'wikiText',
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-add-wikitext' )
|
|
|
|
} );
|
2022-06-22 11:59:22 +00:00
|
|
|
this.upButton = new OO.ui.ButtonWidget( {
|
|
|
|
framed: false,
|
|
|
|
icon: 'upTriangle',
|
2022-06-30 05:55:25 +00:00
|
|
|
title: OO.ui.msg( 'ooui-outline-control-move-up' ),
|
|
|
|
disabled: true
|
2022-06-22 11:59:22 +00:00
|
|
|
} );
|
|
|
|
this.downButton = new OO.ui.ButtonWidget( {
|
|
|
|
framed: false,
|
|
|
|
icon: 'downTriangle',
|
2022-06-30 05:55:25 +00:00
|
|
|
title: OO.ui.msg( 'ooui-outline-control-move-down' ),
|
|
|
|
disabled: true
|
2022-06-22 11:59:22 +00:00
|
|
|
} );
|
|
|
|
this.removeButton = new OO.ui.ButtonWidget( {
|
|
|
|
framed: false,
|
|
|
|
icon: 'trash',
|
2022-06-30 05:55:25 +00:00
|
|
|
title: OO.ui.msg( 'ooui-outline-control-remove' ),
|
|
|
|
disabled: true
|
2022-06-22 11:59:22 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Events
|
2022-06-28 14:10:12 +00:00
|
|
|
this.addTemplateButton.connect( this, {
|
|
|
|
click: [ 'emit', 'addTemplate' ]
|
|
|
|
} );
|
|
|
|
this.addWikitextButton.connect( this, {
|
|
|
|
click: [ 'emit', 'addWikitext' ]
|
|
|
|
} );
|
2022-06-22 11:59:22 +00:00
|
|
|
this.upButton.connect( this, {
|
|
|
|
click: [ 'emit', 'move', -1 ]
|
|
|
|
} );
|
|
|
|
this.downButton.connect( this, {
|
|
|
|
click: [ 'emit', 'move', 1 ]
|
|
|
|
} );
|
|
|
|
this.removeButton.connect( this, {
|
|
|
|
click: [ 'emit', 'remove' ]
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-ui-mwTransclusionOutlineControlsWidget' );
|
2022-06-28 14:10:12 +00:00
|
|
|
this.$group.addClass( 've-ui-mwTransclusionOutlineControlsWidget-items' )
|
|
|
|
.append(
|
|
|
|
this.addTemplateButton.$element,
|
|
|
|
this.addWikitextButton.$element
|
|
|
|
);
|
2022-06-28 15:17:24 +00:00
|
|
|
var $movers = $( '<div>' )
|
|
|
|
.addClass( 've-ui-mwTransclusionOutlineControlsWidget-movers' )
|
2022-06-28 14:10:12 +00:00
|
|
|
.append(
|
|
|
|
this.upButton.$element,
|
|
|
|
this.downButton.$element,
|
|
|
|
this.removeButton.$element
|
|
|
|
);
|
2022-06-28 15:17:24 +00:00
|
|
|
this.$element.append( this.$icon, this.$group, $movers );
|
2022-06-22 11:59:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Setup */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWTransclusionOutlineControlsWidget, OO.ui.Widget );
|
|
|
|
OO.mixinClass( ve.ui.MWTransclusionOutlineControlsWidget, OO.ui.mixin.GroupElement );
|
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
2022-06-28 14:10:12 +00:00
|
|
|
* Emitted when the "Add template" button in the toolbar is clicked
|
2022-07-01 14:25:40 +00:00
|
|
|
*
|
2022-06-28 14:10:12 +00:00
|
|
|
* @event addTemplate
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emitted when the "Add wikitext" button in the toolbar is clicked
|
2022-07-01 14:25:40 +00:00
|
|
|
*
|
2022-06-28 14:10:12 +00:00
|
|
|
* @event addWikitext
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emitted when one of the two "Move item up/down" buttons in the toolbar is clicked
|
2022-07-01 14:25:40 +00:00
|
|
|
*
|
2022-06-22 11:59:22 +00:00
|
|
|
* @event move
|
2022-06-28 14:10:12 +00:00
|
|
|
* @param {number} places Number of places to move, typically -1 or 1
|
2022-06-22 11:59:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2022-06-28 14:10:12 +00:00
|
|
|
* Emitted when the "Remove item" button in the toolbar is clicked
|
2022-07-01 14:25:40 +00:00
|
|
|
*
|
2022-06-22 11:59:22 +00:00
|
|
|
* @event remove
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2022-06-27 14:46:08 +00:00
|
|
|
* Change buttons
|
2022-06-22 11:59:22 +00:00
|
|
|
*
|
2022-06-27 14:46:08 +00:00
|
|
|
* @param {Object} states List of abilities with canMoveUp, canMoveDown and canBeDeleted
|
|
|
|
* @param {boolean} states.canMoveUp Allow moving item up
|
|
|
|
* @param {boolean} states.canMoveDown Allow moving item down
|
|
|
|
* @param {boolean} states.canBeDeleted Allow removing removable item
|
2022-06-22 11:59:22 +00:00
|
|
|
*/
|
2022-06-27 14:46:08 +00:00
|
|
|
ve.ui.MWTransclusionOutlineControlsWidget.prototype.setButtonsEnabled = function ( states ) {
|
|
|
|
this.upButton.setDisabled( !states.canMoveUp );
|
|
|
|
this.downButton.setDisabled( !states.canMoveDown );
|
|
|
|
this.removeButton.setDisabled( !states.canBeDeleted );
|
2022-06-22 11:59:22 +00:00
|
|
|
};
|