define(function(require,exports,module){function e(){}var a,t,n,o,i,r,s,l;a=require("jquery"),require("ui.table"),require("config/ui.config"),t=require("translator"),n=require("common"),o=require("service"),i=require("utils"),r=require("isapi/device"),s=require("dialog"),l=require("isapi/response"),e.prototype={init:function(){this.initController()},initController:function(){angular.module("channelDigitalApp",["ui.config"]).service("service",function($compile,$timeout){var e=this;this.m_oLan=t.oLastLanguage;var d=null;this.m_oScope=null,this.m_oCapbilities={bSupportStreamType:r.m_oDeviceCapa.bSupportIpcStreamType,aProtocolOptions:[],iMaxIpcNum:32,bSupportCustom:!1,aCustomOptions:[],aStep:[e.m_oLan.mainStream,e.m_oLan.subStream],bSupportActiveIPC:!1,bSupportCheckRisk:!1},this.m_oAddParams={szIpAddress:"",szDeviceId:"",oProtocol:{},szManagePort:"",szDeviceChannelNo:"",szUserName:"",oPassword:{},szStreamType:"",szConnMode:"",iChannelNum:1,aChannelList:[],bCheckDvsAll:!1,iType:0,szProtocolName:"",bCustom:!1},this.m_oStreamParams=[],this.m_oParamsIpcValid={oIpAddress:{oMaxLength:{value:48,error:t.getValue("noMoreLength",[48])},oEmpty:{value:!1,error:e.m_oLan.nullTips},bSkipValid:!1},oDeviceId:{oMaxLength:{value:20,error:t.getValue("noMoreLength",[20])},oEmpty:{value:!1,error:e.m_oLan.nullTips},bSkipValid:!0},oManagePort:{oMinValue:{value:0,error:t.getValue("range",[0,65535])},oMaxValue:{value:65535,error:t.getValue("range",[0,65535])},oEmpty:{value:!1,error:e.m_oLan.nullTips},bSkipValid:!1},oDeviceChannelNo:{oMinValue:{value:1,error:t.getValue("range",[1,16])},oMaxValue:{value:16,error:t.getValue("range",[1,16])},oEmpty:{value:!1,error:e.m_oLan.nullTips},bSkipValid:!1},oUserName:{oMaxLength:{value:32,error:t.getValue("noMoreLength",[32])},oEmpty:{value:!1,error:e.m_oLan.nullTips},bSkipValid:!1}},this.m_oParamsCustomValid={oProtocolName:{oMaxLength:{value:16,error:t.getValue("noMoreLength",[16])},oEmpty:{value:!1,error:e.m_oLan.nullTips},oSpecChar:{value:!1,error:t.getValue("notChar")+" / \\ : * ? ' \" < > | % "},bSkipValid:!1},oPort:{oMinValue:{value:1,error:t.getValue("range",[1,65535])},oMaxValue:{value:65535,error:t.getValue("range",[1,65535])},oEmpty:{value:!1,error:e.m_oLan.nullTips},bSkipValid:!1},oStreamPath:{oMaxLength:{value:256,error:t.getValue("noMoreLength",[256])},bSkipValid:!1}},this.m_iSelectTable=0;var m=null,c=null,u=[],p=[],f=null,h=[],g=0,v={ipcNotActivated:"waitActive",risk:"riskPwd",weak:"weakPwd",medium:"normalPwd",strong:"goodPwd"};this.initChannelDigital=function(){e.getActiveCap(),e.initCustomParams(),e.isSupportCustom(),e.getDigitalChannelMax(),e.getIPCFarctor(),e.getChannelDigitalInfo()},this.getDigitalChannelMax=function(){WebSDK.WSDK_GetDeviceConfig(n.m_szHostName,"DigitalChannelInfo",null,{async:!1,success:function(t,n){e.m_oCapbilities.iMaxIpcNum=parseInt(a(n).find("InputProxyChannelList").eq(0).attr("size"),10)}})},this.getIPCFarctor=function(){WebSDK.WSDK_GetDeviceConfig(n.m_szHostName,"sourceSupport",null,{async:!1,success:function(t,n){a(n).find("MediaDeviceSource").each(function(){var t={name:i.nodeValue(a(this),"MediaDeviceMfgr"),type:i.nodeValue(a(this),"MediaDeviceModel")};e.m_oCapbilities.aProtocolOptions.push(t)})}})},this.getChannelDigitalInfo=function(){WebSDK.WSDK_GetDeviceConfig(n.m_szHostName,"DigitalChannelStatus",null,{async:!1,success:function(n,r){u.length=0,a(r).find("InputProxyChannelStatus").each(function(n){u[n]=[];var r=parseInt(i.nodeValue(a(this),"id"),10)-o.m_iAnalogChNum;u[n][0]=10>r?"D0"+r:"D"+r,u[n][1]="ipaddress"===i.nodeValue(a(this),"addressingFormatType")?a(this).find("ipAddress").length>0?i.nodeValue(a(this),"ipAddress"):i.nodeValue(a(this),"ipv6Address"):i.nodeValue(a(this),"hostName"),u[n][2]=i.nodeValue(a(this),"srcInputPort"),u[n][3]=i.nodeValue(a(this),"managePortNo");var s=i.nodeValue(a(this),"SecurityStatus PasswordStatus");u[n][4]=s?"invalid"===s?"N/A":t.getValue(v[s]):"-",u[n][5]="true"===i.nodeValue(a(this),"online")?"true":i.nodeValue(a(this),"chanDetectResult"),u[n][6]=i.nodeValue(a(this),"proxyProtocol"),u[n][7]=$compile(""+i.nodeValue(a(this),"url")+"")(e.m_oScope),u[n][8]=i.nodeValue(a(this),"streamType"),u[n][9]=i.nodeValue(a(this),"userName"),u[n][10]=i.nodeValue(a(this),"connMode"),"GB28181"===i.nodeValue(a(this),"proxyProtocol")&&(u[n][1]=u[n][1]?i.nodeValue(a(this),"deviceID")+"("+u[n][1]+")":i.nodeValue(a(this),"deviceID"))}),e.initTable()}})},this.getActiveCap=function(){WebSDK.WSDK_GetDeviceConfig(n.m_szHostName,"imgTypeCapa",null,{async:!1,success:function(a,t){e.m_oCapbilities.bSupportActiveIPC=i.nodeValue(t,"isSupportActivateIpc","b"),e.m_oCapbilities.bSupportCheckRisk=i.nodeValue(t,"isSupportCheckPassword","b")}})},this.initTable=function(){e.m_iSelectTable=-1,e.m_oScope.iSelectTable=-1,e.m_oScope.iCheckNum=0,m=a("#tableDigitalChannels").table({header:[{display:e.m_oLan.channelNo,width:"80",type:""},{display:e.m_oLan.ipAddr,width:"100",type:""},{display:e.m_oLan.deviceChanNo,width:"80",type:""},{display:e.m_oLan.managementPort,width:"100",type:""},{display:e.m_oLan.securityStat,width:"100",type:"",hide:!e.m_oCapbilities.bSupportCheckRisk},{display:e.m_oLan.state,width:"108",type:{"true":e.m_oLan.onLine,overSysBandwidth:e.m_oLan.offLine+"("+e.m_oLan.overSysBandwidth+")",domainError:e.m_oLan.offLine+"("+e.m_oLan.domainError+")",ipcStreamFail:e.m_oLan.offLine+"("+e.m_oLan.ipcStreamFail+")",connecting:e.m_oLan.offLine+"("+e.m_oLan.connecting+")",chanNoError:e.m_oLan.offLine+"("+e.m_oLan.channelNoError+")",ipAddrConflictWithDev:e.m_oLan.offLine+"("+e.m_oLan.ipAddrConflictWithDev+")",ipAddrConflicWithIpc:e.m_oLan.offLine+"("+e.m_oLan.ipAddrConflicWithIpc+")",errorUserNameOrPasswd:e.m_oLan.offLine+"("+e.m_oLan.userPwdError+")",netUnreachable:e.m_oLan.offLine+"("+e.m_oLan.ipcNetworkAbnormal+")",unknownError:e.m_oLan.offLine+"("+e.m_oLan.paramError+")",notExist:e.m_oLan.offLine+"("+e.m_oLan.ipcNotExist+")",ipcStreamTypeNotSupport:e.m_oLan.offLine+"("+e.m_oLan.ipcStreamTypeNotSupport+")",ipcResolutionNotSupport:e.m_oLan.offLine+"("+e.m_oLan.resolutionNotSupported+")",badLanguage:e.m_oLan.offLine+"("+e.m_oLan.lanMismatch+")",ipcNotActivated:e.m_oLan.offLine+"("+e.m_oLan.waitActive+")",ipcUnregistered:e.m_oLan.offLine+"("+e.m_oLan.ipcUnregistered+")",userLocked:e.m_oLan.offLine+"("+e.m_oLan.userLocked+")",userNotExist:e.m_oLan.offLine+"("+e.m_oLan.userNotExist+")",poePortDetecting:e.m_oLan.offLine+"("+e.m_oLan.ipcDetecting+")","":e.m_oLan.offLine},disabled:!0},{display:e.m_oLan.protocol,width:"80",type:""},{display:e.m_oLan.connect,width:"60",type:""},{type:"data"},{type:"data"},{type:"data"},{type:"data"}],showCheckbox:!0,onSelect:function(a){e.m_iSelectTable=a,e.m_oScope.iSelectTable=a,e.m_oScope.$digest()},onChecked:function(a){if(e.m_oScope.iCheckNum=a,a>0)for(var t=m.getCheckedRows(),n=0;t.length>n;n++)e.m_oScope.bDeleteIPC=""!==t[n].data[10]?!1:!0;else e.m_oScope.bDeleteIPC=!1;e.m_oScope.$digest()}}),e.updateTable()},this.updateTable=function(){m.deleteRows(),m.addRows(u);for(var e=0;u.length>e;e++)"plugplay"===u[e][10]&&m.disableRow(e)},this.createXmlDoc=function(a,t){if(1===a)var n=parseInt(u[e.m_iSelectTable][0].split("D")[1],10)+o.m_iAnalogChNum,r=""+n+"";else if(0===a)var r="0false";else var r="";r+=2!==a?"":"",r+=2!==a?""+e.m_oAddParams.oProtocol.name+"":""+e.m_oAddParams.oProtocol.name+"";var s=i.checkAddressingType(e.m_oAddParams.szIpAddress).toLowerCase();r+=""+("hostname"===s?"hostname":"ipaddress")+"",r+="hostname"===s?""+e.m_oAddParams.szIpAddress+"":"ipv6address"===s?""+e.m_oAddParams.szIpAddress+"":""+e.m_oAddParams.szIpAddress+"",2!==a?(r+=""+e.m_oAddParams.szManagePort+"",r+=void 0!==t?""+t+"":""+e.m_oAddParams.szDeviceChannelNo+""):r+=""+e.m_oAddParams.szManagePort+"",r+=""+e.m_oAddParams.szUserName+"",1===a?e.m_oAddParams.oPassword.szPassword!==e.m_oAddParams.oPassword.szPasswordDefault&&(r+=""+e.m_oAddParams.oPassword.szPassword+""):r+=""+e.m_oAddParams.oPassword.szPassword+"",e.m_oCapbilities.bSupportStreamType&&(r+=""+e.m_oAddParams.szStreamType+""),1===a&&""!==u[e.m_iSelectTable][10]&&(r+=""+e.m_oAddParams.szConnMode+""),"GB28181"===e.m_oAddParams.oProtocol.name&&(r+=""+e.m_oAddParams.szDeviceId.replace(/"),2!==a?(r+="",r+=""):r+="";var l=i.parseXmlFromStr(r);return l},this.skipValidParams=function(a){"modify"===a||"add"===a?(e.m_oParamsCustomValid.oProtocolName.bSkipValid=!0,e.m_oParamsCustomValid.oPort.bSkipValid=!0,e.m_oParamsCustomValid.oStreamPath.bSkipValid=!0,e.m_oParamsIpcValid.oIpAddress.bSkipValid=!1,e.m_oParamsIpcValid.oManagePort.bSkipValid=!1,e.m_oParamsIpcValid.oUserName.bSkipValid=!1,e.m_oParamsIpcValid.oDeviceChannelNo.bSkipValid="add"===a?!0:!1):"custom"===a&&(e.m_oParamsIpcValid.oIpAddress.bSkipValid=!0,e.m_oParamsIpcValid.oManagePort.bSkipValid=!0,e.m_oParamsIpcValid.oDeviceChannelNo.bSkipValid=!0,e.m_oParamsIpcValid.oUserName.bSkipValid=!0,e.m_oParamsCustomValid.oProtocolName.bSkipValid=!1,e.m_oParamsCustomValid.oPort.bSkipValid=!1,e.m_oParamsCustomValid.oStreamPath.bSkipValid=!1)},this.submitIpcReq=function(a,t){if(0===a){var i=m.getAllRows();if(e.m_oAddParams.bCustom){for(var r=0;i.length>r;r++)if(i[r].data[1]===e.m_oAddParams.szIpAddress&&i[r].data[6]===e.m_oAddParams.oProtocol.name)return s.tip(e.m_oLan.ipChanExistTips),d&&d.close(),!1}else for(var r=0;i.length>r;r++)if(i[r].data[1]===e.m_oAddParams.szIpAddress&&i[r].data[2]===(t?""+t:e.m_oAddParams.szDeviceChannelNo)&&i[r].data[3]===e.m_oAddParams.szManagePort)return s.tip(e.m_oLan.ipChanExistTips),d&&d.close(),!1;var c=e.createXmlDoc(0,t);WebSDK.WSDK_SetDeviceConfig(n.m_szHostName,"addIpc",null,{processData:!1,data:c,async:!0,success:function(a,t,n){e.m_oCapbilities.iMaxIpcNum--,e.m_oScope.$apply(),h.length>0?(g++,g===h.length?(d.close(),l.saveState(n),e.getChannelDigitalInfo()):e.submitIpcReq(0,h[g])):(l.saveState(n),e.getChannelDigitalInfo())},error:function(e,a,t){l.saveState(t),d&&d.close()}})}else{var c=e.createXmlDoc(1),p=parseInt(u[e.m_iSelectTable][0].split("D")[1],10)+o.m_iAnalogChNum;WebSDK.WSDK_SetDeviceConfig(n.m_szHostName,"modifyIpc",{channel:p},{processData:!1,data:c,success:function(a,t,n){u[e.m_iSelectTable][1]=e.m_oAddParams.szIpAddress,u[e.m_iSelectTable][2]=e.m_oAddParams.szDeviceChannelNo,u[e.m_iSelectTable][3]=e.m_oAddParams.szManagePort,u[e.m_iSelectTable][6]=e.m_oAddParams.oProtocol.name,u[e.m_iSelectTable][8]=e.m_oAddParams.szStreamType,u[e.m_iSelectTable][9]=e.m_oAddParams.szUserName,u[e.m_iSelectTable][10]=e.m_oAddParams.szConnMode,l.saveState(n),e.updateTable()},error:function(e,a,t){l.saveState(t)}})}},this.addModifyIpc=function(t){if(e.m_oAddParams.iChannelNum=1,0===t)e.m_oScope.bHideDefault=!0,e.m_oAddParams.szIpAddress="",e.m_oAddParams.oProtocol=e.m_oCapbilities.aProtocolOptions[0],e.m_oAddParams.szUserName="admin",e.m_oAddParams.szManagePort="8000",e.m_oAddParams.szStreamType="auto",e.m_oAddParams.iType=0,e.m_oAddParams.szConnMode="",e.m_oAddParams.bCustom=!1,e.skipValidParams("add");else{var o=m.getSelectedRow();if(null===o)return;for(var r=0,c=0;e.m_oCapbilities.aProtocolOptions.length>c;c++)if(o.data[6]===e.m_oCapbilities.aProtocolOptions[c].name){r=c;break}e.skipValidParams("modify"),e.m_oScope.bHideDefault=!1,e.m_oAddParams.oProtocol=e.m_oCapbilities.aProtocolOptions[r],o.data[1].indexOf("(")>-1?(e.m_oAddParams.szIpAddress=o.data[1].split("(")[1].split(")")[0],e.m_oAddParams.szDeviceId=o.data[1].split("(")[0]):"GB28181"===e.m_oAddParams.oProtocol.name?e.m_oAddParams.szDeviceId=o.data[1]:e.m_oAddParams.szIpAddress=o.data[1],e.m_oAddParams.szManagePort=o.data[3],e.m_oAddParams.szDeviceChannelNo=o.data[2],e.m_oAddParams.szStreamType=o.data[8],e.m_oAddParams.szUserName=o.data[9],e.m_oAddParams.szConnMode=o.data[10],e.m_oAddParams.iType=1,e.changeProtocol()}a.get("config/system/channelDigitalAdd.asp",function(o){s.html(e.m_oLan.digitalChannnelConfig,o,null,null,function(){if(e.m_oScope.oInputValidUtils.manualInputValid(),!e.m_oScope.oInputValid.bInputValid)return!1;if(1===e.m_oAddParams.iChannelNum){if(0===t){var o=e.createXmlDoc(2),r=!0;return WebSDK.WSDK_SetDeviceConfig(n.m_szHostName,"sourceCapability",null,{async:!1,processData:!1,data:o,success:function(n,o){if(e.m_oAddParams.iChannelNum=parseInt(i.nodeValue(a(o),"videoInputNums"),10),1===e.m_oAddParams.iChannelNum)e.submitIpcReq(t,1);else{r=!1,e.m_oAddParams.aChannelList.length=0;for(var s=0;e.m_oAddParams.iChannelNum>s;s++)e.m_oAddParams.aChannelList.push({bEnable:!1});e.m_oScope.$apply()}},error:function(a,n,o){var r=i.nodeValue(n,"subStatusCode");"badAuthorization"===r||"badLanguage"===r?l.saveState(o):e.submitIpcReq(t,1)}}),e.m_oScope.oInputValidUtils.clearInputValidList(),i.removeValidTip(),r}e.submitIpcReq(t),e.m_oScope.oInputValidUtils.clearInputValidList(),i.removeValidTip()}else{var m=0;g=0,h.length=0;for(var c=0;e.m_oAddParams.aChannelList.length>c;c++)e.m_oAddParams.aChannelList[c].bEnable&&(h[m]=c+1,m++);h.length>0&&(d=s.wait(null,e.m_oLan.adding),e.submitIpcReq(0,h[0]))}},function(){i.removeValidTip()}),$compile(angular.element("#channelDigitalAdd"))(e.m_oScope),e.m_oScope.$apply(),a("#channelDigitalAdd").hide().show()})},this.deleteIpc=function(){var a=m.getCheckedRows();d=s.wait(null,e.m_oLan.deleting),$timeout(function(){for(var t=0;a.length>t;t++)if(""===a[t].data[10]){var i=parseInt(a[t].data[0].split("D")[1],10)+o.m_iAnalogChNum;WebSDK.WSDK_SetDeviceConfig(n.m_szHostName,"deleteIpc",{channel:i},{processData:!1,async:!1,data:null,success:function(n,o,i){for(var r=0;u.length>r;r++)a[t].data[0]===u[r][0]&&u.splice(r,1);e.m_oCapbilities.iMaxIpcNum++,e.m_oScope.iSelectTable=-1,e.m_oScope.iCheckNum=0,l.saveState(i,"",1)},error:function(e,a,t){l.saveState(t,"",1)}})}e.updateTable(),d.close()},100)},this.changeProtocol=function(){var a=e.m_oAddParams.oProtocol.name,t="",n="",o=!1;switch(e.m_oParamsIpcValid.oDeviceId.bSkipValid=!0,e.m_oParamsIpcValid.oIpAddress.bSkipValid=!1,a){case"HIKVISION":t="admin",n="8000";break;case"ACTi":t="Admin",n="80";break;case"ARECONT":case"BRICKCOM":case"GRANDEYE":case"NATURE":case"ONVIF":case"PANASONIC":case"PELCO":case"PROVIDEO":case"PSIA":case"SAMSUNG":case"SANYO":case"SONY":case"XUNMEI":case"ZAVIO":case"HUNT":t="admin",n="80";break;case"GB28181":t="admin",n="5060",e.m_oParamsIpcValid.oDeviceId.bSkipValid=!1,e.m_oParamsIpcValid.oIpAddress.bSkipValid=!0;break;case"AXIS":case"CANON":case"VIVOTEK":t="root",n="80";break;case"BOSCH":t="service",n="1756";break;case"DYNACOLOR":case"GE105E":case"RTSP_URL":t="",n="0";break;case"INFINOVA":t="INFINOVA",n="80";break;default:}"Any Custom Protocol IP Camera"===e.m_oAddParams.oProtocol.type&&(n="554",o=!0),e.m_oAddParams.bCustom=o,1!==e.m_oAddParams.iType&&(e.m_oAddParams.szUserName=t,e.m_oAddParams.szManagePort=n)},this.initSadpTable=function(){c=a("#tableSadp").table({header:[{display:e.m_oLan.ipAddr,width:"80"},{display:e.m_oLan.channelNum,width:"120"},{display:e.m_oLan.protocol,width:"80"},{display:e.m_oLan.managementPort,width:"110"},{display:e.m_oLan.subNetMask,width:"110"},{display:e.m_oLan.macAddress,width:"120"},{display:e.m_oLan.serialNo,width:"120"},{display:e.m_oLan.firmware,width:"132"},{type:"data"},{type:"data"},{type:"data"}],showCheckbox:!0}),c.addRows(p)},this.sadp=function(){a.get("config/system/channelSadp.asp",function(t){s.html(e.m_oLan.quickAdd,t,null,null,function(){var a=c.getCheckedRows(),t=m.getAllRows();if(a.length>e.m_oCapbilities.iMaxIpcNum)return s.tip(e.m_oLan.channelLimit),!1;for(var n=0;a.length>n;n++){for(var o=!1,i=0;t.length>i;i++)if(a[n].data[1]===t[i].data[1]&&a[n].data[2]===t[i].data[1]&&a[n].data[3]===t[i].data[3]){o=!0;break}o||e.quickAddOne(a[n].data)}a.length>0&&e.getChannelDigitalInfo()},function(){}),e.initSadpTable(),WebSDK.WSDK_GetDeviceConfig(n.m_szHostName,"ipcSearch",null,{success:function(t,n){p.length=0,a(n).find("VideoSourceDescriptor").each(function(e){p[e]=[],p[e][0]=a(this).find("hostName").length>0?i.nodeValue(a(this),"hostName"):a(this).find("ipAddress").length>0?i.nodeValue(a(this),"ipAddress"):i.nodeValue(a(this),"ipv6Address"),p[e][1]=i.nodeValue(a(this),"srcInputPortNums"),p[e][2]=i.nodeValue(a(this),"proxyProtocol"),p[e][3]=i.nodeValue(a(this),"managePortNo"),p[e][4]=i.nodeValue(a(this),"subnetMask"),p[e][5]=i.nodeValue(a(this),"macAddress"),p[e][6]=i.nodeValue(a(this),"serialNumber"),p[e][7]=i.nodeValue(a(this),"firmwareVersion"),p[e][8]=i.nodeValue(a(this),"userName"),p[e][9]=i.nodeValue(a(this),"password"),"GB28181"===i.nodeValue(a(this),"proxyProtocol")&&(p[e][0]=p[e][0]?i.nodeValue(a(this),"deviceID")+"("+p[e][0]+")":i.nodeValue(a(this),"deviceID"))}),e.initSadpTable()}})})},this.quickAddOne=function(a){var t="0true";t+=""+a[2]+"";var o=i.checkAddressingType(a[0]).toLowerCase();if(t+=""+("hostname"===o?"hostname":"ipaddress")+"","GB28181"===a[2])if(a[0].indexOf(")")>-1)var r=a[0].split("(")[1].split(")")[0];else r="";else var r=a[0];t+="hostname"===o?""+r+"":"ipv6address"===o?""+r+"":""+r+"",t+=""+a[3]+"",t+="1",t+="admin",t+="12345","GB28181"===a[2]&&(t+=""+a[0].split("(")[0]+""),t+="";var s=i.parseXmlFromStr(t);WebSDK.WSDK_SetDeviceConfig(n.m_szHostName,"addIpc",null,{async:!1,processData:!1,data:s,success:function(a,t,n){e.m_oCapbilities.iMaxIpcNum--,e.m_oScope.$apply(),l.saveState(n)},error:function(e,a,t){l.saveState(t)}})},this.openCustom=function(){a.get("config/system/channelCustom.asp",function(t){var o={},r={},d={};a.extend(o,e.m_oAddParams),a.extend(r,e.m_oStreamParams[0]),a.extend(d,e.m_oStreamParams[1]),e.skipValidParams("custom"),s.html(e.m_oLan.customProtocol,t,null,null,function(){if(!e.m_oScope.oInputValid.bInputValid)return!1;var t=!0,o=f;return a(o).find("protocalName").eq(0).text(e.m_oAddParams.szProtocolName),a(o).find("streaming").each(function(t){a(o).find("enableStream").eq(t).text(""+e.m_oStreamParams[t].bEnableStream),a(o).find("streamProType").eq(t).text(e.m_oStreamParams[t].szStreamPro),a(o).find("streamTransMode").eq(t).text(e.m_oStreamParams[t].szStreamMode),a(o).find("streamPort").eq(t).text(e.m_oStreamParams[t].szStreamPort),a(o).find("streamPath").eq(t).text(e.m_oStreamParams[t].szStreamPath)}),WebSDK.WSDK_SetDeviceConfig(n.m_szHostName,"customProtocol",{custom:e.m_oScope.oCustomCur.value},{processData:!1,async:!1,data:o,success:function(e,a,t){l.saveState(t)},error:function(e,a,n){t=!1,l.saveState(n)}}),e.m_oScope.oInputValidUtils.clearInputValidList(),i.removeValidTip(),t},function(){a.extend(e.m_oAddParams,o),a.extend(e.m_oStreamParams[0],r),a.extend(e.m_oStreamParams[1],d),e.m_oScope.oInputValidUtils.clearInputValidList(),i.removeValidTip()}),$compile(angular.element("#channelCustom"))(e.m_oScope),e.m_oScope.$apply(),a("#channelCustom").hide().show()})},this.initCustomParams=function(){for(var a=0;16>a;a++)e.m_oCapbilities.aCustomOptions.push({name:e.m_oLan.customProtocol+" "+(a+1),value:a+1})},this.isSupportCustom=function(){WebSDK.WSDK_GetDeviceConfig(n.m_szHostName,"customProtocol",{custom:1},{async:!1,success:function(){e.m_oCapbilities.bSupportCustom=!0}})},this.getCustomCap=function(t){WebSDK.WSDK_GetDeviceConfig(n.m_szHostName,"customProtocolCap",{custom:t},{async:!1,success:function(t,n){a(n).find("streaming").each(function(t){e.m_oStreamParams.push({bSupportEnableStream:2===a(this).find("enableStream").attr("opt").split(",").length?!0:!1,aStreamProOptions:[],aStreamTransModeOptions:[],iStreamPortMin:parseInt(a(this).find("enableStream").attr("min"),10),iStreamPortMax:parseInt(a(this).find("enableStream").attr("max"),10),bEnableStream:!1,szStreamPro:"",szStreamMode:"",szStreamPort:"",szStreamPath:""}),e.m_oStreamParams[t].aStreamProOptions.length=0;for(var n=a(this).find("streamProType").eq(0).attr("opt").split(","),o=0;n.length>o;o++)e.m_oStreamParams[t].aStreamProOptions.push({name:n[o]});e.m_oStreamParams[t].aStreamTransModeOptions.length=0;for(var i=a(this).find("streamTransMode").eq(0).attr("opt").split(","),o=0;i.length>o;o++){var r=i[o];"auto"===i[o]&&(r=e.m_oLan.automatic),e.m_oStreamParams[t].aStreamTransModeOptions.push({name:r,value:i[o]})}})}})},this.getCustomCapInfo=function(t){e.getCustomCap(t),WebSDK.WSDK_GetDeviceConfig(n.m_szHostName,"customProtocol",{custom:t},{success:function(t,n){f=n,e.m_oAddParams.szProtocolName=i.nodeValue(a(n),"protocalName"),a(n).find("streaming").each(function(t){e.m_oStreamParams[t].bEnableStream=i.nodeValue(a(this),"enableStream","b"),e.m_oStreamParams[t].szStreamPro=i.nodeValue(a(this),"streamProType"),e.m_oStreamParams[t].szStreamMode=i.nodeValue(a(this),"streamTransMode"),e.m_oStreamParams[t].szStreamPort=i.nodeValue(a(this),"streamPort"),e.m_oStreamParams[t].szStreamPath=i.nodeValue(a(this),"streamPath")}),e.m_oScope.$apply()}})},this.doActive=function(){for(var a=m.getCheckedRows(),n=null,i=0,r=0;a.length>r;r++)n=a[r],i=parseInt(n.data[0].split("D")[1],10)+o.m_iAnalogChNum,n.data[4]===t.getValue(v.ipcNotActivated)&&e.activateByID(i,e.m_oScope.activeUsername,e.m_oScope.activePassword,e.m_oScope.bActiveByAdminPsw);e.getChannelDigitalInfo(),e.m_oScope.$apply()},this.activateByID=function(e,t,o,r){var s="channel";oXmlDoc=i.parseXmlFromStr(s),a(oXmlDoc).find("dynVideoInputChannelID").text(e),r?a(oXmlDoc).find("password").remove():a(oXmlDoc).find("password").text(o),a(oXmlDoc).find("userName").text(t),a(oXmlDoc).find("passwordType").text(r?"default":"selfDefine"),WebSDK.WSDK_SetDeviceConfig(n.m_szHostName,"activateIPC",null,{async:!1,data:oXmlDoc,complete:function(){}})}}).controller("channelDigitalController",function($scope,service){service.m_oScope=$scope,$scope.oLan=service.m_oLan,$scope.oAddParams=service.m_oAddParams,$scope.oCapbilities=service.m_oCapbilities,$scope.save=service.save,$scope.addModifyIpc=service.addModifyIpc,$scope.submitIpcReq=service.submitIpcReq,$scope.changeProtocol=service.changeProtocol,$scope.deleteIpc=service.deleteIpc,$scope.sadp=service.sadp,$scope.openCustom=service.openCustom,$scope.iSelectTable=-1,$scope.iCheckNum=0,$scope.iCustomTabIndex=0,$scope.bDeleteIPC=!1,$scope.oUtils=i,$scope.oParamsIpcValid=service.m_oParamsIpcValid,$scope.oParamsCustomValid=service.m_oParamsCustomValid,$scope.oInputValid={},$scope.aInputValidList=[],$scope.oInputValidUtils={},$scope.bActiveByAdminPsw=!1,$scope.activeUsername="admin",$scope.activePassword="",$scope.activePasswordConfirm="",$scope.activePasswordStatus=!0,$scope.$watch("oAddParams.aChannelList",function(){if(0!==$scope.oAddParams.aChannelList.length){for(var e=0;$scope.oAddParams.aChannelList.length>e&&$scope.oAddParams.aChannelList[e].bEnable;e++);$scope.oAddParams.bCheckDvsAll=e===$scope.oAddParams.aChannelList.length?!0:!1}},!0),$scope.checkDvsAll=function(){for(var e=0;$scope.oAddParams.aChannelList.length>e;e++)$scope.oAddParams.aChannelList[e].bEnable=$scope.oAddParams.bCheckDvsAll},service.initChannelDigital(),$scope.oCustomCur=service.m_oCapbilities.aCustomOptions[0],$scope.$watch("oCustomCur",function(){service.getCustomCapInfo($scope.oCustomCur.value),$scope.oStreamParams=service.m_oStreamParams[$scope.iCustomTabIndex]}),$scope.changeStream=function(e){$scope.oInputValid.bInputValid&&($scope.iCustomTabIndex=e,$scope.oStreamParams=service.m_oStreamParams[e])},$scope.activateIPC=function(){$scope.bActiveByAdminPsw=!1,$scope.activePassword="",$scope.activePasswordConfirm="",$scope.activePasswordStatus=!1,s.html({szTitle:t.getValue("activeDevice"),szContent:a("#active").get(0),nWidth:300,cbOk:function(){return $scope.doActive()},oButtons:{bOK:!0,bCancel:!0,bClose:!0}}),setTimeout(function(){a("#activePassword").focus()},10)},$scope.doActive=function(){return $scope.bActiveByAdminPsw||$scope.activePassword===$scope.activePasswordConfirm?$scope.bActiveByAdminPsw||$scope.activePasswordStatus?(service.doActive(),!0):!1:(s.alert(t.getValue("passNotMatch")),!1)},$scope.$watch("activePassword",function(e){$scope.activePasswordStatus=$scope.bActiveByAdminPsw||i.checkPasswordComplexity(e,$scope.activeUsername)?!0:!1})}),angular.bootstrap(angular.element("#channelDigital"),["channelDigitalApp"])}},module.exports=new e});