Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/dialogs/ve.ui.LanguageSearchDialog.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface LanguageSearchDialog class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Dialog for searching for and selecting a language.
9 *
10 * @class
11 * @extends OO.ui.ProcessDialog
12 *
13 * @constructor
14 * @param {Object} [config] Configuration options
15 */
16 ve.ui.LanguageSearchDialog = function VeUiLanguageSearchDialog( config ) {
17 // Parent constructor
18 ve.ui.LanguageSearchDialog.super.call( this, config );
19 };
20
21 /* Inheritance */
22
23 OO.inheritClass( ve.ui.LanguageSearchDialog, OO.ui.ProcessDialog );
24
25 /* Static Properties */
26
27 ve.ui.LanguageSearchDialog.static.name = 'languageSearch';
28
29 ve.ui.LanguageSearchDialog.static.size = 'medium';
30
31 ve.ui.LanguageSearchDialog.static.title =
32 OO.ui.deferMsg( 'visualeditor-dialog-language-search-title' );
33
34 ve.ui.LanguageSearchDialog.static.actions = [
35 {
36 label: OO.ui.deferMsg( 'visualeditor-dialog-action-cancel' ),
37 flags: [ 'safe', 'close' ]
38 }
39 ];
40
41 /**
42 * Language search widget class to use.
43 *
44 * @static
45 * @property {Function}
46 * @inheritable
47 */
48 ve.ui.LanguageSearchDialog.static.languageSearchWidget = ve.ui.LanguageSearchWidget;
49
50 /* Methods */
51
52 /**
53 * @inheritdoc
54 */
55 ve.ui.LanguageSearchDialog.prototype.initialize = function () {
56 ve.ui.LanguageSearchDialog.super.prototype.initialize.apply( this, arguments );
57
58 // eslint-disable-next-line new-cap
59 this.searchWidget = new this.constructor.static.languageSearchWidget();
60 this.searchWidget.getResults().connect( this, { choose: 'onSearchResultsChoose' } );
61 this.$body.append( this.searchWidget.$element );
62 };
63
64 /**
65 * Handle the search widget being selected
66 *
67 * @param {ve.ui.LanguageResultWidget} item Chosen item
68 */
69 ve.ui.LanguageSearchDialog.prototype.onSearchResultsChoose = function ( item ) {
70 const data = item.getData();
71 this.close( {
72 action: 'done',
73 lang: data.code,
74 dir: ve.init.platform.getLanguageDirection( data.code )
75 } );
76 };
77
78 /**
79 * @inheritdoc
80 */
81 ve.ui.LanguageSearchDialog.prototype.getSetupProcess = function ( data ) {
82 return ve.ui.LanguageSearchDialog.super.prototype.getSetupProcess.call( this, data )
83 .next( () => {
84 this.searchWidget.setAvailableLanguages( data.availableLanguages );
85 this.searchWidget.addResults();
86 } );
87 };
88
89 /**
90 * @inheritdoc
91 */
92 ve.ui.LanguageSearchDialog.prototype.getReadyProcess = function ( data ) {
93 return ve.ui.LanguageSearchDialog.super.prototype.getReadyProcess.call( this, data )
94 .next( () => {
95 this.searchWidget.getQuery().focus();
96 } );
97 };
98
99 /**
100 * @inheritdoc
101 */
102 ve.ui.LanguageSearchDialog.prototype.getTeardownProcess = function ( data ) {
103 return ve.ui.LanguageSearchDialog.super.prototype.getTeardownProcess.call( this, data )
104 .first( () => {
105 this.searchWidget.getQuery().setValue( '' );
106 } );
107 };
108
109 /**
110 * @inheritdoc
111 */
112 ve.ui.LanguageSearchDialog.prototype.getBodyHeight = function () {
113 return 300;
114 };
115
116 /* Registration */
117
118 ve.ui.windowFactory.register( ve.ui.LanguageSearchDialog );