Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Gadget-database-util.js: Difference between revisions

MediaWiki interface page
Content added Content deleted
mNo edit summary
mNo edit summary
Line 16: Line 16:
}
}
QueryOptions.prototype.addMultioption = function( param, options, fieldOptions ) {
QueryOptions.prototype.addMultioption = function( param, fieldOptions, widgetOptions ) {
this.queryParams[param] = new pswiki.polyfill.Set();
this.queryParams[param] = new pswiki.polyfill.Set();
var paramVal = this.queryParams[param];
var paramVal = this.queryParams[param];
var toggleButtons = options.map( function( option ) {
var toggleButtons = widgetOptions.items.map( function( item ) {
var btn = new OO.ui.ToggleButtonWidget( {
var btn = new OO.ui.ToggleButtonWidget( {
label: option.label,
label: item.label,
value: option.value
value: item.value
} );
} );
btn.on( 'change', function( selected ) {
btn.on( 'change', function( selected ) {
if ( selected ) {
if ( selected ) {
paramVal.add( option.label );
paramVal.add( item.label );
} else {
} else {
paramVal.delete( option.label );
paramVal.delete( item.label );
}
}
console.log(paramVal.values());
console.log(paramVal.values());
Line 39: Line 39:
var widget = new OO.ui.ButtonGroupWidget( {
var widget = new OO.ui.ButtonGroupWidget( {
items: toggleButtons,
items: toggleButtons,
align: 'left'
align: widgetOptions.align || 'left'
} );
} );
Line 45: Line 45:
new OO.ui.FieldLayout( widget, {
new OO.ui.FieldLayout( widget, {
label: fieldOptions.label,
label: fieldOptions.label,
align: 'top'
align: fieldOptions.align || 'top'
} ),
} ),
] );
] );

Revision as of 07:47, 21 December 2021

( function ( $, mw ) {
	'use strict';
	
	mw.loader.using( ['oojs-ui-core', 'oojs-ui-widgets'] ).done( function() {
	
		/*
		 * QueryOptions
		 */
		function QueryOptions() {
			this.queryParams = {};
			
			this.fieldset = new OO.ui.FieldsetLayout( {
			    label: 'Query options',
			    items: []
			} );
		}
		
		QueryOptions.prototype.addMultioption = function( param, fieldOptions, widgetOptions ) {
			this.queryParams[param] = new pswiki.polyfill.Set();
			
			var paramVal = this.queryParams[param];
			
			var toggleButtons = widgetOptions.items.map( function( item ) {
				var btn = new OO.ui.ToggleButtonWidget( {
					label: item.label,
					value: item.value
				} );
				btn.on( 'change', function( selected ) {
					if ( selected ) {
						paramVal.add( item.label );
					} else {
						paramVal.delete( item.label );
					}
					console.log(paramVal.values());
				} );
				
				return btn;
			} );
			var widget = new OO.ui.ButtonGroupWidget( {
				items: toggleButtons,
				align: widgetOptions.align || 'left'
			} );
			
			this.fieldset.addItems( [
				new OO.ui.FieldLayout( widget, {
					label: fieldOptions.label,
					align: fieldOptions.align || 'top'
				} ),
			] );	
		};
		
		QueryOptions.prototype.getOptions = function() {
			
		};
		
		/*
		 * DisplayOptions
		 */
		function DisplayOptions() {
			this.displayOptions = {};
		}
		
		DisplayOptions.prototype.getOptions = function() {
			
		};
		
		Object.preventExtensions( QueryOptions );
		Object.preventExtensions( DisplayOptions );
		
		window.pswiki.dbUtil = {
			QueryOptions: QueryOptions,
			DisplayOptions: DisplayOptions
		};
		
	} );
} )( jQuery, mediaWiki );
Cookies help us deliver our services. By using our services, you agree to our use of cookies.