User:Chrs/userRightsListGenerator.js

$(document).ready(function{	$(mw.util.addPortletLink(		'p-tb',		'',		'Build rights list',		't-userrightslist-gen',		'Build rights list'	)).on('click', function(e){ e.preventDefault; var api = new mw.Api; api.get({			'action': 'query',			'meta': 'siteinfo',			'siprop': 'usergroups'		}).then(function(data){			Dialog = function(config) {				Dialog.super.call(this, config);			};			OO.inheritClass(Dialog, OO.ui.ProcessDialog);			Dialog.static.name = 'userrightslist-gen';			Dialog.static.title = 'Rights list generator';			Dialog.static.actions = [				{ label: 'Close', flags: 'safe' }			];			Dialog.prototype.getApiManager = function {				return this.apiManager;			};			Dialog.prototype.getBodyHeight = function {				return 485;			};			Dialog.prototype.initialize = function {				Dialog.super.prototype.initialize.call( this );				this.editFieldset = new OO.ui.FieldsetLayout( { classes: ['container'] });				this.editPanel = new OO.ui.PanelLayout({ expanded: false });				this.editPanel.$element.append(this.editFieldset.$element);				this.groupInput = new OO.ui.DropdownWidget({ label: 'Group', menu: { items: data['query']['usergroups'].map(function(a){							return new OO.ui.MenuOptionWidget( { data: a['rights'], label: a['name'] });						})					}				});				this.groupInput.getMenu.on('select', => { this.wikitextOutput.setValue(this.groupInput.getMenu.findSelectedItem.getData.filter(right => right !== '').concat.sort.map(right => "*  ").join("\n")); });				this.wikitextOutput = new OO.ui.MultilineTextInputWidget({ value: '', rows: 20, readOnly: true, });				this.editFieldset.addItems([ new OO.ui.FieldLayout(this.groupInput, {						label: 'Group',					}), new OO.ui.FieldLayout(this.wikitextOutput, {						label: 'Wikitext',					}) ]);				this.stackLayout = new OO.ui.StackLayout( { items: [this.editPanel], padded: true } );				this.$body.append(this.stackLayout.$element);			};			dialog = new Dialog({ size: 'larger' });			var windowManager = new OO.ui.WindowManager;			$('body').append(windowManager.$element);			windowManager.addWindows([dialog]);			windowManager.openWindow(dialog);		}); }); });