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 1: Line 1:
( function ( $, mw ) {
( function ( $, mw, psw ) {
'use strict';
'use strict';

/*
* QueryOptions
*/
function QueryOptions() {
this.queryParams = {};
this.getters = {};
this.fieldset = new OO.ui.FieldsetLayout( {
label: 'Query options',
items: []
} );
}
QueryOptions.prototype.addButtonGroup = function( param, fieldOptions, widgetOptions ) {
mw.loader.using( [ 'oojs-ui-core', 'oojs-ui-widgets', 'mediawiki.widgets.DateInputWidget' ] ).done( function() {
var toggleButtons = widgetOptions.items.map( function ( item ) {
var btn = new OO.ui.ButtonOptionWidget({
/*
data: item.data,
* QueryOptions
label: item.label
*/
});
function QueryOptions() {
this.queryParams = {};
this.getters = {};
return btn;
this.fieldset = new OO.ui.FieldsetLayout( {
} );
label: 'Query options',
items: []
var widget = new OO.ui.ButtonSelectWidget( {
} );
items: toggleButtons,
}
align: widgetOptions.align || 'left',
multiselect: widgetOptions.multiselect || false
} );
this.fieldset.addItems( [
QueryOptions.prototype.addButtonGroup = function( param, fieldOptions, widgetOptions ) {
new OO.ui.FieldLayout( widget, {
var toggleButtons = widgetOptions.items.map( function ( item ) {
label: fieldOptions.label,
var btn = new OO.ui.ButtonOptionWidget({
align: fieldOptions.align || 'top'
data: item.data,
} )
label: item.label
});
] );
return btn;
} );
var widget = new OO.ui.ButtonSelectWidget( {
items: toggleButtons,
align: widgetOptions.align || 'left',
multiselect: widgetOptions.multiselect || false
} );
this.fieldset.addItems( [
new OO.ui.FieldLayout( widget, {
label: fieldOptions.label,
align: fieldOptions.align || 'top'
} )
] );
this.getters[ param ] = function() {
var selected = widget.findSelectedItems();
if ( Array.isArray(selected) ) {
return selected.map( function ( item ) {
return item.getData();
} );
} else if ( selected !== null ) {
return [ selected.getData() ];
}
return [];
};
};
QueryOptions.prototype.addCheckbox = function ( param, fieldOptions, widgetOptions ) {
this.getters[ param ] = function() {
var widget = new OO.ui.CheckboxInputWidget( {
var selected = widget.findSelectedItems();
label: widgetOptions.label,
title: widgetOptions.title
} );
if ( Array.isArray(selected) ) {
this.fieldset.addItems( [
return selected.map( function ( item ) {
new OO.ui.FieldLayout( widget, {
return item.getData();
label: fieldOptions.label,
} );
align: fieldOptions.align || 'top'
} else if ( selected !== null ) {
} )
return [ selected.getData() ];
] );
}
return [];
this.getters[ param ] = function() {
var selected = widget.isSelected();
if ( selected ) {
return widgetOptions.dataTrue;
}
return widgetOptions.dataFalse;
};
};
};
};
QueryOptions.prototype.addCheckbox = function ( param, fieldOptions, widgetOptions ) {
var widget = new OO.ui.CheckboxInputWidget( {
label: widgetOptions.label,
title: widgetOptions.title
} );
this.fieldset.addItems( [
QueryOptions.prototype.addCheckboxMulti = function( param, fieldOptions, widgetOptions ) {
new OO.ui.FieldLayout( widget, {
label: fieldOptions.label,
};
align: fieldOptions.align || 'top'
} )
] );
QueryOptions.prototype.getOptions = function() {
this.getters[ param ] = function() {
var opts = {};
var selected = widget.isSelected();
for ( var key in this.getters ) {
if ( selected ) {
return widgetOptions.dataTrue;
opts[ key ] = this.getters[ key ]();
}
}
return opts;
return widgetOptions.dataFalse;
};
};
};
QueryOptions.prototype.addCheckboxMulti = function( param, fieldOptions, widgetOptions ) {
};
/*
* DisplayOptions
QueryOptions.prototype.getOptions = function() {
*/
var opts = {};
function DisplayOptions() {
this.displayOptions = {};
for ( var key in this.getters ) {
opts[ key ] = this.getters[ key ]();
this.fieldset = new OO.ui.FieldsetLayout( {
label: 'Display options',
items: []
} );
}
}
return opts;
DisplayOptions.prototype.addColumnSelector = function( columns ) {
};
/*
* DisplayOptions
*/
function DisplayOptions() {
this.displayOptions = {};
this.fieldset = new OO.ui.FieldsetLayout( {
};
label: 'Display options',
items: []
} );
}
DisplayOptions.prototype.addColumnSelector = function( columns ) {
};
DisplayOptions.prototype.getOptions = function() {
};
DisplayOptions.prototype.getOptions = function() {
};
function SearchWidget( config ) {
this.fieldset = new OO.ui.FieldsetLayout();
this.submitButton = new OO.ui.ButtonInputWidget( {
label: 'Search',
flags: [ 'primary', 'progressive' ],
align: 'left',
icon: 'search'
} );
if ( config.queryOptions ) {
this.fieldset.addItems( [
config.queryOptions.fieldset
] );
}
function SearchWidget( config ) {
if ( config.displayOptions ) {
this.fieldset = new OO.ui.FieldsetLayout();
this.submitButton = new OO.ui.ButtonInputWidget( {
label: 'Search',
flags: [ 'primary', 'progressive' ],
align: 'left',
icon: 'search'
} );
if ( config.queryOptions ) {
this.fieldset.addItems( [
config.queryOptions.fieldset
] );
}
if ( config.displayOptions ) {
this.fieldset.addItems( [
config.displayOptions.fieldset
] );
}
this.fieldset.addItems( [
this.fieldset.addItems( [
config.displayOptions.fieldset
new OO.ui.FieldLayout( this.submitButton )
] );
] );
this.submitButton.on('click', function() {
console.log( config.queryOptions.getOptions() );
} );
}
}
this.fieldset.addItems( [
Object.preventExtensions( QueryOptions );
new OO.ui.FieldLayout( this.submitButton )
Object.preventExtensions( DisplayOptions );
] );
Object.preventExtensions( SearchWidget );
this.submitButton.on('click', function() {
window.pswiki.db = {
console.log( config.queryOptions.getOptions() );
QueryOptions: QueryOptions,
} );
DisplayOptions: DisplayOptions,
}
SearchWidget: SearchWidget
};
Object.preventExtensions( QueryOptions );
Object.preventExtensions( DisplayOptions );
Object.preventExtensions( SearchWidget );
psw.db = {
QueryOptions: QueryOptions,
DisplayOptions: DisplayOptions,
SearchWidget: SearchWidget
};
} )( jQuery, mediaWiki, pswiki );
} );
} )( jQuery, mediaWiki );

Revision as of 23:19, 21 December 2021

( function ( $, mw, psw ) {
	'use strict';

	/*
	 * QueryOptions
	 */
	function QueryOptions() {
		this.queryParams = {};
		this.getters = {};
		
		this.fieldset = new OO.ui.FieldsetLayout( {
		    label: 'Query options',
		    items: []
		} );
	}
	
	QueryOptions.prototype.addButtonGroup = function( param, fieldOptions, widgetOptions ) {
		var toggleButtons = widgetOptions.items.map( function ( item ) {
			var btn = new OO.ui.ButtonOptionWidget({
				data: item.data,
				label: item.label
			});
			
			return btn;
		} );
			
		var widget = new OO.ui.ButtonSelectWidget( {
			items: toggleButtons,
			align: widgetOptions.align || 'left',
			multiselect: widgetOptions.multiselect || false
		} );
		
		this.fieldset.addItems( [
			new OO.ui.FieldLayout( widget, {
				label: fieldOptions.label,
				align: fieldOptions.align || 'top'
			} )
		] );
		
		this.getters[ param ] = function() {
			var selected = widget.findSelectedItems();
			
			if ( Array.isArray(selected) ) {
				return selected.map( function ( item ) { 
					return item.getData();
				} );
			} else if ( selected !== null ) {
				return [ selected.getData() ];
			}
			
			return [];
		};
	};
	
	QueryOptions.prototype.addCheckbox = function ( param, fieldOptions, widgetOptions ) {
		var widget = new OO.ui.CheckboxInputWidget( {
	        label: widgetOptions.label,
	        title: widgetOptions.title
		} );
		
		this.fieldset.addItems( [
			new OO.ui.FieldLayout( widget, {
				label: fieldOptions.label,
				align: fieldOptions.align || 'top'
			} )
		] );
		
		this.getters[ param ] = function() {
			var selected = widget.isSelected();
			
			if ( selected ) {
				return widgetOptions.dataTrue;
			}
			
			return widgetOptions.dataFalse;
		};
	};
	
	QueryOptions.prototype.addCheckboxMulti = function( param, fieldOptions, widgetOptions ) {
		
	};
	
	QueryOptions.prototype.getOptions = function() {
		var opts = {};
		
		for ( var key in this.getters ) {
			opts[ key ] = this.getters[ key ]();
		}
		
		return opts;
	};
	
	/*
	 * DisplayOptions
	 */
	function DisplayOptions() {
		this.displayOptions = {};
		
		this.fieldset = new OO.ui.FieldsetLayout( {
		    label: 'Display options',
		    items: []
		} );
	}
	
	DisplayOptions.prototype.addColumnSelector = function( columns ) {
	
	};
	
	DisplayOptions.prototype.getOptions = function() {
		
	};
	
	
	function SearchWidget( config ) {
		this.fieldset = new OO.ui.FieldsetLayout();
		this.submitButton = new OO.ui.ButtonInputWidget( { 
			label: 'Search',
			flags: [ 'primary', 'progressive' ],
			align: 'left',
			icon: 'search'
		} );
		
		if ( config.queryOptions ) {
			this.fieldset.addItems( [
				config.queryOptions.fieldset
			] );
		}
		
		if ( config.displayOptions ) {
			this.fieldset.addItems( [
				config.displayOptions.fieldset
			] );
		}
		
		this.fieldset.addItems( [
	    	new OO.ui.FieldLayout( this.submitButton )
		] );
		
		this.submitButton.on('click', function() {
			console.log( config.queryOptions.getOptions() );
		} );
	}
	
	Object.preventExtensions( QueryOptions );
	Object.preventExtensions( DisplayOptions );
	Object.preventExtensions( SearchWidget );
	
	psw.db = {
		QueryOptions: QueryOptions,
		DisplayOptions: DisplayOptions,
		SearchWidget: SearchWidget
	};
		
} )( jQuery, mediaWiki, pswiki );
Cookies help us deliver our services. By using our services, you agree to our use of cookies.