Changeset 1852 for trunk/tools/ws.htm
- Timestamp:
- Feb 23, 2007, 2:18:34 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/ws.htm
r1849 r1852 6 6 7 7 <script type="text/javascript"> 8 function setElementText(id, text)9 {10 if (!text) text="";11 var elt = document.getElementById(id);12 if (!elt) alert('setElementText '+id);13 elt.innerHTML = text;14 }15 8 16 9 function setVisibility(id, vis) 17 10 { 18 document.getElementById(id).style.visibility = vis; 19 } 20 21 function clearError() 22 { 23 setElementText("error", ""); 11 $(id).style.visibility = vis; 24 12 } 25 13 … … 38 26 } 39 27 } 40 setElementText("error",s);28 $("error").update(s); 41 29 } 42 30 43 31 var gServiceUrl; 44 var gC urrentMethodParams;32 var gCachedMethods; 45 33 46 34 Ajax.Responders.register({ … … 101 89 function pwgChangeUrl() 102 90 { 103 clearError();91 $("error").update(""); 104 92 setVisibility("methodListWrapper", "hidden"); 105 setElementText("methodList","");93 $("methodList").update(""); 106 94 setVisibility("methodWrapper", "hidden"); 95 setVisibility("methodDetailWrapper", "hidden"); 107 96 108 97 gServiceUrl = $F('ws_url'); 109 gC urrentMethodParams = null;98 gCachedMethods = new Hash(); 110 99 111 100 try { … … 131 120 ml += '<li><a href="#" onclick="return pwgSelectMethod(this.innerHTML)">'+ result.methods[i]+'</a></li>'; 132 121 } 133 setElementText("methodList",ml);122 $("methodList").update(ml); 134 123 setVisibility("methodListWrapper", "visible"); 135 124 } 136 125 137 function pwgSelectMethod(method )138 { 139 clearError();140 setElementText("methodName", method);126 function pwgSelectMethod(methodName) 127 { 128 $("error").update(""); 129 $("methodName").update(methodName); 141 130 setVisibility("methodDetailWrapper", "hidden"); 142 131 setVisibility("methodWrapper", "visible"); 143 gCurrentMethodParams = null; 144 145 try { 146 147 var ajaxReq = new Ajax.Request( 148 gServiceUrl, 149 {method:'get', parameters:'format=json&method=reflection.getMethodDetails&methodName='+method, 150 onSuccess: function (r) { onSuccess_getMethodDetails(r); } 151 } 152 ) 153 }catch (e) 132 133 if ( gCachedMethods[methodName] ) 134 fillNewMethod( gCachedMethods[methodName] ); 135 else 154 136 { 155 dumpError( e ); 137 try { 138 var ajaxReq = new Ajax.Request( 139 gServiceUrl, 140 {method:'get', parameters:'format=json&method=reflection.getMethodDetails&methodName='+methodName, 141 onSuccess: function (r) { onSuccess_getMethodDetails(r); } 142 } 143 ) 144 }catch (e) 145 { 146 dumpError( e ); 147 } 156 148 } 157 149 return false; … … 161 153 { 162 154 var result = pwgGetJsonResult(transport); 155 fillNewMethod( gCachedMethods[result.name] = $H(result) ); 156 } 157 158 function fillNewMethod(method) 159 { 163 160 var methodParamsElt = $("methodParams"); 164 161 while (methodParamsElt.tBodies[0].rows.length) 165 162 methodParamsElt.tBodies[0].deleteRow(methodParamsElt.tBodies[0].rows.length-1); 166 163 167 if (result.params) 168 { 169 gCurrentMethodParams = result.params; 170 if (result.params.length>0) 171 { 172 for (var i=0; i<result.params.length; i++) 164 if (method.params && method.params.length>0) 165 { 166 for (var i=0; i<method.params.length; i++) 173 167 { 174 168 var row = methodParamsElt.tBodies[0].insertRow(-1); 175 var isOptional = result.params[i].optional; 176 var defaultValue = result.params[i].defaultValue == null ? '' : result.params[i].defaultValue; 169 var isOptional = method.params[i].optional; 170 var acceptArray = method.params[i].acceptArray; 171 var defaultValue = method.params[i].defaultValue == null ? '' : method.params[i].defaultValue; 177 172 178 row.insertCell(0).innerHTML = result.params[i].name; 179 row.insertCell(1).innerHTML = (isOptional ? 'optional':'required'); 173 row.insertCell(0).innerHTML = method.params[i].name; 174 row.insertCell(1).innerHTML = '<span title="parameter is '+(isOptional ? 'optional':'required') +'">'+(isOptional ? '?':'*')+'</span>' 175 + (method.params[i].acceptArray ? ' <span title="parameter can be an array; use | (pipe) character to split values">[ ]</span>':''); 180 176 row.insertCell(2).innerHTML = '<input id="methodParameterSend_'+i+'" type="checkbox" '+(isOptional ? '':'checked="checked"')+'/>'; 181 177 row.insertCell(3).innerHTML = '<input id="methodParameterValue_'+i+'"" value="'+defaultValue+'" style="width:99%" onchange="$(\'methodParameterSend_'+i+'\').checked=true;"/>'; 182 178 } 183 } 184 } 185 setElementText("methodDescription", result.description); 179 } 180 $("methodDescription").update(method.description); 186 181 setVisibility("methodDetailWrapper", "visible"); 187 182 } … … 189 184 function pwgInvokeMethod( newWindow ) 190 185 { 191 var method = document.getElementById('methodName').innerHTML; 186 var methodName = $('methodName').innerHTML; 187 var method = gCachedMethods[methodName]; 192 188 193 189 var reqUrl = gServiceUrl; 194 190 reqUrl += "?format="+$F('responseFormat'); 195 191 196 if ( document.getElementById('requestFormat').value == 'get')192 if ($('requestFormat').value == 'get') 197 193 { 198 reqUrl += "&method="+method ;199 for ( var i=0; i< gCurrentMethodParams.length; i++)194 reqUrl += "&method="+methodName; 195 for ( var i=0; i<method.params.length; i++) 200 196 { 201 if (document.getElementById('methodParameterSend_'+i).checked) 202 reqUrl += '&'+gCurrentMethodParams[i].name+'='+$F('methodParameterValue_'+i); 197 if (! $('methodParameterSend_'+i).checked) 198 continue; 199 200 if ( method.params[i].acceptArray && $F('methodParameterValue_'+i).split('|').length > 1 ) 201 { 202 $F('methodParameterValue_'+i).split('|').each( 203 function(v) { 204 reqUrl += '&'+method.params[i].name+'[]='+v; 205 } 206 ); 207 } 208 else 209 reqUrl += '&'+method.params[i].name+'='+$F('methodParameterValue_'+i); 203 210 } 204 211 if ( !newWindow ) 205 document.getElementById("invokeFrame").src = reqUrl;212 $("invokeFrame").src = reqUrl; 206 213 else 207 214 window.open(reqUrl); … … 209 216 else 210 217 { 211 var form = document.getElementById("invokeForm");218 var form = $("invokeForm"); 212 219 form.action = reqUrl; 213 var t = '<input type="hidden" name="'+'method'+'" value="'+method +'"/>';214 for ( var i=0; i< gCurrentMethodParams.length; i++)220 var t = '<input type="hidden" name="'+'method'+'" value="'+methodName+'"/>'; 221 for ( var i=0; i<method.params.length; i++) 215 222 { 216 if (document.getElementById('methodParameterSend_'+i).checked) 217 t += '<input type="hidden" name="'+gCurrentMethodParams[i].name+'" value="'+$F('methodParameterValue_'+i)+'"/>'; 223 if (! $('methodParameterSend_'+i).checked) 224 continue; 225 226 if ( method.params[i].acceptArray && $F('methodParameterValue_'+i).split('|').length > 1 ) 227 { 228 $F('methodParameterValue_'+i).split('|').each( 229 function(v) { 230 t += '<input type="hidden" name="'+method.params[i].name+'[]" value="'+v+'"/>'; 231 } 232 ); 233 } 234 else 235 t += '<input type="hidden" name="'+method.params[i].name+'" value="'+$F('methodParameterValue_'+i)+'"/>'; 218 236 } 219 237 form.innerHTML = t; 220 if ( !newWindow ) 221 form.target = "invokeFrame"; 222 else 223 form.target = "_blank"; 238 form.target = newWindow ? "_blank" : "invokeFrame"; 224 239 form.submit(); 225 240 } … … 357 372 <tr> 358 373 <td style="width:150px">Parameter</td> 359 <td> Optional</td>374 <td>Extra</td> 360 375 <td>Send</td> 361 376 <td style="width:160px">Value</td>
Note: See TracChangeset
for help on using the changeset viewer.