(function(g){var q=new function(){this.SMB=function(){this.category="Software";this.name="SMB";this.subnavigationicon="sec-nav-smb.png";var d=void 0,p=!1;this.Init=function(){d=this;if(void 0==d||null==d)return!1;d.setCycleTime(2E3);d.setCommunicationObj(g.DevMan.getCommunicationModule(g.DevMan.CommunicationType.mdp));d.addParameter("SMB_Property_Share_Names_Len",!0);d.addParameter("SMB_Property_Path_Names_Len",!0);d.addParameter("SMB_Property_Userlist_Len",!0);d.addParameter("SMB_Property_Access_Rights_Len",
!0);d.addParameter("Management_Username_Property_Len",!1);d.setOnInitStaticPage(q);d.setOnDisplayValues(r);d.setOnServiceTransferFailed(t);d.setOnServiceTransferResult(u);return!0};var q=function(b){var a;a="<h3>Shared Folders SMB</h3><h4>Shares</h4>";a+='<div id="smb_shares"></div>';a+="<br>";a+="<h4>Access Rights</h4>";a+='<div id="smb_accessrights"></div>';a+="<br>";if(b[0].getHasValues()&&b[4].getHasValues()){a+='<table style="margin-bottom: 5px"><tr>';a+=' <td class="td_trans"><h4>Set User Access Rights</h4></td>';
a+=' <td class="td_Action_trans">'+(new ControlLib.SmallButton).Create("btnSetUserAccessRights","save","Set Access Rights")+(new ControlLib.SmallButton).Create("btnSetUserAccessRights_cancel","delete");a+="</tr></table>";a+="<table>";a+='<tr><td class="td_FirstColumn">Share Name</td><td><div id="cmbShareNameDiv"</div></td></tr>';var c=[];c.push("");for(var e=0;e<b[4].values[0].length;e++)0==b[4].values[0][e].error&&c.push(b[4].values[0][e].data);c.push("Other");a+='<tr><td class="td_FirstColumn">User Name</td><td>'+
(new ControlLib.Combobox).CreateMap("cmbUserName",c,c)+"</td></tr>";a+='<tr><td class="td_FirstColumn">User Name (other)</td><td>'+(new ControlLib.Textbox).Create("txtUserNameEx")+"</td></tr>";c=[];c.push("");e=[];e.push("");winxp&&(c.push("Read"),e.push(10),c.push("Change"),e.push(20));c.push("Full Access");e.push(-1);c.push("Delete User");e.push(0);a+='<tr><td class="td_FirstColumn">Access Rights</td><td>'+(new ControlLib.Combobox).CreateMap("cmbAccessRights",c,e)+"</td></tr>";a+="</table>";a+=
"<br>"}a+='<table style="margin-bottom: 5px"><tr>';a+=' <td class="td_trans"><h4>Add Share</h4></td>';a+=' <td class="td_Action_trans">'+(new ControlLib.SmallButton).Create("btnAddShare","save","Add Share");a+="</tr></table>";a+="<table>";a+=' <tr><td class="td_FirstColumn">Share-Name</td><td>'+(new ControlLib.Textbox).Create("txtShareName")+"</td></tr>";a+=' <tr><td class="td_FirstColumn">Path to folder</td><td>'+(new ControlLib.Textbox).Create("txtSharePath","99%")+"</td></tr>";a+=' <tr><td class="td_FirstColumn"></td> <td><div id="divSelectDirectory"></div></td></tr>';
a+="</table>";a+="<br>";a+='<div id="status"></div>';d.writeActivePage(a);b[0].getHasValues()&&b[4].getHasValues()&&(d.setElementOnChange("cmbUserName",function(a){return function(){k(a)}}(0)),d.setElementOnClick("btnSetUserAccessRights",function(a){return function(){var b=d.getElementValue("cmbShareName"),c=d.getElementValue("cmbUserName");"Other"==c&&(c=d.getElementValue("txtUserNameEx"));var e=d.getElementValue("cmbAccessRights");if(0<b.length&&0<c.length&&""!=e){var f=[];f.push(b.length);f.push(c.length);
f.push(e);f.push(b);f.push(c);d.executeCommand("SMB_Function_SetUserAccessRights",a,f);Helper.ShowLoading()}else g.DevMan.getErrorQueue().AddError(2147811377)}}(0)),d.setElementOnClick("btnSetUserAccessRights_cancel",function(a){return function(){l(a)}}(0)),d.setElementDisabled("txtUserNameEx",!0));b="\\";winxp&&(b="C:\\");m(b,!1);d.setElementOnClick("btnAddShare",function(a){return function(){var b=d.getElementValue("txtShareName"),c=d.getElementValue("txtSharePath");Helper.StringEndsWith(c,"\\")&&
(c=c.substr(0,c.length-1));var e=d.getCommunicationObj().getServiceTransferParameterSize("SMB_Function_Add_Share")+b.length+c.length,f=[];f.push(e);f.push(b.length);f.push(c.length);f.push(b);f.push(c);d.executeCommand("SMB_Function_Add_Share",a,f);Helper.ShowLoading()}}(0));d.setElementOnKeyUp("txtSharePath",function(){if(13===event.keyCode){var a=d.getElementValue("txtSharePath"),a=a.replace(/\//g,"\\");m(a,!0)}});return!0},r=function(b){if(b[0].getHasValues()||b[1].getHasValues()){var a;a="<table><tr><th>Name</th><th>Path</th><th></th></tr>";
var c=0;b[0].getHasValues()&&(c=b[0].values[0].length);var e=0;b[1].getHasValues()&&(e=b[1].values[0].length);e=Math.max(c,e);for(c=0;c<e;c++){a+="<tr>";try{a+='<td class="td_FirstColumn"><div id="'+b[0].parameterName+c+'">'+b[0].values[0][c].getOutput()+"</div></td>"}catch(g){a+="<td></td>"}try{a+='<td><div id="'+b[1].parameterName+c+'">'+b[1].values[0][c].getOutput()+"</div></td>"}catch(l){a+="<td></td>"}try{a+='<td><div align="right" id="">'+(new ControlLib.SmallButton).Create("btnDeleteShare"+
c,"delete","")+"</div></td>"}catch(m){a+="<td></td>"}a+="</tr>"}a+="</table>";d.writeElement("smb_shares",a);for(c=0;c<e;c++)try{d.setElementOnClick("btnDeleteShare"+c,function(a){return function(){var b=d.getRequestParamIDs(),b=d.readElement(b[0].parameterName+a);if(confirm("Do you really want to delete the share "+b+"?")){var c=[];c.push(b.length);c.push(b);d.executeCommand("SMB_Function_Del_Share",0,c);Helper.ShowLoading()}}}(c))}catch(p){}}else d.writeElement("smb_shares","No items available");
if(b[0].getHasValues&&!d.isLocked("cmbShareName")){a="";a=[];a.push("");for(c=0;c<b[0].values[0].length;c++)0==b[0].values[0][c].error&&a.push(b[0].values[0][c].data);a=(new ControlLib.Combobox).CreateMap("cmbShareName",a,a);d.writeElement("cmbShareNameDiv",a);d.addLockListener("cmbShareName")}if(b[0].getHasValues()||b[2].getHasValues()||b[3].getHasValues()){a="<table>";a+="<tr><th>Name</th><th>Userlist</th><th>Access Rights</th></tr>";c=0;b[0].getHasValues()&&(c=b[0].values[0].length);e=0;b[2].getHasValues()&&
(e=b[2].values[0].length);var f=0;b[3].getHasValues()&&(f=b[3].values[0].length);e=Math.max(c,e,f);for(c=0;c<e;c++){a+="<tr>";try{a+='<td class="td_FirstColumn"><div id="'+b[0].parameterName+c+'">'+b[0].values[0][c].getOutput()+"</div></td>"}catch(q){a+="<td></td>"}try{if(0==b[2].values[0][c].error){var k=b[2].values[0][c].data.split(";");a+='<td><div id="'+b[2].parameterName+c+'">';for(var h=0;h<k.length;h++)a+=h+1+": "+k[h]+"<br>";a+="</div></td>"}else a+="<td>-</td>"}catch(s){a+="<td>-</td>"}try{if(0==
b[3].values[0][c].error){var n=b[3].values[0][c].data;a+='<td><div id="'+b[3].parameterName+c+'">';for(f=h=0;h<n.length;h+=4,f++){var r=Helper.parseAccessRights(n.substr(h,4));a+=f+1+": "+r+"<br>"}a+="</div></td>"}else a+="<td>-</td>"}catch(t){a+="<td>-</td>"}a+="</tr>"}d.writeElement("smb_accessrights",a)}},t=function(b){Helper.HideLoading();g.DevMan.getErrorQueue().AddError(b.requestStatus,b.requestStatusText)},u=function(b){Helper.HideLoading();"FSO_Function_Dir"==b.moduleItem.name?(b.hasError?
(b=CommunicationModule_ERROR.ErrorCodeToErrorMessage(b.errCode),0==b.length&&(b="Unknown error!"),v(b)):(b=Helper.parseDirs(b.result),w(b)),d.setElementValue("txtSharePath",RootDir),p&&(d.scrollToElement("txtSharePath"),p=!1)):b.hasError?(32768==b.errCode>>>16&&(b.errCode=3970367488+(b.errCode&65535)),g.DevMan.getErrorQueue().AddError(b.errCode)):"SMB_Function_Add_Share"==b.moduleItem.name?(d.setElementValue("txtShareName",""),l(0)):"SMB_Function_Del_Share"==b.moduleItem.name?l(0):"SMB_Function_SetUserAccessRights"==
b.moduleItem.name&&l(0)},m=function(b,a){Helper.StringEndsWith(b,"\\")||(b+="\\");b+="*";var c=[];c.push(b.length);c.push(b);RootDir=b.substr(0,b.length-1);p=a;d.executeCommand("FSO_Function_Dir",0,c);d.showLoading("divSelectDirectory")},l=function(b){d.removeLock("cmbShareName");d.setElementValue("cmbShareName","");d.setElementValue("cmbUserName","");d.setElementValue("cmbAccessRights","");k()},w=function(b){var a="";s(RootDir)||b.splice(0,0,"..");for(var c=0;c<b.length;c++){var e="res/website/other/dir.png";
".."==b[c]&&(e="res/website/other/dir_back.png");a+=(new ControlLib.SMBFolder).Create("dir_"+b[c],b[c],"#",e)}d.writeElement("divSelectDirectory",a);for(c=0;c<b.length;c++)d.setElementOnClick("dir_"+b[c],function(a){return function(){n(a)}}(b[c]))},v=function(b){var a="";s(RootDir)||(a="..");var c="";0<a.length&&(c+=(new ControlLib.SMBFolder).Create("dir_"+a,a,"#","res/website/other/dir_back.png"));d.writeElement("divSelectDirectory",c+(b+"<br>"));0<a.length&&d.setElementOnClick("dir_"+a,function(a){return function(){n(a)}}(a))},
s=function(b){return 3<b.length?!1:3!=b.length||":"!=b.charAt(1)||"\\"!=b.charAt(2)&&"/"!=b.charAt(2)?2==b.length&&":"==b.charAt(1)?!0:!1:!0},n=function(b){if(".."==b){var a=b=RootDir;Helper.StringEndsWith(b,"\\")&&(b=b.substr(0,b.length-1));var c=b.lastIndexOf("\\");b=-1<c?b.substr(0,c):a;m(b,!0)}else m(RootDir+b,!0)},k=function(){var b="Other"==d.getElementValue("cmbUserName");d.setElementDisabled("txtUserNameEx",!b);b||d.setElementValue("txtUserNameEx","")}};this.SMB.prototype=new g.Page_Template.Template};
g.DevMan.RegisterModule(new q.SMB,g.DevMan.ModuleType.Website)})(window);
