PageRenderTime 33ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/jsLinb4.0/VisualJS/js/ServiceTester.js

http://linb.googlecode.com/
JavaScript | 251 lines | 231 code | 18 blank | 2 comment | 7 complexity | 98b49f07da2deda6d7fe12bbed4a9b91 MD5 | raw file
  1. Class('VisualJS.ServiceTester', 'linb.Com',{
  2. Instance:{
  3. initialize : function(){
  4. this.autoDestroy = true;
  5. this.properties = {};
  6. },
  7. iniComponents : function(){
  8. // [[code created by jsLinb UI Builder
  9. var host=this, children=[], append=function(child){children.push(child.get(0))};
  10. append(
  11. (new linb.UI.Dialog)
  12. .setHost(host,"dlg")
  13. .setLeft(60)
  14. .setTop(60)
  15. .setWidth(600)
  16. .setHeight(407)
  17. .setCaption("$VisualJS.spabuilder.st_title")
  18. .setMinBtn(false)
  19. .setMaxBtn(false)
  20. .beforeClose("_dlg_beforeclose")
  21. );
  22. host.dlg.append(
  23. (new linb.UI.SLabel)
  24. .setHost(host,"ctl_slabel1")
  25. .setLeft(10)
  26. .setTop(10)
  27. .setWidth(74)
  28. .setCaption("$VisualJS.spabuilder.st_uri")
  29. );
  30. host.dlg.append(
  31. (new linb.UI.Group)
  32. .setHost(host,"ctl_group1")
  33. .setLeft(10)
  34. .setTop(40)
  35. .setWidth(570)
  36. .setHeight(120)
  37. .setCaption("$VisualJS.spabuilder.st_queryobj")
  38. .setToggleBtn(false)
  39. );
  40. host.ctl_group1.append(
  41. (new linb.UI.TextEditor)
  42. .setHost(host,"ctl_query")
  43. .setDirtyMark(false)
  44. .setLeft(5)
  45. .setWidth(560)
  46. .setHeight(100)
  47. .setValue("{a:1,b:2}")
  48. );
  49. host.dlg.append(
  50. (new linb.UI.SButton)
  51. .setHost(host,"ctl_sbutton5")
  52. .setLeft(460)
  53. .setTop(342)
  54. .setWidth(110)
  55. .setCaption("$VisualJS.close")
  56. .onClick("_ctl_sbutton5_onclick")
  57. );
  58. host.dlg.append(
  59. (new linb.UI.SButton)
  60. .setHost(host,"ctl_sbutton6")
  61. .setLeft(280)
  62. .setTop(342)
  63. .setWidth(170)
  64. .setCaption("$VisualJS.spabuilder.st_createcode")
  65. .onClick("_ctl_sbutton6_onclick")
  66. );
  67. host.dlg.append(
  68. (new linb.UI.Button)
  69. .setHost(host,"ctl_sbutton15")
  70. .setLeft(340)
  71. .setTop(174)
  72. .setWidth(230)
  73. .setHeight(36)
  74. .setCaption("<strong>$VisualJS.spabuilder.st_send</strong>")
  75. .onClick("_ctl_sbutton15_onclick")
  76. );
  77. host.dlg.append(
  78. (new linb.UI.Group)
  79. .setHost(host,"ctl_group3")
  80. .setLeft(10)
  81. .setTop(212)
  82. .setWidth(570)
  83. .setHeight(120)
  84. .setCaption("$VisualJS.spabuilder.st_result")
  85. .setToggleBtn(false)
  86. );
  87. host.ctl_group3.append(
  88. (new linb.UI.Input)
  89. .setHost(host,"ctl_result")
  90. .setDirtyMark(false)
  91. .setLeft(4)
  92. .setTop(0)
  93. .setWidth(560)
  94. .setHeight(100)
  95. .setMultiLines(true)
  96. );
  97. host.dlg.append(
  98. (new linb.UI.SButton)
  99. .setHost(host,"ctl_sbutton26")
  100. .setLeft(500)
  101. .setTop(35)
  102. .setWidth(70)
  103. .setCaption("$VisualJS.spabuilder.st_format")
  104. .onClick("_ctl_sbutton26_onclick")
  105. );
  106. host.dlg.append(
  107. (new linb.UI.RadioBox)
  108. .setHost(host,"ctl_method")
  109. .setDirtyMark(false)
  110. .setItems([{"id":"auto", "caption":"Auto"}, {"id":"get", "caption":"Get"}, {"id":"post", "caption":"Post"}])
  111. .setLeft(90)
  112. .setTop(175)
  113. .setWidth(220)
  114. .setHeight(26)
  115. .setValue("auto")
  116. );
  117. host.dlg.append(
  118. (new linb.UI.SLabel)
  119. .setHost(host,"ctl_slabel13")
  120. .setLeft(0)
  121. .setTop(180)
  122. .setWidth(84)
  123. .setCaption("$VisualJS.spabuilder.st_method")
  124. );
  125. host.dlg.append(
  126. (new linb.UI.ComboInput)
  127. .setHost(host,"ctl_uri")
  128. .setDirtyMark(false)
  129. .setLeft(90)
  130. .setTop(6)
  131. .setWidth(484)
  132. .setValueFormat("^(http|https)\\:")
  133. .setType("popbox")
  134. .setValue("http://www.linb.net/backend/PHP/demo.php")
  135. .onClick("_ctl_uri_onclick")
  136. );
  137. return children;
  138. // ]]code created by jsLinb UI Builder
  139. },
  140. customAppend : function(parent, subId, left, top){
  141. var ns=this;
  142. ns.dlg.setDisplay('block');
  143. ns.dlg.showModal();
  144. return false;
  145. },
  146. events : {},
  147. init:function(force){
  148. var ns=this;
  149. if(force){
  150. ns.ctl_uri.setValue("http://www.linb.net/backend/PHP/demo.php", true);
  151. ns.ctl_query.setValue("{a:1,b:2}", true);
  152. }
  153. ns.ctl_method.setValue("auto",true);
  154. ns.ctl_result.setValue("", true);
  155. },
  156. _ctl_sbutton5_onclick : function (profile, e, src, value) {
  157. var ns = this, uictrl = profile.boxing();
  158. ns.dlg.close();
  159. },
  160. _ctl_sbutton15_onclick : function (profile, e, src, value) {
  161. var ns = this,
  162. ctrl = profile.boxing(),
  163. options = {},
  164. uri = ns.ctl_uri.getUIValue(),
  165. str_query =ns.ctl_query.getUIValue();
  166. if(uri && str_query){
  167. var query = _.unserialize(str_query);
  168. if(query){
  169. var method = ns.ctl_method.getUIValue();
  170. if(method!='auto'){
  171. options.method = method;
  172. }
  173. ctrl.getRoot().onMouseout(true);
  174. ctrl.setDisabled(true).setCaption("<strong>$VisualJS.spabuilder.st_sending</strong>");
  175. linb.request(uri, query, function(rsp){
  176. var rspobj = rsp;
  177. if(rspobj){
  178. ns.showResult(rspobj);
  179. }else{
  180. ns.showErr(rsp);
  181. }
  182. ctrl.setDisabled(false).setCaption("<strong>$VisualJS.spabuilder.st_send</strong>");
  183. }, function(rsp){
  184. ns.showErr(rsp);
  185. ctrl.setDisabled(false).setCaption("<strong>$VisualJS.spabuilder.st_send</strong>");
  186. }, null, options);
  187. return ;
  188. }
  189. }
  190. linb.message(linb.getRes("VisualJS.spabuilder.st_nodata"));
  191. },
  192. showErr:function(msg){
  193. linb.alert(msg);
  194. },
  195. showResult:function(obj){
  196. var ns=this;
  197. ns.ctl_result.setValue(linb.Coder.formatText(_.stringify(obj)), true);
  198. },
  199. _ctl_sbutton26_onclick : function (profile, e, src, value) {
  200. var ns = this;
  201. this.ctl_query.setValue(linb.Coder.formatText(ns.ctl_query.getUIValue()),true);
  202. },
  203. _ctl_sbutton6_onclick : function (profile, e, src, value) {
  204. var ns = this, uictrl = profile.boxing(),
  205. uri = ns.ctl_uri.getUIValue(),
  206. str_query =ns.ctl_query.getUIValue(),
  207. method = ns.ctl_method.getUIValue();
  208. var code = 'linb.request("$1", ' + '\n' +
  209. '$2, '+ '\n' +
  210. 'function(rsp){' + '\n' +
  211. ' var rspobj = rsp;' + '\n' +
  212. ' if(rspobj){' + '\n' +
  213. ' // handle result' + '\n' +
  214. ' }else{' + '\n' +
  215. ' // handle exception' + '\n' +
  216. ' }' + '\n' +
  217. ' }, function(rsp){' + '\n' +
  218. ' // handle exception' + '\n' +
  219. ' }, null, $3);';
  220. code = code.replace('$1',uri ).replace('$2',str_query).replace('$3', method=="auto"?"null":("{method:'"+method+"'}"));
  221. ns.ctl_result.setValue(code, true);
  222. },
  223. _dlg_beforeclose : function (profile) {
  224. this.dlg.hide();
  225. this.dlg.setDisplay('none');
  226. return false;
  227. },
  228. _ctl_uri_onclick : function (profile, node) {
  229. var ns = this, uictrl = profile.boxing();
  230. linb.Dom.submit(uictrl.getUIValue());
  231. }
  232. }
  233. });