| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
( function () { |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
mw.widgets.UserInputWidget = function MwWidgetsUserInputWidget( config ) { |
| 25 |
|
| 26 |
config = config || {}; |
| 27 |
|
| 28 |
|
| 29 |
mw.widgets.UserInputWidget.super.call( this, Object.assign( {}, config, { autocomplete: false } ) ); |
| 30 |
|
| 31 |
|
| 32 |
OO.ui.mixin.LookupElement.call( this, config ); |
| 33 |
|
| 34 |
|
| 35 |
this.limit = config.limit || 10; |
| 36 |
this.excludeNamed = config.excludenamed || false; |
| 37 |
this.excludeTemp = config.excludetemp || false; |
| 38 |
this.api = config.api || new mw.Api(); |
| 39 |
|
| 40 |
|
| 41 |
this.$element.addClass( 'mw-widget-userInputWidget' ); |
| 42 |
this.lookupMenu.$element.addClass( 'mw-widget-userInputWidget-menu' ); |
| 43 |
}; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
OO.inheritClass( mw.widgets.UserInputWidget, OO.ui.TextInputWidget ); |
| 48 |
OO.mixinClass( mw.widgets.UserInputWidget, OO.ui.mixin.LookupElement ); |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
mw.widgets.UserInputWidget.prototype.onLookupMenuChoose = function ( item ) { |
| 58 |
this.closeLookupMenu(); |
| 59 |
this.setLookupsDisabled( true ); |
| 60 |
this.setValue( item.getData() ); |
| 61 |
this.setLookupsDisabled( false ); |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
mw.widgets.UserInputWidget.prototype.focus = function () { |
| 68 |
|
| 69 |
this.setLookupsDisabled( true ); |
| 70 |
|
| 71 |
|
| 72 |
const retval = mw.widgets.UserInputWidget.super.prototype.focus.apply( this, arguments ); |
| 73 |
|
| 74 |
this.setLookupsDisabled( false ); |
| 75 |
|
| 76 |
return retval; |
| 77 |
}; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
mw.widgets.UserInputWidget.prototype.getLookupRequest = function () { |
| 83 |
return this.api.get( { |
| 84 |
action: 'query', |
| 85 |
list: 'allusers', |
| 86 |
auprefix: this.value, |
| 87 |
aulimit: this.limit, |
| 88 |
auexcludenamed: this.excludeNamed, |
| 89 |
auexcludetemp: this.excludeTemp |
| 90 |
} ); |
| 91 |
}; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
mw.widgets.UserInputWidget.prototype.getLookupCacheDataFromResponse = function ( response ) { |
| 101 |
return response.query.allusers || {}; |
| 102 |
}; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
mw.widgets.UserInputWidget.prototype.getLookupMenuOptionsFromData = function ( data ) { |
| 111 |
const items = []; |
| 112 |
|
| 113 |
for ( let i = 0, len = data.length; i < len; i++ ) { |
| 114 |
const user = data[ i ] || {}; |
| 115 |
items.push( new OO.ui.MenuOptionWidget( { |
| 116 |
label: user.name, |
| 117 |
data: user.name |
| 118 |
} ) ); |
| 119 |
} |
| 120 |
|
| 121 |
return items; |
| 122 |
}; |
| 123 |
|
| 124 |
}() ); |