function SoapAction(a){this.path=a||""}SoapAction.prototype.getData=function(a){a.body=this.createBody(a.body);var b=this;$.ajax({url:b.path+a.url,type:"post",data:a.body,dataType:"text",contentType:"text/xml; charset=utf-8",headers:{SOAPAction:'"http://opcfoundation.org/webservices/XMLDA/1.0/'+a.name+'"'},success:function(c){c=b.clearXml(c);a.success(c)},error:function(){a.error()}})};
SoapAction.prototype.clearXml=function(a){a=a.replace(/<\?xml.*?\?>/g,"");for(var b=a.match(/xmlns\:[^=]*/g)||[],c=0,f=b.length;c<f;c++){var e=b[c].split(":")[1];a=a.replace(RegExp(e+":","g"),"")}return $.parseXML("<xml>"+a+"</xml>")};
SoapAction.prototype.createBody=function(a){return'<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body>'+a+" </soap:Body></soap:Envelope>"};
SoapAction.prototype.read=function(a,b){var c=a.items,f=a.group_uid||"";if(c&&c.length){b=b||$.noop;for(var e='<Read xmlns="http://opcfoundation.org/webservices/XMLDA/1.0/"><Options ReturnItemTime="true" ReturnItemName="true" ClientRequestHandle="" LocaleID="en-US" /><ItemList>',g={},d=0;d<c.length;d++)e+='<Items ItemName="'+c[d].id+'" ClientItemHandle="'+(c[d].uid||"")+'" ClientRequestHandle="'+f+'"/>',g[c[d].id]={desc:c[d].desc,ReType:c[d].ReType,Address:c[d].Address};this.getData({url:"/Read",
name:"Read",body:e+"</ItemList></Read>",success:function(c){c=$(c).find(this.name+"Response");var d=[];c.find("RItemList").find("Items").each(function(a,c){var b=$(this);if(b.attr("ItemName")){var e=g[b.attr("ItemName")],b={itemName:b.attr("ItemName"),valueType:b.find("Value").attr("type")||"",value:b.find("Value").text(),time:b.attr("Timestamp")||"",quality:b.find("Quality").attr("QualityField")||"",desc:e.desc,ReType:e.ReType,Address:e.Address};d.push(b)}});b(d,f,c,a.items)},error:function(){}})}};
SoapAction.prototype.write=function(a){a=a||[{name:"Channel_1.Device_1.Tag_1",value:1}];$.isArray(a)||(a=[a]);for(var b='<Write xmlns="http://opcfoundation.org/webservices/XMLDA/1.0/"><ItemList>',c=0,f=a.length;c<f;c++)b+='<Items   ItemName="'+a[c].name+'" ClientItemHandle="'+(a[c].uid||"")+'" ClientRequestHandle="'+(a[c].group_uid||"")+'"><DiagnosticInfo>string</DiagnosticInfo><Value>'+a[c].value+"</Value><Quality/></Items>";this.getData({url:"/Write",name:"Write",body:b+"</ItemList></Write>",success:function(a){$(a).find(this.name+
"Response").find("RItemList").find("Items")},error:function(){}})};SoapAction.prototype.getStatus=function(a){a=a||$.noop;this.getData({url:"/GetStatus",name:"GetStatus",body:' <GetStatus LocaleID="en-US" xmlns="http://opcfoundation.org/webservices/XMLDA/1.0/" />',success:function(b){b=$(b).find("GetStatusResult").attr("ServerState");$("#getStatus").html(b);"running"==b?a(b):window.console&&console.log(b)},error:function(){window.console&&console.log("getStatus error!!!")}})};
