Index: trunk/extensions/ApiSandbox/SpecialApiSandbox.php |
— | — | @@ -89,7 +89,7 @@ |
90 | 90 | . '</td></tr> |
91 | 91 | </table> |
92 | 92 | '; |
93 | | - $s .= '<div id="api-sandbox-main-inputs"></div>' |
| 93 | + $s .= '<div id="api-sandbox-main-inputs"></div><div id="api-sandbox-query-inputs" style="display: none"></div>' |
94 | 94 | . $this->openFieldset( 'generic-parameters' ) |
95 | 95 | . '<div id="api-sandbox-generic-inputs" class="mw-collapsible mw-collapsed"></div></fieldset>' |
96 | 96 | . $this->openFieldset( 'generator-parameters', array( 'style' => 'display: none;' ) ) |
Index: trunk/extensions/ApiSandbox/ext.apiSandbox.js |
— | — | @@ -7,10 +7,11 @@ |
8 | 8 | * @param info {Object} Query information |
9 | 9 | * @param prefix {String} Additional prefix for parameter names |
10 | 10 | */ |
11 | | - function UiBuilder( $container, info, prefix ) { |
| 11 | + function UiBuilder( $container, info, prefix, params ) { |
12 | 12 | this.$container = $container; |
13 | 13 | this.info = info; |
14 | 14 | this.prefix = prefix + info.prefix; |
| 15 | + this.params = isset( params ) ? params : info.parameters; |
15 | 16 | |
16 | 17 | this.createInputs(); |
17 | 18 | } |
— | — | @@ -21,8 +22,8 @@ |
22 | 23 | */ |
23 | 24 | createInputs: function() { |
24 | 25 | var s = '<table class="api-sandbox-options">\n<tbody>'; |
25 | | - for ( var i = 0; i < this.info.parameters.length; i++ ) { |
26 | | - var param = this.info.parameters[i], |
| 26 | + for ( var i = 0; i < this.params.length; i++ ) { |
| 27 | + var param = this.params[i], |
27 | 28 | name = this.prefix + param.name; |
28 | 29 | |
29 | 30 | s += '<tr><td class="api-sandbox-label"><label for="param-' + name + '">' + name + '=</label></td>' |
— | — | @@ -148,6 +149,8 @@ |
149 | 150 | $mainContainer = $( '#api-sandbox-main-inputs' ), |
150 | 151 | $genericContainer, // will be set later |
151 | 152 | $generatorContainer = $( '#api-sandbox-generator-inputs' ), |
| 153 | + $queryContainer = $( '#api-sandbox-query-inputs' ), |
| 154 | + $generatorBox = $( '#api-sandbox-generator-parameters' ), |
152 | 155 | $submit = $( '#api-sandbox-submit' ), |
153 | 156 | $requestUrl = $( '#api-sandbox-url' ), |
154 | 157 | $requestPost = $( '#api-sandbox-post' ), |
— | — | @@ -155,9 +158,10 @@ |
156 | 159 | $postRow = $( '#api-sandbox-post-row' ); |
157 | 160 | |
158 | 161 | // UiBuilder objects |
159 | | - var mainQuery, |
160 | | - genericQuery, |
161 | | - generatorQuery; |
| 162 | + var mainRequest, |
| 163 | + genericRequest, |
| 164 | + generatorRequest, |
| 165 | + queryRequest; |
162 | 166 | |
163 | 167 | // cached stuff |
164 | 168 | var paramInfo = { modules: {}, querymodules: {} }, |
— | — | @@ -191,7 +195,10 @@ |
192 | 196 | paramInfo.mainmodule.parameters.shift(); // remove format |
193 | 197 | paramInfo.mainmodule.parameters.shift(); // ...and action |
194 | 198 | $genericContainer = $( '#api-sandbox-generic-inputs > div' ); |
195 | | - genericQuery = new UiBuilder( $genericContainer, paramInfo.mainmodule, '' ); |
| 199 | + genericRequest = new UiBuilder( $genericContainer, paramInfo.mainmodule, '' ); |
| 200 | + queryRequest = new UiBuilder( $queryContainer, paramInfo.modules.query, '', |
| 201 | + [].concat( paramInfo.modules.query.parameters, paramInfo.pagesetmodule.parameters ) |
| 202 | + ); |
196 | 203 | }, |
197 | 204 | function() {} |
198 | 205 | ); |
— | — | @@ -202,32 +209,34 @@ |
203 | 210 | $( '#param-generator' ).live( 'change', function() { |
204 | 211 | var generator = $( '#param-generator' ).val(); |
205 | 212 | if ( generator == '' ) { |
206 | | - $generatorContainer.hide(); |
| 213 | + $generatorBox.hide(); |
207 | 214 | } else { |
| 215 | + $generatorBox.show(); |
208 | 216 | getParamInfo( { querymodules: generator }, |
209 | 217 | function() { showLoading( $generatorContainer ); }, |
210 | 218 | function() { |
211 | | - generatorQuery = new UiBuilder( $generatorContainer, paramInfo.querymodules[generator], 'g' ); |
212 | | - $generatorContainer.show(); |
| 219 | + generatorRequest = new UiBuilder( $generatorContainer, paramInfo.querymodules[generator], 'g' ); |
213 | 220 | }, |
214 | | - function() {} |
| 221 | + function() { |
| 222 | + showLoadError( $generatorContainer, 'apisb-request-error' ); |
| 223 | + } |
215 | 224 | ); |
216 | 225 | } |
217 | 226 | } ); |
218 | 227 | |
219 | 228 | $submit.click( function() { |
220 | | - var url = mw.util.wikiScript( 'api' ) + '?action=' + $action.val(); |
| 229 | + var url = mw.util.wikiScript( 'api' ) + '?action=' + $action.val(), |
| 230 | + params = mainRequest.getRequestData(), |
| 231 | + mustBePosted = isset( mainRequest.info.mustbeposted ); |
221 | 232 | if ( $action.val() == 'query' ) { |
222 | 233 | url += '&' + $query.val(); |
| 234 | + params += queryRequest.getRequestData(); |
223 | 235 | } |
224 | 236 | url += '&format=' + $format.val(); |
225 | 237 | |
226 | | - var params = mainQuery.getRequestData(), |
227 | | - mustBePosted = isset( mainQuery.info.mustbeposted ); |
228 | | - |
229 | | - params += genericQuery.getRequestData(); |
230 | | - if ( $( '#param-generator' ).val() != '' ) { |
231 | | - params += generatorQuery.getRequestData(); |
| 238 | + params += genericRequest.getRequestData(); |
| 239 | + if ( $( '#param-generator' ).length && $( '#param-generator' ).val() != '' ) { |
| 240 | + params += generatorRequest.getRequestData(); |
232 | 241 | } |
233 | 242 | |
234 | 243 | showLoading( $output ); |
— | — | @@ -360,12 +369,12 @@ |
361 | 370 | function() { |
362 | 371 | var info; |
363 | 372 | if ( isQuery ) { |
364 | | - info = merge( paramInfo.querymodules[query], paramInfo.modules.query, paramInfo.pagesetmodule ); |
| 373 | + info = paramInfo.querymodules[query]; |
365 | 374 | } else { |
366 | 375 | info = paramInfo.modules[action]; |
367 | 376 | } |
368 | | - mainQuery = new UiBuilder( $mainContainer, info, '' ); |
369 | | - mainQuery.setHelp( $help ); |
| 377 | + mainRequest = new UiBuilder( $mainContainer, info, '' ); |
| 378 | + mainRequest.setHelp( $help ); |
370 | 379 | $submit.removeAttr( 'disabled' ); |
371 | 380 | }, |
372 | 381 | function() { |
— | — | @@ -400,15 +409,19 @@ |
401 | 410 | isQuery = a == 'query'; |
402 | 411 | if ( isQuery ) { |
403 | 412 | $queryRow.show(); |
404 | | - $( '#api-sandbox-generator-parameters' ).show(); |
| 413 | + if ( q != '-' ) { |
| 414 | + $queryContainer.show(); |
| 415 | + } else { |
| 416 | + $queryContainer.hide(); |
| 417 | + } |
405 | 418 | } else { |
406 | 419 | $queryRow.hide(); |
407 | | - $( '#api-sandbox-generator-parameters' ).hide(); |
| 420 | + $queryContainer.hide(); |
408 | 421 | } |
409 | 422 | $mainContainer.text( '' ); |
410 | 423 | $help.text( '' ); |
411 | 424 | updateQueryInfo( a, q ); |
412 | | - $generatorContainer.hide(); |
| 425 | + $generatorBox.hide(); |
413 | 426 | } |
414 | 427 | |
415 | 428 | }); |
\ No newline at end of file |