All files / src/ui/dialogs ve.ui.LanguageSearchDialog.js

48.28% Statements 14/29
100% Branches 0/0
0% Functions 0/10
48.28% Lines 14/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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