jest 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  1. var Describe = function() {
  2. // 20180730
  3. }
  4. Describe.splitValue = function(str) {
  5. if (str) {
  6. if (str.length > 0) {
  7. return str.split(',');
  8. }
  9. }
  10. return [];
  11. }
  12. Describe.joinValue = function(o, split) {
  13. var s = ',';
  14. if (split) {
  15. s = '' + split;
  16. }
  17. if (o) {
  18. if (toString.apply(o) === '[object Array]') {
  19. return o.join(s);
  20. }
  21. }
  22. return o;
  23. }
  24. Describe.doPost = function(address, m, data) {
  25. $('#url').html(address);
  26. if ((m.resultContentType) && m.resultContentType.indexOf('application/json') > -1) {
  27. $.ajax({
  28. url : address,
  29. type : 'POST',
  30. headers : {
  31. 'x-debugger' : true
  32. },
  33. contentType : (m.contentType.indexOf('application/json') > -1) ? m.contentType : m.contentType,
  34. processData : (m.contentType.indexOf('application/json') > -1) ? true : false,
  35. xhrFields : {
  36. 'withCredentials' : true
  37. },
  38. data : ((m.contentType.indexOf('application/json') > -1) && (!m.useStringParameter) ? JSON.stringify(data) : data)
  39. }).always(function(resultJson) {
  40. $('#result').html(JSON.stringify(resultJson, null, 4));
  41. Describe.writeOut(m.outs, resultJson);
  42. });
  43. } else {
  44. $.ajax({
  45. url : address,
  46. type : 'POST',
  47. headers : {
  48. 'x-debugger' : true
  49. },
  50. contentType : (m.contentType.indexOf('application/json') > -1) ? m.contentType : false,
  51. processData : (m.contentType.indexOf('application/json') > -1) ? true : false,
  52. xhrFields : {
  53. 'withCredentials' : true
  54. },
  55. data : ((m.contentType.indexOf('application/json') > -1) && (!m.useStringParameter) ? JSON.stringify(data) : data)
  56. });
  57. }
  58. }
  59. Describe.doPut = function(address, m, data) {
  60. $('#url').html(address);
  61. if ((m.resultContentType) && m.resultContentType.indexOf('application/json') > -1) {
  62. $.ajax({
  63. url : address,
  64. type : 'PUT',
  65. headers : {
  66. 'x-debugger' : true
  67. },
  68. contentType : (m.contentType.indexOf('application/json') > -1) ? m.contentType : false,
  69. processData : (m.contentType.indexOf('application/json') > -1) ? true : false,
  70. xhrFields : {
  71. 'withCredentials' : true
  72. },
  73. data : ((m.contentType.indexOf('application/json') > -1) && (!m.useStringParameter) ? JSON.stringify(data) : data)
  74. }).always(function(resultJson) {
  75. $('#result').html(JSON.stringify(resultJson, null, 4));
  76. Describe.writeOut(m.outs, resultJson);
  77. });
  78. } else {
  79. $.ajax({
  80. url : address,
  81. type : 'PUT',
  82. headers : {
  83. 'x-debugger' : true
  84. },
  85. contentType : (m.contentType.indexOf('application/json') > -1) ? m.contentType : false,
  86. processData : (m.contentType.indexOf('application/json') > -1) ? true : false,
  87. xhrFields : {
  88. 'withCredentials' : true
  89. },
  90. data : ((m.contentType.indexOf('application/json') > -1) && (!m.useStringParameter) ? JSON.stringify(data) : data)
  91. });
  92. }
  93. }
  94. Describe.doGet = function(address, m) {
  95. $('#url').html(address);
  96. if ((m.resultContentType) && m.resultContentType.indexOf('application/json') > -1) {
  97. $.ajax({
  98. type : 'GET',
  99. dataType : 'json',
  100. url : address,
  101. headers : {
  102. 'x-debugger' : true
  103. },
  104. contentType : m.contentType,
  105. xhrFields : {
  106. 'withCredentials' : true
  107. },
  108. crossDomain : true
  109. }).always(function(resultJson) {
  110. $('#result').html(JSON.stringify(resultJson, null, 4));
  111. Describe.writeOut(m.outs, resultJson);
  112. });
  113. } else {
  114. window.open(address, '_blank');
  115. }
  116. }
  117. Describe.doDelete = function(address, m) {
  118. $('#url').html(address);
  119. if ((m.resultContentType) && m.resultContentType.indexOf('application/json') > -1) {
  120. $.ajax({
  121. type : 'DELETE',
  122. dataType : 'json',
  123. url : address,
  124. headers : {
  125. 'x-debugger' : true
  126. },
  127. contentType : m.contentType,
  128. xhrFields : {
  129. 'withCredentials' : true
  130. },
  131. crossDomain : true
  132. }).always(function(resultJson) {
  133. $('#result').html(JSON.stringify(resultJson, null, 4));
  134. Describe.writeOut(m.outs, resultJson);
  135. });
  136. } else {
  137. $.ajax({
  138. type : 'DELETE',
  139. dataType : 'json',
  140. url : address,
  141. headers : {
  142. 'x-debugger' : true
  143. },
  144. contentType : m.contentType,
  145. xhrFields : {
  146. 'withCredentials' : true
  147. },
  148. crossDomain : true
  149. });
  150. }
  151. }
  152. Describe.writeOut = function(outs, json) {
  153. if (outs && (outs.length) && json && json.data) {
  154. $.each(Object.keys(json.data), function(i, k) {
  155. $('#out_' + k + '_out', '#outs').html(json.data[k]);
  156. });
  157. }
  158. }
  159. Describe.createSampleMootools = function(m) {
  160. debugger;
  161. var address = window.location.href;
  162. address = address.substring(0,address.indexOf("/jest/"));
  163. var address = address +"/"+ m.path;
  164. if (m.pathParameters && m.pathParameters.length > 0) {
  165. $.each(m.pathParameters, function(pi, p) {
  166. address = address.replace('{' + p.name + '}', '替换参数'+pi);
  167. });
  168. }
  169. if (m.queryParameters && m.queryParameters.length > 0) {
  170. $.each(m.queryParameters, function(pi, p) {
  171. var query = p.name + '=' + '替换参数'+pi;
  172. if (address.indexOf("?") > 0) {
  173. address += '&' + query;
  174. } else {
  175. address += '?' + query;
  176. }
  177. });
  178. }
  179. var strSample="";
  180. if (m.contentType.indexOf('application/json') > -1) {
  181. strSample = "var data = {};" + "\n";
  182. if (m.ins && m.ins.length > 0) {
  183. $.each(m.ins, function(ii, i) {
  184. switch (i.type) {
  185. default:
  186. if (i.isBaseType) {
  187. if (i.isCollection) {
  188. strSample += ' data["'+i.name+'"] = ["参数1"];' + "\n";
  189. } else {
  190. strSample += ' data["'+i.name+'"] = "参数";' + "\n";
  191. }
  192. } else {
  193. if(i.isCollection){
  194. if(i.fieldValue){
  195. if(i.fieldType =='enum'){
  196. strSample += ' data["'+i.name+'"] = ["'+ i.fieldValue +'"];'+"\n";
  197. }else{
  198. strSample += ' data["'+i.name+'"] = ['+ i.fieldValue +'];'+"\n";
  199. }
  200. }else{
  201. strSample += ' data["'+i.name+'"] = [{"参数1":"value1","参数2":"value2"}];'+"\n";
  202. }
  203. }else{
  204. if(i.fieldType =='enum'){
  205. strSample += ' data["'+i.name+'"] = "'+ i.fieldValue +'";'+"\n";
  206. }else{
  207. strSample += ' data["'+i.name+'"] = {"参数1":"value1","参数2":"value2"};'+"\n";
  208. }
  209. }
  210. }
  211. }
  212. });
  213. } else if (m.useJsonElementParameter) {
  214. strSample += 'data = {"参数1":"value1","参数2":"value2"};' +"\n";
  215. } else if (m.useStringParameter) {
  216. strSample += 'data = "参数";'+"\n";
  217. }
  218. strSample += " \n var mootoolsRequest = new Request({" + "\n";
  219. strSample += " url:'"+address + "',\n";
  220. strSample += " method:'"+ m.type + "',\n";
  221. strSample += " dataType:'json',\n";
  222. strSample += " headers : {'Content-Type':'application/json;charset=utf8','x-token':'实际的x-token'}" + ",\n";
  223. if((m.contentType.indexOf('application/json') > -1) && (!m.useStringParameter)){
  224. strSample += " data:JSON.stringify(data),\n";
  225. }else{
  226. strSample += " data:data,\n";
  227. }
  228. strSample += " onRequest: function(){ },"+ "\n";
  229. strSample += " onSuccess: function(responseText){},"+ "\n";
  230. strSample += " onFailure: function(){}"+ "\n";
  231. strSample +="}).send();"+ "\n";
  232. } else {
  233. /*
  234. strSample = "var formData = new FormData();" + "\n";
  235. if (m.formParameters && m.formParameters.length > 0) {
  236. $.each(m.formParameters, function(pi, p) {
  237. if (p.type == "File") {
  238. //formData.append(p.name, $('input[type=file]', '#formParameters')[0].files[0]);
  239. strSample += 'formData.append("'+p.name+'", $("input[type=file]")[0].files[0]);' + "\n";
  240. } else {
  241. strSample += 'formData.append("'+p.name+'", "参数'+pi+'");' + "\n";
  242. }
  243. });
  244. }
  245. strSample += "$.ajax({" + "\n";
  246. strSample += "type : '"+ m.type + "',\n";
  247. strSample += "url : '"+address + "',\n";
  248. strSample += "headers : {'x-debugger' : true}" + ",\n";
  249. strSample += "contentType : false,\n";
  250. strSample += "processData : false,\n";
  251. strSample += "xhrFields : {'withCredentials' : true}" + ",\n";
  252. strSample += "crossDomain : true"+ ",\n";
  253. strSample += "data : formData"+"\n";
  254. strSample += "});";
  255. */
  256. }
  257. return strSample;
  258. }
  259. Describe.createSampleJSO2= function(m) {
  260. var address = window.location.href;
  261. address = address.substring(0,address.indexOf("/jest/"));
  262. var uri = address.substring(address.lastIndexOf("/")+1,address.length);
  263. address = m.path;
  264. address = address.substring(address.indexOf("jaxrs/")+6,address.length);
  265. var parameter = "";
  266. if (m.pathParameters && m.pathParameters.length > 0) {
  267. $.each(m.pathParameters, function(pi, p) {
  268. address = address.replace('{' + p.name + '}', '替换参数'+pi);
  269. if(parameter == ""){
  270. parameter = "\"" + p.name + "\"" + ":" + '"替换参数'+pi +'"';
  271. }else{
  272. parameter = parameter + ",\"" + p.name + "\"" + ":" + '替换参数'+pi +'"';
  273. }
  274. });
  275. }
  276. if (m.queryParameters && m.queryParameters.length > 0) {
  277. $.each(m.queryParameters, function(pi, p) {
  278. var query = p.name + '=' + '替换参数'+pi;
  279. if (address.indexOf("?") > 0) {
  280. address += '&' + query;
  281. } else {
  282. address += '?' + query;
  283. }
  284. });
  285. }
  286. var strSample="";
  287. if (m.contentType.indexOf('application/json') > -1) {
  288. strSample = "var data = {};" + "\n";
  289. if (m.ins && m.ins.length > 0) {
  290. $.each(m.ins, function(ii, i) {
  291. switch (i.type) {
  292. default:
  293. if (i.isBaseType) {
  294. if (i.isCollection) {
  295. strSample += ' data["'+i.name+'"] = ["参数1"];' + "\n";
  296. } else {
  297. strSample += ' data["'+i.name+'"] = "参数";' + "\n";
  298. }
  299. } else {
  300. if(i.isCollection){
  301. if(i.fieldValue){
  302. if(i.fieldType =='enum'){
  303. strSample += ' data["'+i.name+'"] = ["'+ i.fieldValue +'"];'+"\n";
  304. }else{
  305. strSample += ' data["'+i.name+'"] = ['+ i.fieldValue +'];'+"\n";
  306. }
  307. }else{
  308. strSample += ' data["'+i.name+'"] = [{"参数1":"value1","参数2":"value2"}];'+"\n";
  309. }
  310. }else{
  311. if(i.fieldType =='enum'){
  312. strSample += ' data["'+i.name+'"] = "'+ i.fieldValue + '";' + "\n";
  313. }else{
  314. strSample += ' data["'+i.name+'"] = {"参数1":"value1","参数2":"value2"};'+"\n";
  315. }
  316. }
  317. }
  318. }
  319. });
  320. } else if (m.useJsonElementParameter) {
  321. strSample += 'data = {"参数1":"value1","参数2":"value2"};' +"\n";
  322. } else if (m.useStringParameter) {
  323. strSample += 'data = "参数";'+"\n";
  324. }
  325. var functionName = "do";
  326. strSample += "\n var root = \"" + uri + "\";" + "\n";
  327. strSample += " var options = { " + "\n";
  328. strSample += " " + functionName + ":{ //服务命名1,自定义"+ "\n";
  329. strSample += " \"uri\": \"/" + m.path + "\","+ "\n";;
  330. strSample += " \"method\": \""+m.type+"\""+ "\n";
  331. strSample += " }"+ "\n";
  332. strSample += " }" + "\n";
  333. strSample += "var action = new this.Action( root, options);" + "\n\n";
  334. strSample += "action.invoke({" + "\n";
  335. strSample += " \"name\": \"" + functionName+ "\", //自定义的服务名" + "\n";
  336. strSample += " \"parameter\": {" + parameter+ "}, //uri参数 " + "\n";
  337. strSample += " \"data\": data, //请求的正文, JsonObject " + "\n";
  338. strSample += " \"success\": function(json){ //服务调用成功时的回调方法,json 是服务返回的数据" + "\n";
  339. strSample += " //这里进行具体的处理"+ "\n";
  340. strSample += " }.bind(this),"+ "\n";
  341. strSample += " \"failure\" : function(xhr){ //服务调用失败时的回调方法,xhr 为 XMLHttpRequest 对象" + "\n";
  342. strSample += " //这里进行具体的处理"+ "\n";
  343. strSample += " },"+ "\n";
  344. strSample += " \"async\" : true, //同步还是异步,默认为true" + "\n";
  345. strSample += " \"withCredentials\" : true, //是否允许跨域请求,默认为true" + "\n";
  346. strSample += " \"urlEncode\" : true //uri参数是否需要通过encodeURIComponent函数编码,默认为true" + "\n";
  347. strSample += "});"
  348. } else {
  349. }
  350. return strSample;
  351. }
  352. Describe.createSampleO2= function(m) {
  353. var address = window.location.href;
  354. address = address.substring(0,address.indexOf("/jest/"));
  355. var uri = address.substring(address.lastIndexOf("/")+1,address.length);
  356. address = m.path;
  357. address = address.substring(address.indexOf("jaxrs/")+6,address.length);
  358. if (m.pathParameters && m.pathParameters.length > 0) {
  359. $.each(m.pathParameters, function(pi, p) {
  360. address = address.replace('{' + p.name + '}', '替换参数'+pi);
  361. });
  362. }
  363. if (m.queryParameters && m.queryParameters.length > 0) {
  364. $.each(m.queryParameters, function(pi, p) {
  365. var query = p.name + '=' + '替换参数'+pi;
  366. if (address.indexOf("?") > 0) {
  367. address += '&' + query;
  368. } else {
  369. address += '?' + query;
  370. }
  371. });
  372. }
  373. var strSample="";
  374. if (m.contentType.indexOf('application/json') > -1) {
  375. strSample = "var data = {};" + "\n";
  376. if (m.ins && m.ins.length > 0) {
  377. $.each(m.ins, function(ii, i) {
  378. switch (i.type) {
  379. default:
  380. if (i.isBaseType) {
  381. if (i.isCollection) {
  382. strSample += ' data["'+i.name+'"] = ["参数1"];' + "\n";
  383. } else {
  384. strSample += ' data["'+i.name+'"] = "参数";' + "\n";
  385. }
  386. } else {
  387. if(i.isCollection){
  388. if(i.fieldValue){
  389. if(i.fieldType =='enum'){
  390. strSample += ' data["'+i.name+'"] = ["'+ i.fieldValue +'"];'+"\n";
  391. }else{
  392. strSample += ' data["'+i.name+'"] = ['+ i.fieldValue +'];'+"\n";
  393. }
  394. }else{
  395. strSample += ' data["'+i.name+'"] = [{"参数1":"value1","参数2":"value2"}];'+"\n";
  396. }
  397. }else{
  398. if(i.fieldType =='enum'){
  399. strSample += ' data["'+i.name+'"] = "'+i.fieldValue+'"\n';
  400. }else{
  401. strSample += ' data["'+i.name+'"] = {"参数1":"value1","参数2":"value2"};'+"\n";
  402. }
  403. }
  404. }
  405. }
  406. });
  407. } else if (m.useJsonElementParameter) {
  408. strSample += 'data = {"参数1":"value1","参数2":"value2"};' +"\n";
  409. } else if (m.useStringParameter) {
  410. strSample += 'data = "参数";'+"\n";
  411. }
  412. if(m.type=="POST"){
  413. strSample += " \n var string = JSON.stringify(data);" + "\n";
  414. strSample += " var applications = this.Action.applications;"+ "\n";
  415. strSample += " var serviceRoot = \"" + uri + "\";"+ "\n";
  416. strSample += " var path = \"" + address + "\";"+ "\n"; ;
  417. strSample += " var resp = applications.postQuery( serviceRoot, path , string);"+ "\n";
  418. }
  419. if(m.type=="GET"){
  420. strSample += " \n var applications = this.Action.applications;"+ "\n";
  421. strSample += " var serviceRoot = \"" + uri + "\";"+ "\n";
  422. strSample += " var path = \"" + address + "\";"+ "\n"; ;
  423. strSample += " var resp = applications.getQuery( serviceRoot, path );"+ "\n";
  424. }
  425. if(m.type=="PUT"){
  426. strSample += " \n var string = JSON.stringify(data)"+ "\n";
  427. strSample += " var applications = this.Action.applications"+ "\n";
  428. strSample += " var serviceRoot = \"" + uri + "\";"+ "\n";
  429. strSample += " var path = \"" + address+ "\";"+ "\n"; ;
  430. strSample += " var resp = applications.putQuery( serviceRoot, path , string);"+ "\n";
  431. }
  432. if(m.type=="DELETE"){
  433. strSample += " \n var applications = this.Action.applications;"+ "\n";
  434. strSample += " var serviceRoot = \" "+ uri + "\";"+ "\n";
  435. strSample += " var path = \"" + address + "\";"+ "\n"; ;
  436. strSample += " var resp = applications.deleteQuery( serviceRoot, path);"+ "\n";
  437. }
  438. strSample += " var json = JSON.parse( resp.toString() );"+ "\n";
  439. } else {
  440. }
  441. return strSample;
  442. }
  443. Describe.createSample= function(m) {
  444. var address = window.location.href;
  445. address = address.substring(0,address.indexOf("/jest/"));
  446. var address = address +"/"+ m.path;
  447. if (m.pathParameters && m.pathParameters.length > 0) {
  448. $.each(m.pathParameters, function(pi, p) {
  449. address = address.replace('{' + p.name + '}', '替换参数'+pi);
  450. });
  451. }
  452. if (m.queryParameters && m.queryParameters.length > 0) {
  453. $.each(m.queryParameters, function(pi, p) {
  454. var query = p.name + '=' + '替换参数'+pi;
  455. if (address.indexOf("?") > 0) {
  456. address += '&' + query;
  457. } else {
  458. address += '?' + query;
  459. }
  460. });
  461. }
  462. var strSample="";
  463. if (m.contentType.indexOf('application/json') > -1) {
  464. if (m.ins && m.ins.length > 0) {
  465. strSample = "var data = {};" + "\n";
  466. $.each(m.ins, function(ii, i) {
  467. switch (i.type) {
  468. default:
  469. if (i.isBaseType) {
  470. if (i.isCollection) {
  471. strSample += ' data["'+i.name+'"] = ["参数1"];' + "\n";
  472. } else {
  473. strSample += ' data["'+i.name+'"] = "参数";' + "\n";
  474. }
  475. } else {
  476. if(i.isCollection){
  477. if(i.fieldValue){
  478. if(i.fieldType =='enum'){
  479. strSample += ' data["'+i.name+'"] = ["'+ i.fieldValue +'"];'+"\n";
  480. }else{
  481. strSample += ' data["'+i.name+'"] = ['+ i.fieldValue +'];'+"\n";
  482. }
  483. }else{
  484. strSample += ' data["'+i.name+'"] = [{"参数1":"value1","参数2":"value2"}];'+"\n";
  485. }
  486. }else{
  487. if(i.fieldType =='enum'){
  488. strSample += ' data["'+i.name+'"] = "'+i.fieldValue+'"\n';
  489. }else{
  490. strSample += ' data["'+i.name+'"] = {"参数1":"value1","参数2":"value2"};'+"\n";
  491. }
  492. }
  493. }
  494. }
  495. });
  496. } else if (m.useJsonElementParameter) {
  497. strSample += ' data = {"参数1":"value1","参数2":"value2"};' +"\n";
  498. } else if (m.useStringParameter) {
  499. strSample += ' data = "参数";'+"\n";
  500. }
  501. strSample += "\n$.ajax({" + "\n";
  502. strSample += " type : '"+ m.type + "',\n";
  503. strSample += " dataType : 'json'" + ",\n";
  504. strSample += " url : '"+address + "',\n";
  505. strSample += " headers : {'x-debugger' : true}" + ",\n";
  506. strSample += " contentType : '"+m.contentType+ "',\n";
  507. strSample += " xhrFields : {'withCredentials' : true}" + ",\n";
  508. strSample += " crossDomain : true"+ ",\n";
  509. if((m.contentType.indexOf('application/json') > -1) && (!m.useStringParameter)){
  510. strSample += " data : JSON.stringify(data),\n";
  511. }else{
  512. strSample += " data : data"+"\n";
  513. }
  514. strSample += "}).always(function(resultJson) {"+"\n";
  515. strSample += " alert(JSON.stringify(resultJson, null, 4))" +"\n";
  516. strSample += "});";
  517. } else {
  518. strSample = "var formData = new FormData();" + "\n";
  519. if (m.formParameters && m.formParameters.length > 0) {
  520. $.each(m.formParameters, function(pi, p) {
  521. if (p.type == "File") {
  522. //formData.append(p.name, $('input[type=file]', '#formParameters')[0].files[0]);
  523. strSample += 'formData.append("'+p.name+'", $("input[type=file]")[0].files[0]);' + "\n";
  524. } else {
  525. strSample += 'formData.append("'+p.name+'", "参数'+pi+'");' + "\n";
  526. }
  527. });
  528. }
  529. strSample += "$.ajax({" + "\n";
  530. strSample += " type : '"+ m.type + "',\n";
  531. strSample += " url : '"+address + "',\n";
  532. strSample += " headers : {'x-debugger' : true}" + ",\n";
  533. //strSample += " contentType : false,\n";
  534. strSample += " contentType : '"+m.contentType+ "',\n";
  535. strSample += " processData : false,\n";
  536. strSample += " xhrFields : {'withCredentials' : true}" + ",\n";
  537. strSample += " crossDomain : true"+ ",\n";
  538. strSample += " data : formData"+"\n";
  539. strSample += "});";
  540. }
  541. return strSample;
  542. }
  543. Describe.createSampleCommon= function(m,className) {
  544. debugger;
  545. var address = window.location.href;
  546. address = address.substring(0,address.indexOf("/jest/"));
  547. var root = address.substring(address.lastIndexOf("/")+1,address.length);
  548. var parameter = "";
  549. if (m.pathParameters && m.pathParameters.length > 0) {
  550. $.each(m.pathParameters, function(pi, p) {
  551. if(parameter == ""){
  552. parameter = p.name ;
  553. }else{
  554. parameter = parameter + "," + p.name;
  555. }
  556. });
  557. }
  558. var query = "";
  559. if (m.queryParameters && m.queryParameters.length > 0) {
  560. $.each(m.queryParameters, function(pi, p) {
  561. if (query == "") {
  562. query = "&" + p.name + '=' + '替换参数'+pi;
  563. } else {
  564. query = query + "&"+ p.name + '=' + '替换参数'+pi;
  565. }
  566. });
  567. }
  568. var strSample="";
  569. var body = "";
  570. if (m.contentType.indexOf('application/json') > -1) {
  571. if (m.ins && m.ins.length > 0) {
  572. body = "var data = {};" + "\n";
  573. $.each(m.ins, function(ii, i) {
  574. switch (i.type) {
  575. default:
  576. if (i.isBaseType) {
  577. if (i.isCollection) {
  578. body += ' data["'+i.name+'"] = ["参数1"];' + "\n";
  579. } else {
  580. body += ' data["'+i.name+'"] = "参数";' + "\n";
  581. }
  582. } else {
  583. if(i.isCollection){
  584. if(i.fieldValue){
  585. if(i.fieldType =='enum'){
  586. body += ' data["'+i.name+'"] = ["'+ i.fieldValue +'"];'+"\n";
  587. body +=(i.fieldSample ? " "+'<span style="color:red">//注解:'+i.fieldSample +'</span>\n':"");
  588. }else{
  589. body += ' data["'+i.name+'"] = ['+ i.fieldValue +'];'+"\n";
  590. body +=(i.fieldSample ? " "+'<span style="color:red">//注解:'+i.fieldSample +'</span>\n':"");
  591. }
  592. }else{
  593. body += ' data["'+i.name+'"] = [{"参数1":"value1","参数2":"value2"}];'+"\n";
  594. }
  595. }else{
  596. if(i.fieldType =='enum'){
  597. body += ' data["'+i.name+'"] = "'+ i.fieldValue +'";'+"\n";
  598. body +=(i.fieldSample ? " "+'<span style="color:red">//注解:'+i.fieldSample +'</span>\n':"");
  599. }else{
  600. body += ' data["'+i.name+'"] = {"参数1":"value1","参数2":"value2"};'+"\n";
  601. }
  602. }
  603. }
  604. }
  605. });
  606. } else if (m.useJsonElementParameter) {
  607. body += ' data = {"参数1":"value1","参数2":"value2"};' +"\n";
  608. } else if (m.useStringParameter) {
  609. body += ' data = "参数";'+"\n";
  610. }
  611. if(m.type != "GET" ){
  612. if( body != ""){
  613. strSample += body;
  614. }
  615. }
  616. strSample += "var action = this.Actions.load(\"" + root + "\");\n";
  617. strSample += " action."+ className + "."+m.name+ "(//平台封装好的方法\n";
  618. if(parameter!=""){
  619. strSample += " " + parameter +",//uri的参数\n";
  620. }
  621. if(m.type != "GET" ){
  622. if( body != ""){
  623. strSample += " data,//body请求参数\n";
  624. }
  625. }
  626. strSample += " function( json ){ //服务调用成功的回调函数, json为服务传回的数据\n";
  627. strSample += " data = json.data; //为变量data赋值\n";
  628. strSample += " }.bind(this),\n";
  629. strSample += " function( json ){ //服务调用失败的回调函数, json为服务传回的数据\n";
  630. strSample += " data = json.data; //为变量data赋值\n";
  631. strSample += " }.bind(this),\n";
  632. strSample += " false //同步执行 \n";
  633. strSample += " );\n";
  634. }else{
  635. var formData = "var formData = new FormData();" + "\n";
  636. if (m.formParameters && m.formParameters.length > 0) {
  637. $.each(m.formParameters, function(pi, p) {
  638. if (p.type == "File") {
  639. formData += ' formData.append("'+p.name+'", $("input[type=file]")[0].files[0]);' + "\n";
  640. } else {
  641. formData += ' formData.append("'+p.name+'", "参数值'+pi+'");' + "\n";
  642. }
  643. });
  644. }
  645. strSample += formData;
  646. strSample += "var action = this.Actions.load(\"" + root + "\");\n";
  647. //strSample += "action."+m.name+ "(//平台封装好的方法\n";
  648. strSample += " action."+ className + "."+m.name+ "(//平台封装好的方法\n";
  649. strSample += " "+parameter +",//uri的参数\n";
  650. strSample += " formData"+",//from参数\n";
  651. strSample += "function( json ){ //服务调用成功的回调函数, json为服务传回的数据\n";
  652. strSample += " data = json.data; //为变量data赋值\n";
  653. strSample += "}.bind(this),\n";
  654. strSample += "function( json ){ //服务调用失败的回调函数, json为服务传回的数据\n";
  655. strSample += " data = json.data; //为变量data赋值\n";
  656. strSample += "}.bind(this),\n";
  657. strSample += "false //同步执行 \n";
  658. strSample += ");\n"
  659. }
  660. return strSample ;
  661. }
  662. Describe.prototype = {
  663. "load" : function() {
  664. var str = '<ul>';
  665. $.getJSON('../describe/describe.json?rd=' + Math.random(), function(json) {
  666. Describe.json = json;
  667. $.each(json.jaxrs, function(ji, j) {
  668. str += '<li xtype="menu" ' + 'style="margin-top: 30px;font-size:14px;font-weight:bold;"title="' +'" >' + j.name + ' <span style="font-style:italic">(' + j.description+ ')</span>';
  669. $.each(j.methods, function(mi, m) {
  670. str += '<ul><li xtype="li" style="margin-top: 10px;margin-left:-24px;font-size:12px; font-weight:normal;line-height:18px" ><a title="' + m.path + '"id ="' + j.name + '_' + m.name + '" href="#"><b>' + m.name+'</b><br/><span style="color: #666666;">-'+ m.description + '</span>' + '</a></li></ul>';
  671. });
  672. str += '</li>'
  673. });
  674. str += '</ul>';
  675. $("#menu").html(str);
  676. $.each(json.jaxrs, function(ji, j) {
  677. $.each(j.methods, function(mi, m) {
  678. $('#' + j.name + '_' + m.name).click(
  679. function() {
  680. $('#result').html('');
  681. var sample = "";
  682. var txt = '<fieldset id="method"><legend>Method</legend>';
  683. txt += '<table>';
  684. txt += '<tr><td style="width:100px;">name:</td><td><a href="../describe/sources/' + m.className.replace(/\./g, '/') + '.java">' + m.name + '</a></td></tr>';
  685. txt += '<tr><td>path:</td><td>' + m.path + '</td></tr>';
  686. txt += '<tr><td>type:</td><td>' + m.type + '</td></tr>';
  687. txt += '<tr><td>description:</td><td>' + m.description + '</td></tr>';
  688. txt += '</table>';
  689. txt += '<button id="' + m.name + "_" + m.type + '">' + m.type + '</button>';
  690. txt += '<div id="url">&nbsp;</div>';
  691. txt += '</fieldset>';
  692. if (m.pathParameters && m.pathParameters.length > 0) {
  693. txt += '<fieldset id="pathParameters"><legend>Path Parameter</legend>';
  694. txt += '<table >';
  695. $.each(m.pathParameters, function(pi, p) {
  696. if (m.name == 'listNext' || m.name == 'listPrev') {
  697. switch (p.name) {
  698. case 'flag':
  699. case 'id':
  700. txt += '<tr><td><input type="text" id="' + p.name + '" style="width:600px; padding:1px; border:1px #000000 solid" value="(0)"/></td><td>' + p.name
  701. + ':' + p.description + '</td></tr>';
  702. break;
  703. case 'count':
  704. txt += '<tr><td><input type="text" id="' + p.name + '" style="width:600px; padding:1px; border:1px #000000 solid" value="20"/></td><td>' + p.name + ':'
  705. + p.description + '</td></tr>';
  706. break;
  707. default:
  708. txt += '<tr><td><input type="text" id="' + p.name + '" style="width:600px; padding:1px; border:1px #000000 solid"/></td><td>' + p.name + ':'
  709. + p.description + '</td></tr>';
  710. break
  711. }
  712. } else {
  713. txt += '<tr><td><input type="text" id="' + p.name + '" style="width:600px; padding:1px; border:1px #000000 solid"/></td><td>' + p.name + ':'
  714. + p.description + '</td></tr>';
  715. }
  716. });
  717. txt += '</table>';
  718. txt += '</fieldset>';
  719. }
  720. if (m.formParameters && m.formParameters.length > 0) {
  721. txt += '<fieldset id="formParameters"><legend>Form Parameter</legend>';
  722. txt += '<table >';
  723. $.each(m.formParameters, function(pi, p) {
  724. if (p.type == "File") {
  725. txt += '<tr><td><input type="file" name="' + p.name + '" id="' + p.name + '" style="width:600px; padding:1px; border:1px #000000 solid"/></td><td>'
  726. + p.name + ':' + p.description + '</td></tr>';
  727. } else {
  728. txt += '<tr><td><input type="text" id="' + p.name + '" style="width:600px; padding:1px; border:1px #000000 solid"/></td><td>' + p.name + ':'
  729. + p.description + '</td></tr>';
  730. }
  731. });
  732. txt += '</table>';
  733. txt += '</fieldset>';
  734. }
  735. if (m.queryParameters && m.queryParameters.length > 0) {
  736. txt += '<fieldset id="queryParameters"><legend>Query Parameter</legend>';
  737. txt += '<table >';
  738. $.each(m.queryParameters, function(pi, p) {
  739. txt += '<tr><td><input type="text" id="' + p.name + '" style="width:600px; padding:1px; border:1px #000000 solid"/></td><td>' + p.name + ':' + p.description
  740. + '</td></tr>';
  741. });
  742. txt += '</table>';
  743. txt += '</fieldset>';
  744. }
  745. if (m.ins && m.ins.length > 0) {
  746. txt += '<fieldset id="ins"><legend>In</legend>';
  747. txt += '<table>';
  748. $.each(m.ins, function(ii, i) {
  749. if (i.isCollection) {
  750. txt += '<tr><td><textarea id="' + i.name + '" style="width:600px; padding:1px; border:1px #000000 solid"/></td><td>' + i.name + ':' + i.description +(i.fieldValue ? " "+'。数据格式:<span style="color:red">'+i.fieldValue +'</span>':"") + (i.fieldSample ? " "+'<span style="color:red">'+i.fieldSample +'</span>':"")
  751. +'</td></tr>';
  752. } else {
  753. txt += '<tr><td><input type="text" id="' + i.name + '" style="width:600px; padding:1px; border:1px #000000 solid"/></td><td>' + i.name + ':'
  754. + i.description+ (i.fieldValue ? " "+'。数据格式:<span style="color:red">'+i.fieldValue +'</span>':"") + (i.fieldSample ? " "+'<span style="color:red">'+i.fieldSample +'</span>':"")
  755. +'</td></tr>';
  756. }
  757. });
  758. txt += '</table>';
  759. txt += '</fieldset>';
  760. }
  761. if (m.useJsonElementParameter) {
  762. txt += '<fieldset><legend>JsonElement</legend>';
  763. txt += '<table><tr><td>';
  764. txt += '<textarea id="jsonElement" style="height:300px; width:600px; padding:1px; border:1px #000000 solid"/>';
  765. txt += '</td><td>json</td></tr>';
  766. txt += '</table>';
  767. txt += '</fieldset>';
  768. }
  769. if (m.useStringParameter) {
  770. txt += '<fieldset><legend>String</legend>';
  771. txt += '<table><tr><td>';
  772. txt += '<textarea id="string" style="height:300px; width:600px; padding:1px; border:1px #000000 solid"/>';
  773. txt += '</td><td>string</td></tr>';
  774. txt += '</table>';
  775. txt += '</fieldset>';
  776. }
  777. if (m.outs && m.outs.length > 0) {
  778. txt += '<fieldset id="outs"><legend>Out</legend>';
  779. txt += '<table>';
  780. $.each(m.outs, function(oi, o) {
  781. txt += '<tr><td style="width: 160px;">' + o.name + '</td><td style="width: 90px;">' + o.type + '</td><td style="width: 90px;">' + (o.isCollection ? 'multi' : 'single') + '</td><td style="width: 90px;">' + o.description + '</td><td id="out_'
  782. + o.name + '_out">&nbsp;</td></tr>';
  783. });
  784. txt += '</table>';
  785. txt += '</fieldset>';
  786. }
  787. $('#content').html(txt);
  788. $('#' + m.name + '_' + m.type, '#method').click(function() {
  789. var address = '../' + m.path;
  790. if (m.pathParameters && m.pathParameters.length > 0) {
  791. $.each(m.pathParameters, function(pi, p) {
  792. address = address.replace('{' + p.name + '}', encodeURIComponent($('#' + p.name, '#pathParameters').val()));
  793. });
  794. }
  795. if (m.queryParameters && m.queryParameters.length > 0) {
  796. $.each(m.queryParameters, function(pi, p) {
  797. var query = p.name + '=' + encodeURIComponent($('#' + p.name, '#queryParameters').val());
  798. if (address.indexOf("?") > 0) {
  799. address += '&' + query;
  800. } else {
  801. address += '?' + query;
  802. }
  803. });
  804. }
  805. if (m.contentType.indexOf('application/json') > -1) {
  806. switch (m.type) {
  807. case 'POST':
  808. var data = {};
  809. if (m.ins && m.ins.length > 0) {
  810. $.each(m.ins, function(ii, i) {
  811. switch (i.type) {
  812. default:
  813. if (i.isBaseType) {
  814. if (i.isCollection) {
  815. data[i.name] = Describe.splitValue($('#' + i.name, '#ins').val());
  816. } else {
  817. data[i.name] = $('#' + i.name, '#ins').val();
  818. }
  819. } else {
  820. //data[i.name] = $.parseJSON($('#' + i.name, '#ins').val());
  821. if($('#' + i.name, '#ins').val() == ""){
  822. /*
  823. if(i.isCollection){
  824. data[i.name] = [{}];
  825. }else{
  826. data[i.name] = {};
  827. }*/
  828. }else{
  829. data[i.name] = $.parseJSON($('#' + i.name, '#ins').val());
  830. }
  831. }
  832. }
  833. });
  834. } else if (m.useJsonElementParameter) {
  835. data = $.parseJSON($('#jsonElement').val());
  836. } else if (m.useStringParameter) {
  837. data = $('#string').val();
  838. }
  839. Describe.doPost(address, m, data);
  840. break;
  841. case 'PUT':
  842. var data = {};
  843. if (m.ins && m.ins.length > 0) {
  844. $.each(m.ins, function(ii, i) {
  845. switch (i.type) {
  846. default:
  847. if (i.isBaseType) {
  848. if (i.isCollection) {
  849. data[i.name] = Describe.splitValue($('#' + i.name, '#ins').val());
  850. } else {
  851. data[i.name] = $('#' + i.name, '#ins').val();
  852. }
  853. } else {
  854. if($('#' + i.name, '#ins').val() == ""){
  855. /*
  856. if(i.isCollection){
  857. data[i.name] = [{}];
  858. }else{
  859. data[i.name] = {};
  860. }*/
  861. }else{
  862. data[i.name] = $.parseJSON($('#' + i.name, '#ins').val());
  863. }
  864. }
  865. }
  866. });
  867. } else if (m.useJsonElementParameter) {
  868. data = $.parseJSON($('#jsonElement').val());
  869. } else if (m.useStringParameter) {
  870. data = $('#string').val();
  871. }
  872. Describe.doPut(address, m, data);
  873. break;
  874. case 'GET':
  875. Describe.doGet(address, m);
  876. break;
  877. case 'DELETE':
  878. Describe.doDelete(address, m);
  879. break;
  880. default:
  881. break;
  882. }
  883. } else {
  884. switch (m.type) {
  885. case 'POST':
  886. var formData = new FormData();
  887. if (m.formParameters && m.formParameters.length > 0) {
  888. $.each(m.formParameters, function(pi, p) {
  889. if (p.type == "File") {
  890. formData.append(p.name, $('input[type=file]', '#formParameters')[0].files[0]);
  891. } else {
  892. formData.append(p.name, $('#' + p.name, '#formParameters').val());
  893. }
  894. });
  895. }
  896. Describe.doPost(address, m, formData);
  897. break;
  898. case 'PUT':
  899. var formData = new FormData();
  900. if (m.formParameters && m.formParameters.length > 0) {
  901. $.each(m.formParameters, function(pi, p) {
  902. if (p.type == "File") {
  903. formData.append(p.name, $('input[type=file]', '#formParameters')[0].files[0]);
  904. } else {
  905. formData.append(p.name, $('#' + p.name, '#formParameters').val());
  906. }
  907. });
  908. }
  909. Describe.doPut(address, m, formData);
  910. break;
  911. case 'GET':
  912. Describe.doGet(address, m);
  913. break;
  914. case 'DELETE':
  915. Describe.doDelete(address, m);
  916. break;
  917. default:
  918. break;
  919. }
  920. }
  921. })
  922. debugger;
  923. $('#Sample').html("<div style=\"border-bottom:1px solid #E6E6E6;padding-bottom: 40px;line-height:21px\"><span style=\"font-size:17px;font-weight:bold;color: #1E7ACE;\">\n平台推荐脚本样例</span>\n\n"+ Describe.createSampleCommon(m,j.name)+ "</div><div style=\"border-bottom:1px solid #E6E6E6;padding-bottom: 40px;line-height:21px\"><span style=\"font-size:17px;font-weight:bold;\">\n\n后台脚本样例</span>\n\n" + Describe.createSampleO2(m) + "</div><div style=\"line-height:21px\"><span style=\"font-size:17px;font-weight:bold;\">\n\njquery样例</span>\n\n<span style=\"\">"+ Describe.createSample(m)+"</span></div>");
  924. });
  925. });
  926. });
  927. $("[xtype='menu']").click(
  928. function(event) {
  929. if(event.stopPropagation){
  930. event.stopPropagation();
  931. }else{
  932. event.cancelBubble = true;
  933. }
  934. $(this).children().each(function(i){
  935. debugger;
  936. if(this.tagName != "SPAN"){
  937. $(this).toggle();
  938. }
  939. });
  940. //$(this).children().toggle();
  941. });
  942. $("[xtype='li']").click( function(event) {
  943. if(event.stopPropagation){
  944. event.stopPropagation();
  945. }else{
  946. event.cancelBubble = true;
  947. }
  948. })
  949. $("[xtype='menu']").each(function(i){
  950. if(i!=0){
  951. // $(this).children().toggle();
  952. $(this).children().each(function(i){
  953. if(this.tagName != "SPAN"){
  954. $(this).toggle();
  955. }
  956. });
  957. }
  958. }
  959. );
  960. });
  961. },
  962. "search":function(strKey) {
  963. var str = '<ul>';
  964. var strTemp = "";
  965. $.each(Describe.json.jaxrs, function(ji, j) {
  966. var flag = false;
  967. strTemp = '<li xtype="menu" ' + 'style="margin-top: 30px;font-size:14px;font-weight:bold;"title="' +'" >' + j.name + ' <span style="font-style:italic">(' + j.description+ ')</span>';
  968. $.each(j.methods, function(mi, m) {
  969. if((m.name.toUpperCase().indexOf(strKey.toUpperCase())>-1) || (m.description.toUpperCase().indexOf(strKey.toUpperCase())>-1) || (m.path.toUpperCase().indexOf(strKey.toUpperCase())>-1)){
  970. flag = true;
  971. var tempKey = strKey;
  972. var tempReplace = "<span style='color: #f31313'>"+ strKey + "</span>";
  973. debugger;
  974. var strDescripthion = m.description.replace(tempKey, tempReplace);
  975. var strName = m.name.replace(tempKey, tempReplace);
  976. var strPath = m.path;
  977. var startPost = m.name.toUpperCase().indexOf(strKey.toUpperCase());
  978. if(startPost>-1){
  979. tempReplace = m.name.substr(startPost,tempKey.length);
  980. tempKey = tempReplace;
  981. tempReplace = "<span style='color: #f31313'>"+ tempReplace + "</span>";
  982. strName = m.name.replace(tempKey, tempReplace);
  983. }
  984. tempKey = strKey;
  985. startPost = m.description.toUpperCase().indexOf(strKey.toUpperCase());
  986. if(startPost>-1){
  987. tempReplace = m.description.substr(startPost,tempKey.length);
  988. tempKey = tempReplace;
  989. tempReplace = "<span style='color: #f31313'>"+ tempReplace + "</span>";
  990. strDescripthion = m.description.replace(tempKey, tempReplace);
  991. }
  992. strTemp += '<ul><li xtype="li" style="margin-top: 10px;margin-left:-24px;font-size:12px; font-weight:normal;line-height:18px" ><a title = "' + strPath+ '" id ="' + j.name + '_' + m.name + '" href="#"><b>' + strName+'</b><br/><span style="color: #666666;">-'+strDescripthion + '</span>' + '</a></li></ul>';
  993. }
  994. });
  995. strTemp += '</li>';
  996. if(flag == true){
  997. str += strTemp;
  998. }
  999. });
  1000. str += '</ul>';
  1001. $("#menu").html(str);
  1002. this.display(Describe.json);
  1003. },
  1004. "display":function(json) {
  1005. $.each(json.jaxrs, function(ji, j) {
  1006. $.each(j.methods, function(mi, m) {
  1007. $('#' + j.name + '_' + m.name).click(
  1008. function() {
  1009. $('#result').html('');
  1010. var sample = "";
  1011. var txt = '<fieldset id="method"><legend>Method</legend>';
  1012. txt += '<table>';
  1013. txt += '<tr><td style="width:100px;">name:</td><td><a href="../describe/sources/' + m.className.replace(/\./g, '/') + '.java">' + m.name + '</a></td></tr>';
  1014. txt += '<tr><td>path:</td><td>' + m.path + '</td></tr>';
  1015. txt += '<tr><td>type:</td><td>' + m.type + '</td></tr>';
  1016. txt += '<tr><td>description:</td><td>' + m.description + '</td></tr>';
  1017. txt += '</table>';
  1018. txt += '<button id="' + m.name + "_" + m.type + '">' + m.type + '</button>';
  1019. txt += '<div id="url">&nbsp;</div>';
  1020. txt += '</fieldset>';
  1021. if (m.pathParameters && m.pathParameters.length > 0) {
  1022. txt += '<fieldset id="pathParameters"><legend>Path Parameter</legend>';
  1023. txt += '<table >';
  1024. $.each(m.pathParameters, function(pi, p) {
  1025. if (m.name == 'listNext' || m.name == 'listPrev') {
  1026. switch (p.name) {
  1027. case 'flag':
  1028. case 'id':
  1029. txt += '<tr><td><input type="text" id="' + p.name + '" style="width:600px; padding:1px; border:1px #000000 solid" value="(0)"/></td><td>' + p.name
  1030. + ':' + p.description + '</td></tr>';
  1031. break;
  1032. case 'count':
  1033. txt += '<tr><td><input type="text" id="' + p.name + '" style="width:600px; padding:1px; border:1px #000000 solid" value="20"/></td><td>' + p.name + ':'
  1034. + p.description + '</td></tr>';
  1035. break;
  1036. default:
  1037. txt += '<tr><td><input type="text" id="' + p.name + '" style="width:600px; padding:1px; border:1px #000000 solid"/></td><td>' + p.name + ':'
  1038. + p.description + '</td></tr>';
  1039. break
  1040. }
  1041. } else {
  1042. txt += '<tr><td><input type="text" id="' + p.name + '" style="width:600px; padding:1px; border:1px #000000 solid"/></td><td>' + p.name + ':'
  1043. + p.description + '</td></tr>';
  1044. }
  1045. });
  1046. txt += '</table>';
  1047. txt += '</fieldset>';
  1048. }
  1049. if (m.formParameters && m.formParameters.length > 0) {
  1050. txt += '<fieldset id="formParameters"><legend>Form Parameter</legend>';
  1051. txt += '<table >';
  1052. $.each(m.formParameters, function(pi, p) {
  1053. if (p.type == "File") {
  1054. txt += '<tr><td><input type="file" name="' + p.name + '" id="' + p.name + '" style="width:600px; padding:1px; border:1px #000000 solid"/></td><td>'
  1055. + p.name + ':' + p.description + '</td></tr>';
  1056. } else {
  1057. txt += '<tr><td><input type="text" id="' + p.name + '" style="width:600px; padding:1px; border:1px #000000 solid"/></td><td>' + p.name + ':'
  1058. + p.description + '</td></tr>';
  1059. }
  1060. });
  1061. txt += '</table>';
  1062. txt += '</fieldset>';
  1063. }
  1064. if (m.queryParameters && m.queryParameters.length > 0) {
  1065. txt += '<fieldset id="queryParameters"><legend>Query Parameter</legend>';
  1066. txt += '<table >';
  1067. $.each(m.queryParameters, function(pi, p) {
  1068. txt += '<tr><td><input type="text" id="' + p.name + '" style="width:600px; padding:1px; border:1px #000000 solid"/></td><td>' + p.name + ':' + p.description
  1069. + '</td></tr>';
  1070. });
  1071. txt += '</table>';
  1072. txt += '</fieldset>';
  1073. }
  1074. if (m.ins && m.ins.length > 0) {
  1075. txt += '<fieldset id="ins"><legend>In</legend>';
  1076. txt += '<table>';
  1077. $.each(m.ins, function(ii, i) {
  1078. if (i.isCollection) {
  1079. txt += '<tr><td><textarea id="' + i.name + '" style="width:600px; padding:1px; border:1px #000000 solid"/></td><td>' + i.name + ':' + i.description +(i.fieldValue ? " "+'。数据格式:<span style="color:red">'+i.fieldValue +'</span>':"") + (i.fieldSample ? " "+'<span style="color:red">'+i.fieldSample +'</span>':"")
  1080. '</td></tr>';
  1081. } else {
  1082. txt += '<tr><td><input type="text" id="' + i.name + '" style="width:600px; padding:1px; border:1px #000000 solid"/></td><td>' + i.name + ':'
  1083. + i.description
  1084. '</td></tr>';
  1085. }
  1086. });
  1087. txt += '</table>';
  1088. txt += '</fieldset>';
  1089. }
  1090. if (m.useJsonElementParameter) {
  1091. txt += '<fieldset><legend>JsonElement</legend>';
  1092. txt += '<table><tr><td>';
  1093. txt += '<textarea id="jsonElement" style="height:300px; width:600px; padding:1px; border:1px #000000 solid"/>';
  1094. txt += '</td><td>json</td></tr>';
  1095. txt += '</table>';
  1096. txt += '</fieldset>';
  1097. }
  1098. if (m.useStringParameter) {
  1099. txt += '<fieldset><legend>String</legend>';
  1100. txt += '<table><tr><td>';
  1101. txt += '<textarea id="string" style="height:300px; width:600px; padding:1px; border:1px #000000 solid"/>';
  1102. txt += '</td><td>string</td></tr>';
  1103. txt += '</table>';
  1104. txt += '</fieldset>';
  1105. }
  1106. if (m.outs && m.outs.length > 0) {
  1107. txt += '<fieldset id="outs"><legend>Out</legend>';
  1108. txt += '<table>';
  1109. $.each(m.outs, function(oi, o) {
  1110. txt += '<tr><td style="width: 160px;">' + o.name + '</td><td style="width: 90px;">' + o.type + '</td><td style="width: 90px;">' + (o.isCollection ? 'multi' : 'single') + '</td><td style="width: 90px;">' + o.description + '</td><td id="out_'
  1111. + o.name + '_out">&nbsp;</td></tr>';
  1112. });
  1113. txt += '</table>';
  1114. txt += '</fieldset>';
  1115. }
  1116. $('#content').html(txt);
  1117. $('#' + m.name + '_' + m.type, '#method').click(function() {
  1118. var address = '../' + m.path;
  1119. if (m.pathParameters && m.pathParameters.length > 0) {
  1120. $.each(m.pathParameters, function(pi, p) {
  1121. address = address.replace('{' + p.name + '}', encodeURIComponent($('#' + p.name, '#pathParameters').val()));
  1122. });
  1123. }
  1124. if (m.queryParameters && m.queryParameters.length > 0) {
  1125. $.each(m.queryParameters, function(pi, p) {
  1126. var query = p.name + '=' + encodeURIComponent($('#' + p.name, '#queryParameters').val());
  1127. if (address.indexOf("?") > 0) {
  1128. address += '&' + query;
  1129. } else {
  1130. address += '?' + query;
  1131. }
  1132. });
  1133. }
  1134. if (m.contentType.indexOf('application/json') > -1) {
  1135. switch (m.type) {
  1136. case 'POST':
  1137. var data = {};
  1138. if (m.ins && m.ins.length > 0) {
  1139. $.each(m.ins, function(ii, i) {
  1140. switch (i.type) {
  1141. default:
  1142. if (i.isBaseType) {
  1143. if (i.isCollection) {
  1144. data[i.name] = Describe.splitValue($('#' + i.name, '#ins').val());
  1145. } else {
  1146. data[i.name] = $('#' + i.name, '#ins').val();
  1147. }
  1148. } else {
  1149. //data[i.name] = $.parseJSON($('#' + i.name, '#ins').val());
  1150. if($('#' + i.name, '#ins').val() == ""){
  1151. if(i.isCollection){
  1152. data[i.name] = [{}];
  1153. }else{
  1154. data[i.name] = {};
  1155. }
  1156. }else{
  1157. data[i.name] = $.parseJSON($('#' + i.name, '#ins').val());
  1158. }
  1159. }
  1160. }
  1161. });
  1162. } else if (m.useJsonElementParameter) {
  1163. data = $.parseJSON($('#jsonElement').val());
  1164. } else if (m.useStringParameter) {
  1165. data = $('#string').val();
  1166. }
  1167. Describe.doPost(address, m, data);
  1168. break;
  1169. case 'PUT':
  1170. var data = {};
  1171. if (m.ins && m.ins.length > 0) {
  1172. $.each(m.ins, function(ii, i) {
  1173. switch (i.type) {
  1174. default:
  1175. if (i.isBaseType) {
  1176. if (i.isCollection) {
  1177. data[i.name] = Describe.splitValue($('#' + i.name, '#ins').val());
  1178. } else {
  1179. data[i.name] = $('#' + i.name, '#ins').val();
  1180. }
  1181. } else {
  1182. if($('#' + i.name, '#ins').val() == ""){
  1183. if(i.isCollection){
  1184. data[i.name] = [{}];
  1185. }else{
  1186. data[i.name] = {};
  1187. }
  1188. }else{
  1189. data[i.name] = $.parseJSON($('#' + i.name, '#ins').val());
  1190. }
  1191. }
  1192. }
  1193. });
  1194. } else if (m.useJsonElementParameter) {
  1195. data = $.parseJSON($('#jsonElement').val());
  1196. } else if (m.useStringParameter) {
  1197. data = $('#string').val();
  1198. }
  1199. Describe.doPut(address, m, data);
  1200. break;
  1201. case 'GET':
  1202. Describe.doGet(address, m);
  1203. break;
  1204. case 'DELETE':
  1205. Describe.doDelete(address, m);
  1206. break;
  1207. default:
  1208. break;
  1209. }
  1210. } else {
  1211. switch (m.type) {
  1212. case 'POST':
  1213. var formData = new FormData();
  1214. if (m.formParameters && m.formParameters.length > 0) {
  1215. $.each(m.formParameters, function(pi, p) {
  1216. if (p.type == "File") {
  1217. formData.append(p.name, $('input[type=file]', '#formParameters')[0].files[0]);
  1218. } else {
  1219. formData.append(p.name, $('#' + p.name, '#formParameters').val());
  1220. }
  1221. });
  1222. }
  1223. Describe.doPost(address, m, formData);
  1224. break;
  1225. case 'PUT':
  1226. var formData = new FormData();
  1227. if (m.formParameters && m.formParameters.length > 0) {
  1228. $.each(m.formParameters, function(pi, p) {
  1229. if (p.type == "File") {
  1230. formData.append(p.name, $('input[type=file]', '#formParameters')[0].files[0]);
  1231. } else {
  1232. formData.append(p.name, $('#' + p.name, '#formParameters').val());
  1233. }
  1234. });
  1235. }
  1236. Describe.doPut(address, m, formData);
  1237. break;
  1238. case 'GET':
  1239. Describe.doGet(address, m);
  1240. break;
  1241. case 'DELETE':
  1242. Describe.doDelete(address, m);
  1243. break;
  1244. default:
  1245. break;
  1246. }
  1247. }
  1248. })
  1249. debugger;
  1250. $('#Sample').html("<div style=\"border-bottom:1px solid #E6E6E6;padding-bottom: 40px;line-height:21px\"><span style=\"font-size:17px;font-weight:bold;color: #1E7ACE;\">\n平台推荐脚本样例</span>\n\n"+ Describe.createSampleCommon(m,j.name)+ "</div><div style=\"border-bottom:1px solid #E6E6E6;padding-bottom: 40px;line-height:21px\"><span style=\"font-size:17px;font-weight:bold;\">\n\n后台脚本样例</span>\n\n" + Describe.createSampleO2(m) + "</div><div style=\"line-height:21px\"><span style=\"font-size:17px;font-weight:bold;\">\n\njquery样例</span>\n\n<span style=\"\">"+ Describe.createSample(m)+"</span></div>");
  1251. });
  1252. });
  1253. });
  1254. $("[xtype='menu']").click(
  1255. function(event) {
  1256. if(event.stopPropagation){
  1257. event.stopPropagation();
  1258. }else{
  1259. event.cancelBubble = true;
  1260. }
  1261. $(this).children().each(function(i){
  1262. debugger;
  1263. if(this.tagName != "SPAN"){
  1264. $(this).toggle();
  1265. }
  1266. });
  1267. });
  1268. $("[xtype='li']").click( function(event) {
  1269. if(event.stopPropagation){
  1270. event.stopPropagation();
  1271. }else{
  1272. event.cancelBubble = true;
  1273. }
  1274. })
  1275. }
  1276. }