{% extends "data_opform.html" %} {% load i18n %} {% block headajaxjs %} {% endblock %} {% block form %} {% endblock %} {% block help_panel %} {% endblock %} {% block operation_panel %} {% if request.user|HasPerm:"iclock.opsearchacpanel_device" %}

{% trans "搜索以太网中的门禁控制器" %}

{% trans "搜索中..." %}

{% trans "搜索结果" %}

{% endif %} {% endblock %} {% block loading %} {% endblock %} {% block addjs %} {% if request.user|HasPerm:"iclock.opsearchacpanel_device" %} var searching = false;//当前处于未搜索状态 var device_added_count = 0;//当前搜索出来的设备已添加的数量。 $("#id_searching").hide(); var after_init = function() { $("#OK").parent().hide(); $("#Cancel").text(gettext("退出")) $("#searching").hide(); $("#searched").hide(); $("#total_tip").hide(); $("#id_showTbl").hide(); after_init = undefined; } var after_cancel = function() { $("#id_datalist").get(0).g.load_data(); after_cancel = undefined;//加载数据后取消,避免新增设备时放弃也会刷新列表 } $("#id_start_search").click(function(){ //判断当前是否正在搜索 if(searching == true) { alert(gettext("正在搜索中,请等待!")); return false; } searching=true; device_added_count = 0;//如果不为零,重新置为0,(不刷新界面反复搜索时有用) var type = $("#search_type").val(); $("#id_showTbl thead").remove(); $("#id_showTbl tbody").remove(); $("#searched").hide(); $($("#total_tip h2")[1]).empty(); $("#total_tip").hide(); $("#search_type").attr("disabled", true); $("#id_searching").show(); get_all_ip_sn();//重新获取ip/sn search_tcpip(); }); var ips_existed = new Array();//全局变量,存放所有ip地址 var sns_existed = new Array();// function get_all_ip_sn() { //获取数据库中所有的IP地址、sn,避免用户修改ip地址时写入数据库中已有的ip地址(包含考勤和门禁 var stamp = new Date().getTime(); $.ajax({ type: "POST", url: "/{{ request.surl }}iaccess/GetData/?func=get_all_ip_sn&stamp="+ stamp, dataType: "json", async: false, success: function(data) { ips_existed = data.ipaddress; sns_existed = data.sn; }, error: function(XMLHttpRequest, textStatus, errorThrown) { //alert(textStatus+" "+errorThrown); alert(gettext("服务器处理数据失败,请重试!错误码:-612")); } }); } //将ip地址转换成字符串,字段不足三位的补零 function getValue(value){ value = value.split("");//全部分割--解决ie下排序不起作用bug var ip_tostring = new Array(3); for(var j=0;j<3;j++) { if(value[j] == undefined) { ip_tostring[2] = ip_tostring[1]; ip_tostring[1] = ip_tostring[0]; ip_tostring[0] = "0"; } else { ip_tostring[j] = value[j]; } } return ip_tostring.join(""); } //根据IP地址对搜索出来的设备进行排序 function sort(datas){ var list=new Array(); for(var i=0;i{% trans "IP地址" %}{% trans "MAC地址" %}{% trans "子网掩码" %}{% trans "网关" %}{% trans "序列号" %}{% trans "设备类型" %}{% trans "操作" %}'); var ip_addr = ""; datas=sort(datas); for(var index=0,j=datas.length;index'+datas[index]["IP"]+''+datas[index]["MAC"]+''+datas[index]["NetMask"]+''+datas[index]["GATEIPAddress"]+''+datas[index]["SN"]+''+datas[index]["Device"]+'{% trans "该设备已添加" %}'); i++; break; } } if(i == 0) { if(datas[index]["NetMask"] == undefined) { datas[index]["NetMask"] = ''; } if(datas[index]["GATEIPAddress"] == undefined) { datas[index]["GATEIPAddress"] = ''; } $("#id_showTbl table").append(''+datas[index]["IP"]+''+datas[index]["MAC"]+''+datas[index]["NetMask"]+''+datas[index]["GATEIPAddress"]+''+datas[index]["SN"]+''+datas[index]["Device"]+'{% trans "修改IP地址" %}{% trans "添加设备" %}'); } ips_existed.push(datas[index]["IP"]);//获取当前广播搜索到的IP地址 } //将设备添加至数据库 $("a[id^='add_device']").each(function(){ $(this).click(function(){ var ip = $($(this).parent().parent().find("td")[0]).text(); var subnet_mask = $($(this).parent().parent().find("td")[2]).text(); var gateway = $($(this).parent().parent().find("td")[3]).text(); var sn = $($(this).parent().parent().find("td")[4]).text(); var alias = ""; var whether_sync_all = null;//新增设备时是否需要同步所有数据 var comm_pwd = null; var $tr = $(this).parent().parent(); ip_network_segment = ip.split(".")[2]; // for(var i=0;i'+gettext("自定义设备名称")+'' +'' +'' +'' +'' +'
'+'
'+'
'+''; $(modify_alias_form).dialog(); $("#id_alias_form").find("#id_Cancel").click(function(){ $("#id_close").click(); }); $("#id_alias_form").find("#id_OK").click(function(){ alias = $("#id_alias").val(); whether_sync_all = $("#id_whether_sync_all").attr("checked"); comm_pwd = $("#id_new_commpwd").val(); if(whether_sync_all) { sync_tips = gettext("您选择了[新增时删除设备中数据],系统将自动删除设备中的数据(事件记录除外),确定要继续?"); } else { sync_tips = gettext("您没有选择[新增时删除设备中数据],该功能仅用于系统功能演示和测试。请及时手动同步数据到设备,以确保系统中和设备中权限一致,确定要继续?"); } if(!confirm(sync_tips)) { return false; } else { if(alias == null) { return false; } if(alias == "") { alert(gettext("设备名称不能为空,请重新添加设备!")); return false; } } //该请求将验证ip地址和sn是否存在,如果不存在的话,将会将该设备写入数据库中 var stamp = new Date().getTime(); $.ajax({ type: "POST", url: "/{{ request.surl }}iaccess/SearchACPanel/?func=check_and_save&ip="+ ip +"&subnet_mask="+ subnet_mask +"&gateway="+ gateway +"&sn="+ sn +"&stamp="+ stamp,//验证ip地址和序列号是否已经存在 dataType: "json", data:{"alias": alias, "whether_sync_all": whether_sync_all,"comm_pwd":comm_pwd}, async: true, success: function(check){ if(check.ret > 0)//1 { alert(alias +" "+gettext("的设备添加成功!")); $("#id_close").click(); $tr.remove(); device_added_count++; $($("#total_tip h2")[1]).text(gettext("已添加设备数:")+ device_added_count); } else if(check.ret == 0) { if(check.ip_existed) { alert(gettext("IP地址:")+ ip +gettext(" 已存在!")); return false; } if(check.sn_existed) { alert(gettext("序列号:")+ sn +gettext(" 已存在!")); return false; } } else if(check.ret == -1) { alert(gettext("IP地址为:")+ ip +gettext(" 的设备添加失败!原因:") + check.reason); } else if(check.ret == -5) { alert(gettext("IP地址为:")+ ip +gettext(" 的设备添加异常!")); } else if(check.ret == -2) { alert(alias +" "+gettext("的设备添加成功,但设备扩展参数获取失败!"));//设备参数将在下次连接成功时自动添加 $("#id_close").click(); $tr.remove(); device_added_count++; $($("#total_tip h2")[1]).text(gettext("已添加设备数:")+ device_added_count); } else if(check.ret == -3) { alert(gettext("设备连接成功,但无数据返回,添加设备失败!")); } else if(check.ret == -4) { if(check.reason == "") { alert(gettext("设备连接失败(错误码:")+ check.result +gettext("),无法添加该设备!")); } else { alert(gettext("设备连接失败(原因:")+ check.reason +gettext("),无法添加该设备!")); } } }, error:function (XMLHttpRequest, textStatus, errorThrown) { //alert(textStatus+" "+errorThrown); alert(gettext("服务器处理数据失败,请重试!错误码:-613")); } }); }); }); }); //修改设备的ip地址(下发命令至设备) $("a[id^='change_ip']").each(function(){ $(this).click(function(){ $ip = $($(this).parent().parent().find("td")[0]); $gateway = $($(this).parent().parent().find("td")[3]); $submask = $($(this).parent().parent().find("td")[2]); var oldip = $ip.text(); $tr = $(this).parent().parent(); var mac = $($(this).parent().parent().find("td")[1]).text(); //弹出框的形式获取新的ip地址 var pop_up_form = '
' +'

'+gettext("修改设备IP地址")+'

' +'' +'' +'' +'' +'
' +'
' +'
' +'
'; $(pop_up_form).dialog() var ipv4_ip=new IpV4Box("ipv4_ip","id_newip"); var ipv4_gateway =new IpV4Box("ipv4_gateway","id_gateway",0);//参数0表示不对第一个输入框进行1到233间的验证 var ipv4_subnet_mask=new IpV4Box("ipv4_subnet_mask","id_subnet_mask",0); ipv4_subnet_mask.setValue($submask.text()); ipv4_gateway.setValue($gateway.text()); $("#id_pop_up_form").find("#id_Cancel").click(function(){ $("#id_close").click(); }); var newip = ""; var gateway = ""; var subnet_mask = ""; //弹出框新的ip地址的提交 $("#id_pop_up_form").find("#id_OK").click(function(){ newip = ipv4_ip.getValue(); gateway = ipv4_gateway.getValue(); subnet_mask = ipv4_subnet_mask.getValue(); //$("#id_page_load").show(); if(newip == "") { alert(gettext("新的IP地址不能为空!")); return false; } var reg = /^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$/; if(newip != "" && !reg.test(newip)) { alert(gettext("请输入一个有效的IPv4地址!")); return false; } if(gateway != "" && !reg.test(gateway)) { alert(gettext("请输入一个有效的网关地址!")); return false; } if(subnet_mask != "" && !reg.test(subnet_mask)) { alert(gettext("请输入一个有效的子网掩码!")); return false; } for(var i in ips_existed) { if(ips_existed[i] == newip) { alert(gettext("该IP地址的设备已存在或该IP地址已被使用,不能添加!请重新输入!")); return false; } } //发送改变ip地址的请求 var stamp = new Date().getTime(); $.ajax({ type: "POST", url: "/{{ request.surl }}iaccess/SearchACPanel/?func=change_ip&oldip="+oldip+"&newip="+newip+"&mac="+mac+"&gateway="+gateway+"&subnet_mask="+subnet_mask+"&stamp="+stamp, dataType: "json", async: true, success: function(data){ if(data.ret >= 0) { alert(gettext("修改IP地址成功!")); //$tr.remove(); for(i in ips_existed) { if(ips_existed[i] == $ip.text()) { ips_existed.splice(i, 1) ips_existed.push(newip); break; } } $ip.text(newip); $submask.text(subnet_mask); $gateway.text(gateway); $("#id_close").click(); } else { alert(gettext("修改IP地址失败!原因:") + data.reason); } }, error:function (XMLHttpRequest, textStatus, errorThrown) { //alert(textStatus+" "+errorThrown); alert(gettext("服务器处理数据失败,请重试!错误码:-614")); } }); }); }); }); } else { $("#id_searching").hide(); alert(gettext("没有搜索到门禁控制器!")); //setTimeout('$("#Cancel").click();',5); } searching=false;//标志搜索结束 $("#search_type").attr("disabled",false); } }); } {% else %} alert(gettext("对不起,您没有访问该页面的权限,不能浏览更多信息!")); window.location.href = "/{{ request.surl }}accounts/login/"; {% endif %} {% endblock%}