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.

374 lines
9.8 KiB

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