Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/widgets/ve.ui.MWTransclusionOutlineControlsWidget.js

raw symbols SCIP
1 /**
2 * Toolbar at the bottom of the template dialog sidebar. Provides buttons to
3 * reorder and delete top-level parts, and buttons to add templates or raw
4 * wikitext.
5 *
6 * When there is only one template in the transclusion, the sidebar may be
7 * hidden.
8 *
9 * @class
10 * @extends OO.ui.Widget
11 * @mixes OO.ui.mixin.GroupElement
12 *
13 * @constructor
14 */
15 ve.ui.MWTransclusionOutlineControlsWidget = function OoUiOutlineControlsWidget() {
16 // Parent constructor
17 ve.ui.MWTransclusionOutlineControlsWidget.super.call( this );
18
19 // Mixin constructors
20 OO.ui.mixin.GroupElement.call( this );
21
22 // Properties
23 this.addTemplateButton = new OO.ui.ButtonWidget( {
24 framed: false,
25 icon: 'puzzle',
26 title: ve.msg( 'visualeditor-dialog-transclusion-add-template-button' )
27 } );
28 this.addWikitextButton = new OO.ui.ButtonWidget( {
29 framed: false,
30 icon: 'wikiText',
31 title: ve.msg( 'visualeditor-dialog-transclusion-add-wikitext' )
32 } );
33 this.upButton = new OO.ui.ButtonWidget( {
34 framed: false,
35 icon: 'upTriangle',
36 title: OO.ui.msg( 'ooui-outline-control-move-up' ),
37 disabled: true
38 } );
39 this.downButton = new OO.ui.ButtonWidget( {
40 framed: false,
41 icon: 'downTriangle',
42 title: OO.ui.msg( 'ooui-outline-control-move-down' ),
43 disabled: true
44 } );
45 this.removeButton = new OO.ui.ButtonWidget( {
46 framed: false,
47 icon: 'trash',
48 title: OO.ui.msg( 'ooui-outline-control-remove' ),
49 disabled: true
50 } );
51
52 // Events
53 this.addTemplateButton.connect( this, {
54 click: [ 'emit', 'addTemplate' ]
55 } );
56 this.addWikitextButton.connect( this, {
57 click: [ 'emit', 'addWikitext' ]
58 } );
59 this.upButton.connect( this, {
60 click: [ 'emit', 'move', -1 ]
61 } );
62 this.downButton.connect( this, {
63 click: [ 'emit', 'move', 1 ]
64 } );
65 this.removeButton.connect( this, {
66 click: [ 'emit', 'remove' ]
67 } );
68
69 // Initialization
70 this.$element.addClass( 've-ui-mwTransclusionOutlineControlsWidget' );
71 this.$group.addClass( 've-ui-mwTransclusionOutlineControlsWidget-items' )
72 .append(
73 this.addTemplateButton.$element,
74 this.addWikitextButton.$element
75 );
76 const $movers = $( '<div>' )
77 .addClass( 've-ui-mwTransclusionOutlineControlsWidget-movers' )
78 .append(
79 this.upButton.$element,
80 this.downButton.$element,
81 this.removeButton.$element
82 );
83 this.$element.append( this.$icon, this.$group, $movers );
84 };
85
86 /* Setup */
87
88 OO.inheritClass( ve.ui.MWTransclusionOutlineControlsWidget, OO.ui.Widget );
89 OO.mixinClass( ve.ui.MWTransclusionOutlineControlsWidget, OO.ui.mixin.GroupElement );
90
91 /* Events */
92
93 /**
94 * Emitted when the "Add template" button in the toolbar is clicked
95 *
96 * @event ve.ui.MWTransclusionOutlineControlsWidget#addTemplate
97 */
98
99 /**
100 * Emitted when the "Add wikitext" button in the toolbar is clicked
101 *
102 * @event ve.ui.MWTransclusionOutlineControlsWidget#addWikitext
103 */
104
105 /**
106 * Emitted when one of the two "Move item up/down" buttons in the toolbar is clicked
107 *
108 * @event ve.ui.MWTransclusionOutlineControlsWidget#move
109 * @param {number} places Number of places to move, typically -1 or 1
110 */
111
112 /**
113 * Emitted when the "Remove item" button in the toolbar is clicked
114 *
115 * @event ve.ui.MWTransclusionOutlineControlsWidget#remove
116 */
117
118 /* Methods */
119
120 /**
121 * Change buttons
122 *
123 * @param {Object} states List of abilities with canMoveUp, canMoveDown and canBeDeleted
124 * @param {boolean} states.canMoveUp Allow moving item up
125 * @param {boolean} states.canMoveDown Allow moving item down
126 * @param {boolean} states.canBeDeleted Allow removing removable item
127 */
128 ve.ui.MWTransclusionOutlineControlsWidget.prototype.setButtonsEnabled = function ( states ) {
129 this.upButton.setDisabled( !states.canMoveUp );
130 this.downButton.setDisabled( !states.canMoveDown );
131 this.removeButton.setDisabled( !states.canBeDeleted );
132 };