Index: trunk/extensions/ApiSandbox/ext.apiSandbox.js |
— | — | @@ -49,28 +49,34 @@ |
50 | 50 | $prop.change( updateBasics ); |
51 | 51 | |
52 | 52 | $submit.click( function() { |
53 | | - var url = apiPhp + '?action=' + $action.val(); |
| 53 | + var url = apiPhp + '?action=' + $action.val(), |
| 54 | + info = currentInfo; // in case it changes later |
54 | 55 | if ( $action.val() == 'query' ) { |
55 | 56 | url += '&prop=' + $prop.val(); |
56 | 57 | } |
57 | 58 | url += '&format=json'; // @todo: |
58 | 59 | var params = ''; |
59 | | - for ( var i = 0; i < currentInfo.parameters.length; i++ ) { |
60 | | - var param = currentInfo.parameters[i]; |
61 | | - var name = currentInfo.prefix + param.name; |
62 | | - var value = $( '#param-' + name ).val(); |
63 | | - if ( param.value == '' |
64 | | - && ( param.type != 'boolean' && param.type != 'bool' ) |
65 | | - && !isset( param.required ) ) |
66 | | - { |
67 | | - value = null; |
68 | | - } |
69 | | - if ( typeof value != 'undefined' ) { |
| 60 | + for ( var i = 0; i < info.parameters.length; i++ ) { |
| 61 | + var param = info.parameters[i], |
| 62 | + name = info.prefix + param.name, |
| 63 | + $node = $( '#param-' + name ); |
| 64 | + if ( param.type == 'boolean' ) { |
| 65 | + if ( $node.attr( 'checked' ) ) { |
| 66 | + params += '&' + name; |
| 67 | + } |
| 68 | + } else { |
| 69 | + var value = $node.val(); |
| 70 | + if ( !isset( value ) || value == '' ) { |
| 71 | + continue; |
| 72 | + } |
| 73 | + if ( $.isArray( value ) ) { |
| 74 | + value = value.join( '|' ); |
| 75 | + } |
70 | 76 | params += '&' + name + '=' + encodeURIComponent( value ); |
71 | 77 | } |
72 | 78 | } |
73 | 79 | showLoading( $output ); |
74 | | - if ( isset( currentInfo.mustbeposted ) ) { |
| 80 | + if ( isset( info.mustbeposted ) ) { |
75 | 81 | $requestUrl.val( url ); |
76 | 82 | $requestPost.val( params ); |
77 | 83 | $postRow.show(); |
— | — | @@ -83,7 +89,7 @@ |
84 | 90 | url: url, |
85 | 91 | data: params, |
86 | 92 | dataType: 'text', |
87 | | - type: isset( currentInfo.mustbeposted ) ? 'POST' : 'GET', |
| 93 | + type: isset( info.mustbeposted ) ? 'POST' : 'GET', |
88 | 94 | success: function( data ) { |
89 | 95 | data = data.match( /<pre>[\s\S]*<\/pre>/ )[0]; |
90 | 96 | $output.html( data ); |
— | — | @@ -206,6 +212,7 @@ |
207 | 213 | s = '<input class="api-sandbox-input" id="param-' + name + '" value="' + value + '"/>'; |
208 | 214 | break; |
209 | 215 | case 'bool': |
| 216 | + param.type = 'boolean'; // normalisation for later use |
210 | 217 | case 'boolean': |
211 | 218 | s = '<input id="param-' + name + '" type="checkbox"/>'; |
212 | 219 | break; |