$(function(){function v(f){var b='<ul class="nav child_menu">';f.find("Channel").each(function(){var a=$(this),d=a.attr("Name"),a=a.find("Devices");b+="<li><a>"+d+'<span class="fa fa-chevron-down"></span></a>'+w(a)+"</li>"});return b+="</ul>"}function x(f,b){k&&clearInterval(k);n=l?!0:!1;f&&p(f,b,-1,function(){})}function y(f,b){l=!0;q.read({items:f},function(a,d,e,c){l=!1;if(!n){for(d=0;d<a.length;d++)a[d].itemName==c[d].id&&$.extend(a[d],c[d]);b(a)}})}function p(f,b,a,d){var e=g[f];e&&(e=e.concat(),
-1!=a?(a>=e.length&&(a=0),e=e.slice(a,a+r)):clearTimeout(k),!e||0>=e.length?d():y(e,function(c){if(-1==a)h=c,a=0;else{for(var e=0;e<c.length;e++)h[e+a]=c[e];a+=r}z(f,b,h);c=200;a>=h.length&&(c=A);k=setTimeout(function(){p(f,b,a,d)},c)}))}function z(f,b,a){if(0<a.length){var d=[],d="soap_variant"==f?[{field:"ItemID",title:$.i18n("title-tag-name")||"Tag Name",width:300},{field:"DataType",title:$.i18n("title-data-type")||"Data Type",width:100},{field:"value",title:$.i18n("title-value")||"Value",width:80},
{field:"quality",title:$.i18n("title-quality")||"Quality",width:80},{field:"time",title:$.i18n("title-timestamp")||"TimeStamp",width:180},{field:"ModbusID",title:$.i18n("title-modbus-id")||"ModbusID",width:80},{field:"ModbusType",title:$.i18n("title-objecttype")||"TransRegister",width:110},{field:"ModbusAddr",title:$.i18n("title-instancenum")||"TransAddress",width:110},{field:"Description",title:$.i18n("title-description")||"Description",width:180}]:[{field:"ItemID",title:$.i18n("title-tag-name")||
"Tag Name",width:120},{field:"RegisterName",title:$.i18n("title-register-type")||"Register Type",width:150},{field:"Address",title:$.i18n("title-address")||"Register Address",width:100},{field:"DataType",title:$.i18n("title-data-type")||"Data Type",width:100},{field:"value",title:$.i18n("title-value")||"Value",width:80},{field:"quality",title:$.i18n("title-quality")||"Quality",width:80},{field:"time",title:$.i18n("title-timestamp")||"TimeStamp",width:180},{field:"ModbusType",title:$.i18n("title-objecttype")||
"TransRegister",width:110},{field:"ModbusAddr",title:$.i18n("title-instancenum")||"TransAddress",width:110},{field:"Description",title:$.i18n("title-description")||"Description",width:180}];f=$("<table id='grid_table' class='table table-striped table-bordered table-hover jambo_table'></table>");b=s(b,f);m.empty().append(b);b="<thead><tr>";for(var e="<tbody>",c=0;c<d.length;c++){var g=d[c];b+="<td>"+g.title+"</td>"}for(c=0;c<a.length;c++){for(var k=a[c],e=e+"<tr>",h=0;h<d.length;h++)g=d[h],e+="<td>"+
(k[g.field]||"")+"</td>";e+="</tr>"}f.html(b+"</tr></thead>"+(e+"</tbody>"));f.on("click","tbody tr",function(){var b=$(this).index(),c=a[b];c&&dialog.prompt(c.ItemID,function(a){q.write([{name:c.itemName,value:a}])})})}}function w(f){var b='<ul class="nav child_menu">';f.find("Device").each(function(){var a=$(this),d=a.attr("Name"),e=a.attr("ID"),c=a.children("Tags"),a=a.find("Groups");t(c,e);c=B(a);b+='<li itemName="'+d+'" id="'+e+'" data-name="'+d+'"><a>'+d;c&&(b+='<span class="fa fa-chevron-down"></span>');
b+="</a>"+c+"</li>"});return b+="</ul>"}function B(f){var b='<ul class="nav child_menu">',a=!1;f.find("Group").each(function(){a=!0;var d=$(this),e=d.attr("Name"),c=d.attr("ID"),d=d.find("Tags");b+='<li itemName="'+e+'" id="'+c+'" data-name="'+e+'"><a>'+e+"</a></li>";t(d,c)});b+="</ul>";return a?b:""}function t(f,b){g[b]=[];f.find("Tag").each(function(){var a=$(this),d=a.attr("ModbusType"),e=a.attr("ModbusAddr");switch(d){case "0":d="0X(Coil Status)";break;case "1":d="1X(Input Status)";break;case "2":d=
"3X(Input Register)";break;case "3":d="4X(Holding Register)";break;default:e=d=""}"-1"==e&&(e=d="");var c=a.attr("DataType");switch(c){case "0":c="None";break;case "1":c="Boolean";break;case "2":c="Word";break;case "3":c="Short";break;case "4":c="DWord";break;case "5":c="Long";break;case "6":c="Float";break;case "7":c="Double";break;case "8":c="String";break;case "9":c="Time";break;default:c=""}g[b].push({id:a.attr("ItemName")||"",ItemID:a.attr("ItemID")||"",RegisterID:a.attr("RegisterID")||"",RegisterName:a.attr("RegisterName")||
"",Address:a.attr("Address")||"",Description:a.attr("Description")||"",DataType:c,ModbusType:d,ModbusAddr:e})})}function C(f,b){g[b]=[];f.find("Tag").each(function(){var a=$(this),d=a.attr("ModbusType"),e=a.attr("ModbusAddr");switch(d){case "0":d="0X(Coil Status)";break;case "1":d="1X(Input Status)";break;case "2":d="3X(Input Register)";break;case "3":d="4X(Holding Register)";break;default:e=d=""}"-1"==e&&(e=d="");var c=a.attr("DataType");switch(c){case "0":c="None";break;case "1":c="Boolean";break;
case "2":c="Word";break;case "3":c="Short";break;case "4":c="DWord";break;case "5":c="Long";break;case "6":c="Float";break;case "7":c="Double";break;case "8":c="String";break;case "9":c="Time";break;default:c=""}g[b].push({id:a.attr("ItemID")||"",ItemID:a.attr("ItemID")||"",Address:a.attr("Address")||"",Description:a.attr("Description")||"",DataType:c,ModbusType:d,ModbusAddr:e,ModbusID:a.attr("ModbusID")||""})})}function D(f){var b='<ul class="nav child_menu">';f.find("HMI").each(function(){var a=
$(this).attr("Name");b+="<li><a>"+a+"</a></li>"});b+="</ul>";u.append(b)}function s(f,b){var a=$('<div style="padding:0 10px;"><div class="x_panel" style="">            <div class="x_title">                <h2>'+f+'</h2>                <div class="clearfix"></div>            </div>           <div class="x_content">            </div></div></div>');a.find(".x_content").append(b);return a}$("a[target]").click(function(){var f=(new Date).getTime(),f='<iframe name="view_iframe" src="'+$(this).attr("data-href")+
"?_="+f+'"  frameborder=no border=0></iframe>';m.html(f)});var m=$("#rightContent"),E=$("#sidebar-menu"),F=$("#soap_server"),u=$("#soap_windows"),g={},q=new SoapAction("/soap");$.ajax({url:"/soap/GetConfig",type:"post",data:"Getconfig",dataType:"xml",contentType:"text/xml; charset=utf-8",success:function(f){var b='<ul class="nav child_menu">';$(f).find("Driver").each(function(a){$driver=$(this);$devices=$driver.find("Devices");driver_name=$driver.attr("Name");a=b;var d="<li><a>"+driver_name+'<span class="fa fa-chevron-down"></span></a>',
e=$driver.find("Channels"),e=""+v(e);b=a+(d+e+"</li>")});b+="</ul>";F.append(b);$(f).find("Vars").each(function(a){$Vars=$(this);C($Vars,"soap_variant")});$(f).find("HMIList").each(function(a){$HMIList=$(this);D($HMIList)});E.find("li").find("a").click(function(){var a=$(this).parent().attr("id"),b=$(this).parent().attr("data-name"),b=$.i18n(b);x(a,b)});u.find("ul").find("a").click(function(){var a=$(this).text();void 0!=a&&(a=s(a,'<iframe name="view_iframe" src="'+(a+".htm")+'"  frameborder=no border=0></iframe>'),
m.empty().append(a))})}});var A=1500,l=!1,n=!1,r=50,h=[],k=0});
