suppressErrors = true,
updatingBooklet = false,
pages = {},
- moduleInfoCache = {};
+ moduleInfoCache = {},
+ baseRequestParams;
WidgetMethods = {
textInputWidget: {
capsuleWidget: {
getApiValue: function () {
- return this.getItemsData().join( '|' );
+ var items = this.getItemsData();
+ if ( items.join( '' ).indexOf( '|' ) === -1 ) {
+ return items.join( '|' );
+ } else {
+ return '\x1f' + items.join( '\x1f' );
+ }
},
setApiValue: function ( v ) {
- this.setItemsFromData( v === undefined || v === '' ? [] : String( v ).split( '|' ) );
+ if ( v === undefined || v === '' || v === '\x1f' ) {
+ this.setItemsFromData( [] );
+ } else {
+ v = String( v );
+ if ( v.indexOf( '\x1f' ) !== 0 ) {
+ this.setItemsFromData( v.split( '|' ) );
+ } else {
+ this.setItemsFromData( v.substr( 1 ).split( '\x1f' ) );
+ }
+ }
},
apiCheckValid: function () {
var ok = this.getApiValue() !== undefined || suppressErrors;
}
} );
} else if ( Util.apiBool( pi.multi ) ) {
- widget = new OO.ui.CapsuleMultiSelectWidget( {
+ widget = new OO.ui.CapsuleMultiselectWidget( {
allowArbitrary: true
} );
widget.paramInfo = pi;
return a.data - b.data;
} );
if ( Util.apiBool( pi.multi ) ) {
- widget = new OO.ui.CapsuleMultiSelectWidget( {
+ widget = new OO.ui.CapsuleMultiselectWidget( {
menu: { items: items }
} );
widget.paramInfo = pi;
return new OO.ui.MenuOptionWidget( { data: String( v ), label: String( v ) } );
} );
if ( Util.apiBool( pi.multi ) ) {
- widget = new OO.ui.CapsuleMultiSelectWidget( {
+ widget = new OO.ui.CapsuleMultiselectWidget( {
menu: { items: items }
} );
widget.paramInfo = pi;
throw new Error( 'Unknown multiMode "' + multiMode + '"' );
}
- widget = new OO.ui.CapsuleMultiSelectWidget( {
+ widget = new OO.ui.CapsuleMultiselectWidget( {
allowArbitrary: true,
popup: {
classes: [ 'mw-apisandbox-popup' ],
*
* @class mw.special.ApiSandbox
*/
- mw.special.ApiSandbox = ApiSandbox = {
+ ApiSandbox = {
/**
* Initialize the UI
*
fullscreenButton.$element,
new OO.ui.ButtonWidget( {
label: mw.message( 'apisandbox-submit' ).text(),
- flags: [ 'primary', 'constructive' ]
+ flags: [ 'primary', 'progressive' ]
} ).on( 'click', ApiSandbox.sendRequest ).$element,
new OO.ui.ButtonWidget( {
label: mw.message( 'apisandbox-reset' ).text(),
/**
* Submit button handler
+ *
+ * @param {Object} [params] Use this set of params instead of those in the form fields.
+ * The form fields will be updated to match.
*/
- sendRequest: function () {
+ sendRequest: function ( params ) {
var page, subpages, i, query, $result, $focus,
progress, $progressText, progressLoading,
deferreds = [],
- params = {},
+ paramsAreForced = !!params,
displayParams = {},
checkPages = [ pages.main ];
suppressErrors = false;
+ // save widget state in params (or load from it if we are forced)
+ if ( paramsAreForced ) {
+ ApiSandbox.updateUI( params );
+ }
+ params = {};
while ( checkPages.length ) {
page = checkPages.shift();
deferreds.push( page.apiCheckValid() );
}
}
+ if ( !paramsAreForced ) {
+ // forced params means we are continuing a query; the base query should be preserved
+ baseRequestParams = $.extend( {}, params );
+ }
+
$.when.apply( $, deferreds ).done( function () {
if ( $.inArray( false, arguments ) !== -1 ) {
windowManager.openWindow( 'errorAlert', {
);
} )
.done( function ( data, jqXHR ) {
- var m, loadTime, button,
+ var m, loadTime, button, clear,
ct = jqXHR.getResponseHeader( 'Content-Type' );
$result.empty();
.text( data )
.appendTo( $result );
}
+ if ( paramsAreForced || data[ 'continue' ] ) {
+ $result.append(
+ $( '<div>' ).append(
+ new OO.ui.ButtonWidget( {
+ label: mw.message( 'apisandbox-continue' ).text()
+ } ).on( 'click', function () {
+ ApiSandbox.sendRequest( $.extend( {}, baseRequestParams, data[ 'continue' ] ) );
+ } ).setDisabled( !data[ 'continue' ] ).$element,
+ ( clear = new OO.ui.ButtonWidget( {
+ label: mw.message( 'apisandbox-continue-clear' ).text()
+ } ).on( 'click', function () {
+ ApiSandbox.updateUI( baseRequestParams );
+ clear.setDisabled( true );
+ booklet.setPage( '|results|' );
+ } ).setDisabled( !paramsAreForced ) ).$element,
+ new OO.ui.PopupButtonWidget( {
+ framed: false,
+ icon: 'info',
+ popup: {
+ $content: $( '<div>' ).append( mw.message( 'apisandbox-continue-help' ).parse() ),
+ padded: true
+ }
+ } ).$element
+ )
+ );
+ }
if ( typeof loadTime === 'number' ) {
$result.append(
$( '<div>' ).append(
}
if ( Util.apiBool( pi.parameters[ i ].multi ) ) {
tmp = [];
- if ( flag && !( widget instanceof OO.ui.CapsuleMultiSelectWidget ) &&
+ if ( flag && !( widget instanceof OO.ui.CapsuleMultiselectWidget ) &&
!(
widget instanceof OptionalWidget &&
- widget.widget instanceof OO.ui.CapsuleMultiSelectWidget
+ widget.widget instanceof OO.ui.CapsuleMultiselectWidget
)
) {
tmp.push( mw.message( 'api-help-param-multi-separate' ).parse() );
dynamicParamNameWidget,
new OO.ui.ButtonWidget( {
icon: 'add',
- flags: 'constructive'
+ flags: 'progressive'
} ).on( 'click', addDynamicParamWidget ),
{
label: mw.message( 'apisandbox-dynamic-parameters-add-label' ).text(),
$( ApiSandbox.init );
+ module.exports = ApiSandbox;
+
}( jQuery, mediaWiki, OO ) );