// Copyright © 2003 FocusPoint Solutions // This file is part of the // Dynamic Web Application Framework for .NET if ("undefined" == typeof (XMLHttpRequest)) { var XMLHttpRequest = function() { if (typeof window.ActiveXObject != "undefined") { try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.4.0"); } catch (err) { try { xmlHttp = new ActiveXObject("MSXML2.XMLHTTP"); } catch (err) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (err) { xmlHttp = null; } } } return xmlHttp; } }; } // JSON support for javascrit as seen in JSON.ORG function JSONSerializer() { var m = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"': '\\"', '\\': '\\\\' }, s = { array: function(x) { var a = ['['], b, f, i, l = x.length, v; for (i = 0; i < l; i += 1) { v = x[i]; f = s[typeof v]; if (f) { v = f(v); if (typeof v == 'string') { if (b) { a[a.length] = ','; } a[a.length] = v; b = true; } } } a[a.length] = ']'; return a.join(''); }, 'boolean': function(x) { return String(x); }, 'null': function(x) { return "null"; }, number: function(x) { return isFinite(x) ? String(x) : 'null'; }, object: function(x) { if (x) { if (x instanceof Array) { return s.array(x); } var a = ['{'], b, f, i, v; for (i in x) { v = x[i]; f = s[typeof v]; if (f) { v = f(v); if (typeof v == 'string') { if (b) { a[a.length] = ','; } a.push(s.string(i), ':', v); b = true; } } } a[a.length] = '}'; return a.join(''); } return 'null'; }, string: function(x) { if (/["\\\x00-\x1f]/.test(x)) { x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) { var c = m[b]; if (c) { return c; } c = b.charCodeAt(); return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); }); } return '"' + x + '"'; } }; var $this = { serialize: function(x) { if (typeof (x) === 'array') { return s.array(x); } else { return s.object(x); } }, deserialize: function(x) { if (typeof (x) === 'string') { return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test( this.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + this + ')'); } else { throw "Not Supported"; } } }; return $this; } var DWAEvents = {}; DWAEvents.PostProcessResponse = null; function DWAParameter(name, type, value) { this.name = name; this.type = type; this.value = value; } function DWAClient(typeName) { this.onError = null; this.request = new XMLHttpRequest(); this.typeName = typeName; this.url = null; this.authorizationHeader = null; this.onCompleted = null; this.onError = null; this.executeAsync = false; } DWAClient.prototype.parseResponse = function(response) { var result = null; if (response) { // create object from JSON try { //sometime this method is called on javascript wizard close and eval in that time does nos exists result = eval("(" + response + ")"); } catch (e) { /* ignore */ } } else { result = { error: true, errorCode: 500 }; } return result; }; DWAClient.prototype.serializeComplexValue = function(value) { var result = ''; if (null == value) { return 'null'; } result += ''; if (value.constructor == Array) { var s = ''; for (var i = 0; i < value.length; ++i) { result += ''; result += this.serializeValue(value[i]); result += ''; } } else { for (var property in value) { var propertyType = eval('typeof(value.' + property + ')'); if ('function' == propertyType) { continue; } result += '

'; result += this.serializeValue(eval('value.' + property)); result += '

'; } } result += '
'; return result; }; DWAClient.prototype.serializeSimpleValue = function(value) { var type = typeof (value); if (type == 'number') { return '' + value + ''; } else { return ''; } }; DWAClient.prototype.serializeValue = function(value) { if (null == value) { return ''; } if ('object' == typeof (value)) { return this.serializeComplexValue(value); } else { return this.serializeSimpleValue(value); } }; DWAClient.prototype.serializeParameter = function(parameter) { var result = ""; result += this.serializeValue(parameter.value); result += ""; return result; }; DWAClient.prototype.handleRequestResult = function(proxy) { try { var result = null; if (200 == this.request.status) { result = this.parseResponse(this.request.responseText); } else { result = {}; result.error = true; result.errorCode = this.request.status; result.value = "Http " + this.request.status + " Error"; } if (null != DWAEvents.PostProcessResponse) { DWAEvents.PostProcessResponse(proxy, result); } if (this.executeAsync) { if (result.error) { if (this.onError) { this.onError(result); } } else { if (this.onCompleted) { this.onCompleted(result); } } } return result; } finally { if (this.request != null) { var me = this; this.request.onReadyStateChange = function() { if (4 == me.request.readyState) { me.request = null; } }; } } }; DWAClient.prototype.executeServerMethod = function(proxy, name, args) { // create xml to send for server var content = ""; if (this.actionId) { content += ""; } if (args) { for (var i = 0; i < args.length; i++) { content += this.serializeParameter(args[i]); } } content += ""; if (!this.executeAsync) { this.executeAsync = false; } // send post this.request.open("POST", this.url, this.executeAsync); this.request.setRequestHeader("Content-Type", "text/xml"); //this.request.setRequestHeader("Content-length", content.length); //this.request.setRequestHeader("Connection", "close"); if (this.executeAsync) { var me = this; var xmlHttp = this.request; this.request.onreadystatechange = function() { if (4 == xmlHttp.readyState && 200 == xmlHttp.status) { me.handleRequestResult(proxy); xmlHttp = null; } }; } try { this.request.send(content); if (!this.executeAsync) { return this.handleRequestResult(proxy); } } catch (err) { var errorMessage = "Ocorreu um erro a efectuar a operacao devido a uma falha na ligacao:\n\n" + "[Codigo]: " + err.number + "\n" + "[Mensagem]: " + err.message + "\n\n" + "Prima OK e tente novamente ..."; alert(errorMessage); result = {}; result.error = true; result.errorCode = err.number; result.value = err.message; return result; } return null; }; //this line must be at the end of the script if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();