r99904 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99903‎ | r99904 | r99905 >
Date:19:46, 15 October 2011
Author:maxsem
Status:ok
Tags:
Comment:
Fixed genrator and extra params display
Modified paths:
  • /trunk/extensions/ApiSandbox/SpecialApiSandbox.php (modified) (history)
  • /trunk/extensions/ApiSandbox/ext.apiSandbox.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ApiSandbox/SpecialApiSandbox.php
@@ -89,7 +89,7 @@
9090 . '</td></tr>
9191 </table>
9292 ';
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>'
9494 . $this->openFieldset( 'generic-parameters' )
9595 . '<div id="api-sandbox-generic-inputs" class="mw-collapsible mw-collapsed"></div></fieldset>'
9696 . $this->openFieldset( 'generator-parameters', array( 'style' => 'display: none;' ) )
Index: trunk/extensions/ApiSandbox/ext.apiSandbox.js
@@ -7,10 +7,11 @@
88 * @param info {Object} Query information
99 * @param prefix {String} Additional prefix for parameter names
1010 */
11 - function UiBuilder( $container, info, prefix ) {
 11+ function UiBuilder( $container, info, prefix, params ) {
1212 this.$container = $container;
1313 this.info = info;
1414 this.prefix = prefix + info.prefix;
 15+ this.params = isset( params ) ? params : info.parameters;
1516
1617 this.createInputs();
1718 }
@@ -21,8 +22,8 @@
2223 */
2324 createInputs: function() {
2425 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],
2728 name = this.prefix + param.name;
2829
2930 s += '<tr><td class="api-sandbox-label"><label for="param-' + name + '">' + name + '=</label></td>'
@@ -148,6 +149,8 @@
149150 $mainContainer = $( '#api-sandbox-main-inputs' ),
150151 $genericContainer, // will be set later
151152 $generatorContainer = $( '#api-sandbox-generator-inputs' ),
 153+ $queryContainer = $( '#api-sandbox-query-inputs' ),
 154+ $generatorBox = $( '#api-sandbox-generator-parameters' ),
152155 $submit = $( '#api-sandbox-submit' ),
153156 $requestUrl = $( '#api-sandbox-url' ),
154157 $requestPost = $( '#api-sandbox-post' ),
@@ -155,9 +158,10 @@
156159 $postRow = $( '#api-sandbox-post-row' );
157160
158161 // UiBuilder objects
159 - var mainQuery,
160 - genericQuery,
161 - generatorQuery;
 162+ var mainRequest,
 163+ genericRequest,
 164+ generatorRequest,
 165+ queryRequest;
162166
163167 // cached stuff
164168 var paramInfo = { modules: {}, querymodules: {} },
@@ -191,7 +195,10 @@
192196 paramInfo.mainmodule.parameters.shift(); // remove format
193197 paramInfo.mainmodule.parameters.shift(); // ...and action
194198 $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+ );
196203 },
197204 function() {}
198205 );
@@ -202,32 +209,34 @@
203210 $( '#param-generator' ).live( 'change', function() {
204211 var generator = $( '#param-generator' ).val();
205212 if ( generator == '' ) {
206 - $generatorContainer.hide();
 213+ $generatorBox.hide();
207214 } else {
 215+ $generatorBox.show();
208216 getParamInfo( { querymodules: generator },
209217 function() { showLoading( $generatorContainer ); },
210218 function() {
211 - generatorQuery = new UiBuilder( $generatorContainer, paramInfo.querymodules[generator], 'g' );
212 - $generatorContainer.show();
 219+ generatorRequest = new UiBuilder( $generatorContainer, paramInfo.querymodules[generator], 'g' );
213220 },
214 - function() {}
 221+ function() {
 222+ showLoadError( $generatorContainer, 'apisb-request-error' );
 223+ }
215224 );
216225 }
217226 } );
218227
219228 $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 );
221232 if ( $action.val() == 'query' ) {
222233 url += '&' + $query.val();
 234+ params += queryRequest.getRequestData();
223235 }
224236 url += '&format=' + $format.val();
225237
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();
232241 }
233242
234243 showLoading( $output );
@@ -360,12 +369,12 @@
361370 function() {
362371 var info;
363372 if ( isQuery ) {
364 - info = merge( paramInfo.querymodules[query], paramInfo.modules.query, paramInfo.pagesetmodule );
 373+ info = paramInfo.querymodules[query];
365374 } else {
366375 info = paramInfo.modules[action];
367376 }
368 - mainQuery = new UiBuilder( $mainContainer, info, '' );
369 - mainQuery.setHelp( $help );
 377+ mainRequest = new UiBuilder( $mainContainer, info, '' );
 378+ mainRequest.setHelp( $help );
370379 $submit.removeAttr( 'disabled' );
371380 },
372381 function() {
@@ -400,15 +409,19 @@
401410 isQuery = a == 'query';
402411 if ( isQuery ) {
403412 $queryRow.show();
404 - $( '#api-sandbox-generator-parameters' ).show();
 413+ if ( q != '-' ) {
 414+ $queryContainer.show();
 415+ } else {
 416+ $queryContainer.hide();
 417+ }
405418 } else {
406419 $queryRow.hide();
407 - $( '#api-sandbox-generator-parameters' ).hide();
 420+ $queryContainer.hide();
408421 }
409422 $mainContainer.text( '' );
410423 $help.text( '' );
411424 updateQueryInfo( a, q );
412 - $generatorContainer.hide();
 425+ $generatorBox.hide();
413426 }
414427
415428 });
\ No newline at end of file

Status & tagging log