Content added Content deleted
mNo edit summary |
No edit summary |
||
Line 9: | Line 9: | ||
function QueryOptions() { |
function QueryOptions() { |
||
this.queryParams = {}; |
this.queryParams = {}; |
||
this. |
this.getters = {}; |
||
this.fieldset = new OO.ui.FieldsetLayout( { |
this.fieldset = new OO.ui.FieldsetLayout( { |
||
Line 39: | Line 39: | ||
} ) |
} ) |
||
] ); |
] ); |
||
⚫ | |||
⚫ | |||
⚫ | |||
this.queryParams[param] = new pswiki.polyfill.Set(); |
|||
this.getters[ param ] = function() { |
|||
var selected = widget.findSelectedItems(); |
|||
⚫ | |||
var toggleButtons = widgetOptions.items.map( function( item ) { |
|||
⚫ | |||
⚫ | |||
value: item.value |
|||
⚫ | |||
if ( Array.isArray(selected) ) { |
|||
return selected.map( function ( item ) { |
|||
return item.getData(); |
|||
} |
} ); |
||
} else if ( selected !== null ) { |
|||
paramVal.delete( item.label ); |
|||
return [ selected.getData() ]; |
|||
⚫ | |||
console.log(paramVal.values()); |
|||
⚫ | |||
⚫ | |||
if ( item.value ) { |
|||
paramVal.add( item.label ); |
|||
} |
} |
||
return |
return []; |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
title: widgetOptions.title |
|||
} ); |
} ); |
||
var widget = new OO.ui.ButtonGroupWidget( { |
|||
items: toggleButtons, |
|||
⚫ | |||
} ); |
|||
this.paramWidgets[ param ] = widget; |
|||
this.fieldset.addItems( [ |
|||
new OO.ui.FieldLayout( widget, { |
|||
label: fieldOptions.label, |
|||
align: fieldOptions.align || 'top' |
|||
} ), |
|||
] ); |
|||
}; |
}; |
||
Line 90: | Line 71: | ||
QueryOptions.prototype.getOptions = function() { |
QueryOptions.prototype.getOptions = function() { |
||
var opts = {}; |
var opts = {}; |
||
⚫ | |||
for ( var key in this.getters ) { |
|||
opts[ key ] = this.getters[ key ](); |
|||
⚫ | |||
return opts; |
return opts; |
||
Line 139: | Line 124: | ||
new OO.ui.FieldLayout( this.submitButton ) |
new OO.ui.FieldLayout( this.submitButton ) |
||
] ); |
] ); |
||
⚫ | |||
this.submitButton.on('click', function() { |
|||
console.log( config.queryOptions.getOptions() ); |
|||
⚫ | |||
} |
} |
||
Revision as of 22:16, 21 December 2021
( function ( $, mw ) {
'use strict';
mw.loader.using( ['oojs-ui-core', 'oojs-ui-widgets'] ).done( function() {
/*
* 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.addCheckboxInput = function ( param, fieldOptions, widgetOptions ) {
var widget = new OO.ui.CheckboxInputWidget( {
data: widgetOptions.data,
label: widgetOptions.label,
title: widgetOptions.title
} );
};
QueryOptions.prototype.addCheckboxMultiselect = 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 );
window.pswiki.dbUtil = {
QueryOptions: QueryOptions,
DisplayOptions: DisplayOptions,
SearchWidget: SearchWidget
};
} );
} )( jQuery, mediaWiki );