Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/pages/ve.ui.MWTemplatesUsedPage.js

raw symbols SCIP
1 /*!
2 * VisualEditor user interface MWTemplatesUsedPage class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * MediaWiki meta dialog TemplatesUsed page.
10 *
11 * @class
12 * @extends OO.ui.PageLayout
13 *
14 * @constructor
15 * @param {string} name Unique symbolic name of page
16 * @param {Object} [config] Configuration options
17 * @param {jQuery} [config.$overlay] Overlay to render dropdowns in
18 */
19 ve.ui.MWTemplatesUsedPage = function VeUiMWTemplatesUsedPage() {
20 const target = ve.init.target;
21
22 // Parent constructor
23 ve.ui.MWTemplatesUsedPage.super.apply( this, arguments );
24
25 // Properties
26 this.templatesUsedFieldset = new OO.ui.FieldsetLayout( {
27 label: ve.msg( 'visualeditor-templatesused-tool' ),
28 icon: 'puzzle'
29 } );
30
31 this.templatesUsedFieldset.$group.addClass( [
32 'mw-body-content'
33 ] );
34
35 target.getContentApi().get( {
36 action: 'visualeditor',
37 paction: 'templatesused',
38 page: target.getPageName(),
39 uselang: mw.config.get( 'wgUserLanguage' )
40 } ).then( ( response ) => {
41 const templatesUsed = $.parseHTML( response.visualeditor );
42 if ( templatesUsed.length && $( templatesUsed ).find( 'li' ).length ) {
43 return templatesUsed;
44 } else {
45 return ve.createDeferred().reject().promise();
46 }
47 } ).then( ( templatesUsed ) => {
48 // templatesUsed is an array of nodes
49 // eslint-disable-next-line no-jquery/no-append-html
50 this.templatesUsedFieldset.$group.append( templatesUsed );
51 ve.targetLinksToNewWindow( this.templatesUsedFieldset.$group[ 0 ] );
52 }, () => {
53 this.templatesUsedFieldset.$group.append(
54 $( '<em>' ).text( ve.msg( 'visualeditor-dialog-meta-templatesused-noresults' ) )
55 );
56 } );
57
58 // Initialization
59 this.$element.append( this.templatesUsedFieldset.$element );
60 };
61
62 /* Inheritance */
63
64 OO.inheritClass( ve.ui.MWTemplatesUsedPage, OO.ui.PageLayout );
65
66 /* Methods */
67
68 /**
69 * @inheritdoc
70 */
71 ve.ui.MWTemplatesUsedPage.prototype.setupOutlineItem = function () {
72 this.outlineItem
73 .setIcon( 'puzzle' )
74 .setLabel( ve.msg( 'visualeditor-templatesused-tool' ) );
75 };
76
77 /**
78 * @inheritdoc
79 */
80 ve.ui.MWTemplatesUsedPage.prototype.focus = function () {
81 // No controls, just focus the whole page instead of the first link
82 this.$element[ 0 ].focus();
83 };
84
85 ve.ui.MWTemplatesUsedPage.prototype.getFieldsets = function () {
86 return [
87 this.templatesUsedFieldset
88 ];
89 };