You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

388 lines
10 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. // Create and append to the body, a Panel containing a block of code from the passed URL
  16. function createCodePanel(url, title) {
  17. var panel = new Ext.Panel({
  18. hideMode: 'visibility',
  19. title: title,
  20. width: 750,
  21. style: {
  22. 'margin-top': '10px'
  23. },
  24. hideCollapseTool: true,
  25. titleCollapse: true,
  26. collapsible: true,
  27. collapsed: true,
  28. autoScroll: true,
  29. renderTo: Ext.getBody(),
  30. listeners: {
  31. render: function(p) {
  32. p.getUpdater().setRenderer({
  33. render: Ext.isIE ? function(el, response, scripts, callback) {
  34. el.update('');
  35. var np = el.createChild({
  36. tag: 'pre',
  37. cls: 'code',
  38. cn: {
  39. tag: 'code'
  40. }
  41. });
  42. var t = response.responseText.split("\n");
  43. var c = np.child('code', true);
  44. for (var i = 0, l = t.length; i < l; i++) {
  45. var pre = document.createElement('pre');
  46. if (t[i].length) {
  47. pre.appendChild(document.createTextNode(t[i]));
  48. c.appendChild(pre);
  49. } else if (i < (l - 1)) {
  50. c.appendChild(document.createElement("br"));
  51. }
  52. }
  53. } : function(el, response, scripts, callback) {
  54. el.update('');
  55. el.createChild({
  56. tag: 'pre',
  57. cls: 'code',
  58. cn: {
  59. tag: 'code',
  60. html: response.responseText
  61. }
  62. });
  63. }
  64. });
  65. },
  66. beforeexpand: function(p) {
  67. p.load(url);
  68. },
  69. single: true
  70. }
  71. });
  72. }
  73. // Patch to allow XHR to local files. From hendricd: http://extjs.com/forum/member.php?u=8730
  74. Ext.apply( Ext.lib.Ajax ,
  75. { forceActiveX:false,
  76. createXhrObject:function(transactionId)
  77. {
  78. var obj={ status:{isError:false}
  79. , tId:transactionId}, http;
  80. try
  81. {
  82. if(Ext.isIE7 && !!this.forceActiveX){throw("IE7forceActiveX");}
  83. obj.conn= new XMLHttpRequest();
  84. }
  85. catch(e)
  86. {
  87. for (var i = 0; i < this.activeX.length; ++i) {
  88. try
  89. {
  90. obj.conn= new ActiveXObject(this.activeX[i]);
  91. break;
  92. }
  93. catch(e) {
  94. }
  95. }
  96. }
  97. finally
  98. {
  99. obj.status.isError = typeof(obj.conn) === undefined;
  100. }
  101. return obj;
  102. },
  103. getHttpStatus: function(reqObj){
  104. var statObj = { status:0
  105. ,statusText:''
  106. ,isError:false
  107. ,isLocal:false
  108. ,isOK:false
  109. ,error:null};
  110. try {
  111. if(!reqObj)throw('noobj');
  112. statObj.status = reqObj.status;
  113. statObj.isLocal = !reqObj.status && location.protocol == "file:" ||
  114. Ext.isSafari && reqObj.status === undefined;
  115. statObj.isOK = (statObj.isLocal || (statObj.status > 199 && statObj.status < 300));
  116. statObj.statusText = reqObj.statusText || '';
  117. } catch(e){ //status may not avail/valid yet (or called too early).
  118. }
  119. return statObj;
  120. },
  121. handleTransactionResponse:function(o, callback, isAbort)
  122. {
  123. callback = callback || {};
  124. var responseObject=null;
  125. if(!o.status.isError){
  126. o.status = this.getHttpStatus(o.conn);
  127. /* create and enhance the response with proper status and XMLDOM if necessary */
  128. responseObject = this.createResponseObject(o, callback.argument);
  129. }
  130. if(o.status.isError){ /* checked again in case exception was raised - ActiveX was disabled during XML-DOM creation? */
  131. // And mixin everything the XHR object had to offer as well
  132. responseObject = Ext.applyIf(responseObject||{},this.createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false)));
  133. }
  134. responseObject.options = o.options;
  135. responseObject.stat = o.status;
  136. if (o.status.isOK && !o.status.isError) {
  137. if (callback.success) {
  138. if (!callback.scope) {
  139. callback.success(responseObject);
  140. }
  141. else {
  142. callback.success.apply(callback.scope, [responseObject]);
  143. }
  144. }
  145. } else {
  146. if (callback.failure) {
  147. if (!callback.scope) {
  148. callback.failure(responseObject);
  149. }
  150. else {
  151. callback.failure.apply(callback.scope, [responseObject]);
  152. }
  153. }
  154. }
  155. if(o.options.async){
  156. this.releaseObject(o);
  157. responseObject = null;
  158. }else{
  159. this.releaseObject(o);
  160. return responseObject;
  161. }
  162. },
  163. createResponseObject:function(o, callbackArg)
  164. {
  165. var obj = {};
  166. var headerObj = {},headerStr='';
  167. try{ //to catch bad encoding problems here
  168. obj.responseText = o.conn.responseText;
  169. }catch(e){obj.responseText ='';}
  170. obj.responseXML = o.conn.responseXML;
  171. try{
  172. headerStr = o.conn.getAllResponseHeaders()||'';
  173. } catch(e){}
  174. if(o.status.isLocal){
  175. o.status.isOK = ((o.status.status = (!!obj.responseText.length)?200:404) == 200);
  176. if(o.status.isOK && (!obj.responseXML || obj.responseXML.childNodes.length == 0)){
  177. var xdoc=null;
  178. try{ //ActiveX may be disabled
  179. if(typeof(DOMParser) == 'undefined'){
  180. xdoc=new ActiveXObject("Microsoft.XMLDOM");
  181. xdoc.async="false";
  182. xdoc.loadXML(obj.responseText);
  183. }else{
  184. try{ //Opera 9 will fail parsing non-XML content, so trap here.
  185. var domParser = new DOMParser();
  186. xdoc = domParser.parseFromString(obj.responseText, 'application\/xml');
  187. }catch(ex){}
  188. finally{domParser = null;}
  189. }
  190. } catch(ex){
  191. o.status.isError = true;
  192. o.status.error = ex;
  193. }
  194. obj.responseXML = xdoc;
  195. }
  196. if(obj.responseXML){
  197. var parseBad = (obj.responseXML.parseError || 0) != 0 || obj.responseXML.childNodes.length == 0;
  198. if(!parseBad){
  199. headerStr = 'Content-Type: ' + (obj.responseXML.contentType || 'text\/xml') + '\n' + headerStr ;
  200. }
  201. }
  202. }
  203. var header = headerStr.split('\n');
  204. for (var i = 0; i < header.length; i++) {
  205. var delimitPos = header[i].indexOf(':');
  206. if (delimitPos != -1) {
  207. headerObj[header[i].substring(0, delimitPos)] = header[i].substring(delimitPos + 2);
  208. }
  209. }
  210. obj.tId = o.tId;
  211. obj.status = o.status.status;
  212. obj.statusText = o.status.statusText;
  213. obj.getResponseHeader = headerObj;
  214. obj.getAllResponseHeaders = headerStr;
  215. obj.stat = o.status
  216. if (typeof callbackArg !== undefined) {
  217. obj.argument = callbackArg;
  218. }
  219. return obj;
  220. },
  221. request : function(method, uri, cb, data, options) {
  222. options = Ext.apply({async:true,
  223. headers:false,
  224. userId:null,
  225. password:null,
  226. xmlData:null }, options||{});
  227. var hs = options.headers;
  228. if(hs){
  229. for(var h in hs){
  230. if(hs.hasOwnProperty(h)){
  231. this.initHeader(h, hs[h], false);
  232. }
  233. }
  234. }
  235. if(options.xmlData){
  236. this.initHeader('Content-Type', 'text/xml', false);
  237. method = 'POST';
  238. data = options.xmlData;
  239. }
  240. return this.makeRequest(method, uri, cb, data, options);
  241. },
  242. asyncRequest:function(method, uri, callback, postData)
  243. {
  244. var o = this.getConnectionObject();
  245. if (!o || o.status.isError) {
  246. return null;
  247. }
  248. else {
  249. o.options = options;
  250. try{
  251. o.conn.open(method, uri, true);
  252. } catch(ex){
  253. o.status.isError = true;
  254. o.status.error = ex;
  255. return Ext.apply(o,this.handleTransactionResponse(o, callback));
  256. }
  257. if (this.useDefaultXhrHeader) {
  258. if (!this.defaultHeaders['X-Requested-With']) {
  259. this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
  260. }
  261. }
  262. if(postData && this.useDefaultHeader){
  263. this.initHeader('Content-Type', this.defaultPostHeader);
  264. }
  265. if (this.hasDefaultHeaders || this.hasHeaders) {
  266. this.setHeader(o);
  267. }
  268. this.handleReadyState(o, callback);
  269. try{ o.conn.send(postData || null);
  270. } catch(ex){
  271. o.status.isError=true;
  272. o.status.error = ex;
  273. return Ext.apply(o,this.handleTransactionResponse(o, callback));
  274. }
  275. return o;
  276. }
  277. },
  278. makeRequest:function(method, uri, callback, postData, options)
  279. {
  280. var o = this.getConnectionObject();
  281. if (!o || o.status.isError) {
  282. return null;
  283. }
  284. else {
  285. o.options = options;
  286. try{
  287. o.conn.open(method, uri, options.async, options.userId, options.password);
  288. } catch(ex){
  289. o.status.isError = true;
  290. o.status.error = ex;
  291. var r=this.handleTransactionResponse(o, callback);
  292. return Ext.apply(o,r);
  293. }
  294. if (this.useDefaultXhrHeader) {
  295. if (!this.defaultHeaders['X-Requested-With']) {
  296. this.initHeader('X-Requested-With', this.defaultXhrHeader, true);
  297. }
  298. }
  299. if(postData && this.useDefaultHeader){
  300. this.initHeader('Content-Type', this.defaultPostHeader);
  301. }
  302. if (this.hasDefaultHeaders || this.hasHeaders) {
  303. this.setHeader(o);
  304. }
  305. if(o.options.async){ //Timers won't work here as it's a blocking call
  306. this.handleReadyState(o, callback);
  307. }
  308. try{ o.conn.send(postData || null);
  309. } catch(ex){
  310. //Ext.apply(o,this.handleTransactionResponse(o, callback));
  311. }
  312. return options.async?o:Ext.apply(o,this.handleTransactionResponse(o, callback));
  313. }
  314. }});
  315. Ext.lib.Ajax.forceActiveX = (document.location.protocol == 'file:');/* or other true/false mechanism */