Web Interface For Lite Argus Control modules
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.

380 lines
12 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. /*
  16. * Portions of this file are based on pieces of Yahoo User Interface Library
  17. * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
  18. * YUI licensed under the BSD License:
  19. * http://developer.yahoo.net/yui/license.txt
  20. */
  21. Ext.lib.Ajax = function() {
  22. var activeX = ['Msxml2.XMLHTTP.6.0',
  23. 'Msxml2.XMLHTTP.3.0',
  24. 'Msxml2.XMLHTTP'],
  25. CONTENTTYPE = 'Content-Type';
  26. // private
  27. function setHeader(o) {
  28. var conn = o.conn,
  29. prop,
  30. headers = {};
  31. function setTheHeaders(conn, headers){
  32. for (prop in headers) {
  33. if (headers.hasOwnProperty(prop)) {
  34. conn.setRequestHeader(prop, headers[prop]);
  35. }
  36. }
  37. }
  38. Ext.apply(headers, pub.headers, pub.defaultHeaders);
  39. setTheHeaders(conn, headers);
  40. delete pub.headers;
  41. }
  42. // private
  43. function createExceptionObject(tId, callbackArg, isAbort, isTimeout) {
  44. return {
  45. tId : tId,
  46. status : isAbort ? -1 : 0,
  47. statusText : isAbort ? 'transaction aborted' : 'communication failure',
  48. isAbort: isAbort,
  49. isTimeout: isTimeout,
  50. argument : callbackArg
  51. };
  52. }
  53. // private
  54. function initHeader(label, value) {
  55. (pub.headers = pub.headers || {})[label] = value;
  56. }
  57. // private
  58. function createResponseObject(o, callbackArg) {
  59. var headerObj = {},
  60. headerStr,
  61. conn = o.conn,
  62. t,
  63. s,
  64. // see: https://prototype.lighthouseapp.com/projects/8886/tickets/129-ie-mangles-http-response-status-code-204-to-1223
  65. isBrokenStatus = conn.status == 1223;
  66. try {
  67. headerStr = o.conn.getAllResponseHeaders();
  68. Ext.each(headerStr.replace(/\r\n/g, '\n').split('\n'), function(v){
  69. t = v.indexOf(':');
  70. if(t >= 0){
  71. s = v.substr(0, t).toLowerCase();
  72. if(v.charAt(t + 1) == ' '){
  73. ++t;
  74. }
  75. headerObj[s] = v.substr(t + 1);
  76. }
  77. });
  78. } catch(e) {}
  79. return {
  80. tId : o.tId,
  81. // Normalize the status and statusText when IE returns 1223, see the above link.
  82. status : isBrokenStatus ? 204 : conn.status,
  83. statusText : isBrokenStatus ? 'No Content' : conn.statusText,
  84. getResponseHeader : function(header){return headerObj[header.toLowerCase()];},
  85. getAllResponseHeaders : function(){return headerStr;},
  86. responseText : conn.responseText,
  87. responseXML : conn.responseXML,
  88. argument : callbackArg
  89. };
  90. }
  91. // private
  92. function releaseObject(o) {
  93. if (o.tId) {
  94. pub.conn[o.tId] = null;
  95. }
  96. o.conn = null;
  97. o = null;
  98. }
  99. // private
  100. function handleTransactionResponse(o, callback, isAbort, isTimeout) {
  101. if (!callback) {
  102. releaseObject(o);
  103. return;
  104. }
  105. var httpStatus, responseObject;
  106. try {
  107. if (o.conn.status !== undefined && o.conn.status != 0) {
  108. httpStatus = o.conn.status;
  109. }
  110. else {
  111. httpStatus = 13030;
  112. }
  113. }
  114. catch(e) {
  115. httpStatus = 13030;
  116. }
  117. if ((httpStatus >= 200 && httpStatus < 300) || (Ext.isIE && httpStatus == 1223)) {
  118. responseObject = createResponseObject(o, callback.argument);
  119. if (callback.success) {
  120. if (!callback.scope) {
  121. callback.success(responseObject);
  122. }
  123. else {
  124. callback.success.apply(callback.scope, [responseObject]);
  125. }
  126. }
  127. }
  128. else {
  129. switch (httpStatus) {
  130. case 12002:
  131. case 12029:
  132. case 12030:
  133. case 12031:
  134. case 12152:
  135. case 13030:
  136. responseObject = createExceptionObject(o.tId, callback.argument, (isAbort ? isAbort : false), isTimeout);
  137. if (callback.failure) {
  138. if (!callback.scope) {
  139. callback.failure(responseObject);
  140. }
  141. else {
  142. callback.failure.apply(callback.scope, [responseObject]);
  143. }
  144. }
  145. break;
  146. default:
  147. responseObject = createResponseObject(o, callback.argument);
  148. if (callback.failure) {
  149. if (!callback.scope) {
  150. callback.failure(responseObject);
  151. }
  152. else {
  153. callback.failure.apply(callback.scope, [responseObject]);
  154. }
  155. }
  156. }
  157. }
  158. releaseObject(o);
  159. responseObject = null;
  160. }
  161. function checkResponse(o, callback, conn, tId, poll, cbTimeout){
  162. if (conn && conn.readyState == 4) {
  163. clearInterval(poll[tId]);
  164. poll[tId] = null;
  165. if (cbTimeout) {
  166. clearTimeout(pub.timeout[tId]);
  167. pub.timeout[tId] = null;
  168. }
  169. handleTransactionResponse(o, callback);
  170. }
  171. }
  172. function checkTimeout(o, callback){
  173. pub.abort(o, callback, true);
  174. }
  175. // private
  176. function handleReadyState(o, callback){
  177. callback = callback || {};
  178. var conn = o.conn,
  179. tId = o.tId,
  180. poll = pub.poll,
  181. cbTimeout = callback.timeout || null;
  182. if (cbTimeout) {
  183. pub.conn[tId] = conn;
  184. pub.timeout[tId] = setTimeout(checkTimeout.createCallback(o, callback), cbTimeout);
  185. }
  186. poll[tId] = setInterval(checkResponse.createCallback(o, callback, conn, tId, poll, cbTimeout), pub.pollInterval);
  187. }
  188. // private
  189. function asyncRequest(method, uri, callback, postData) {
  190. var o = getConnectionObject() || null;
  191. if (o) {
  192. o.conn.open(method, uri, true);
  193. if (pub.useDefaultXhrHeader) {
  194. initHeader('X-Requested-With', pub.defaultXhrHeader);
  195. }
  196. if(postData && pub.useDefaultHeader && (!pub.headers || !pub.headers[CONTENTTYPE])){
  197. initHeader(CONTENTTYPE, pub.defaultPostHeader);
  198. }
  199. if (pub.defaultHeaders || pub.headers) {
  200. setHeader(o);
  201. }
  202. handleReadyState(o, callback);
  203. o.conn.send(postData || null);
  204. }
  205. return o;
  206. }
  207. // private
  208. function getConnectionObject() {
  209. var o;
  210. try {
  211. if (o = createXhrObject(pub.transactionId)) {
  212. pub.transactionId++;
  213. }
  214. } catch(e) {
  215. } finally {
  216. return o;
  217. }
  218. }
  219. // private
  220. function createXhrObject(transactionId) {
  221. var http;
  222. try {
  223. http = new XMLHttpRequest();
  224. } catch(e) {
  225. for (var i = 0; i < activeX.length; ++i) {
  226. try {
  227. http = new ActiveXObject(activeX[i]);
  228. break;
  229. } catch(e) {}
  230. }
  231. } finally {
  232. return {conn : http, tId : transactionId};
  233. }
  234. }
  235. var pub = {
  236. request : function(method, uri, cb, data, options) {
  237. if(options){
  238. var me = this,
  239. xmlData = options.xmlData,
  240. jsonData = options.jsonData,
  241. hs;
  242. Ext.applyIf(me, options);
  243. if(xmlData || jsonData){
  244. hs = me.headers;
  245. if(!hs || !hs[CONTENTTYPE]){
  246. initHeader(CONTENTTYPE, xmlData ? 'text/xml' : 'application/json');
  247. }
  248. data = xmlData || (!Ext.isPrimitive(jsonData) ? Ext.encode(jsonData) : jsonData);
  249. }
  250. }
  251. return asyncRequest(method || options.method || "POST", uri, cb, data);
  252. },
  253. serializeForm : function(form) {
  254. var fElements = form.elements || (document.forms[form] || Ext.getDom(form)).elements,
  255. hasSubmit = false,
  256. encoder = encodeURIComponent,
  257. name,
  258. data = '',
  259. type,
  260. hasValue;
  261. Ext.each(fElements, function(element){
  262. name = element.name;
  263. type = element.type;
  264. if (!element.disabled && name) {
  265. if (/select-(one|multiple)/i.test(type)) {
  266. Ext.each(element.options, function(opt){
  267. if (opt.selected) {
  268. hasValue = opt.hasAttribute ? opt.hasAttribute('value') : opt.getAttributeNode('value').specified;
  269. data += String.format("{0}={1}&", encoder(name), encoder(hasValue ? opt.value : opt.text));
  270. }
  271. });
  272. } else if (!(/file|undefined|reset|button/i.test(type))) {
  273. if (!(/radio|checkbox/i.test(type) && !element.checked) && !(type == 'submit' && hasSubmit)) {
  274. data += encoder(name) + '=' + encoder(element.value) + '&';
  275. hasSubmit = /submit/i.test(type);
  276. }
  277. }
  278. }
  279. });
  280. return data.substr(0, data.length - 1);
  281. },
  282. useDefaultHeader : true,
  283. defaultPostHeader : 'application/x-www-form-urlencoded; charset=UTF-8',
  284. useDefaultXhrHeader : true,
  285. defaultXhrHeader : 'XMLHttpRequest',
  286. poll : {},
  287. timeout : {},
  288. conn: {},
  289. pollInterval : 50,
  290. transactionId : 0,
  291. // This is never called - Is it worth exposing this?
  292. // setProgId : function(id) {
  293. // activeX.unshift(id);
  294. // },
  295. // This is never called - Is it worth exposing this?
  296. // setDefaultPostHeader : function(b) {
  297. // this.useDefaultHeader = b;
  298. // },
  299. // This is never called - Is it worth exposing this?
  300. // setDefaultXhrHeader : function(b) {
  301. // this.useDefaultXhrHeader = b;
  302. // },
  303. // This is never called - Is it worth exposing this?
  304. // setPollingInterval : function(i) {
  305. // if (typeof i == 'number' && isFinite(i)) {
  306. // this.pollInterval = i;
  307. // }
  308. // },
  309. // This is never called - Is it worth exposing this?
  310. // resetDefaultHeaders : function() {
  311. // this.defaultHeaders = null;
  312. // },
  313. abort : function(o, callback, isTimeout) {
  314. var me = this,
  315. tId = o.tId,
  316. isAbort = false;
  317. if (me.isCallInProgress(o)) {
  318. o.conn.abort();
  319. clearInterval(me.poll[tId]);
  320. me.poll[tId] = null;
  321. clearTimeout(pub.timeout[tId]);
  322. me.timeout[tId] = null;
  323. handleTransactionResponse(o, callback, (isAbort = true), isTimeout);
  324. }
  325. return isAbort;
  326. },
  327. isCallInProgress : function(o) {
  328. // if there is a connection and readyState is not 0 or 4
  329. return o.conn && !{0:true,4:true}[o.conn.readyState];
  330. }
  331. };
  332. return pub;
  333. }();</pre>
  334. </body>
  335. </html>