blob: 6610c684ad84bb2fb3e56152726d54c1d5550ecc [file] [log] [blame]
(function($) {
$.fn.objWifiPortTrigger = function() {
this.onLoad = function(flag) {
if(flag) {
LoadWebPage("//192.168.1.1/html/wifi/wifiPortTrigger.html");
$("#lt_portTrigger_btnAdd").click(function() {
AddPortTriggerEntry();
});
$("#lt_portTrigger_btnDelete").click(function() {
DelPortTriggerEntry();
});
} //end flag
GetFWPortTriggerInfo();
}
function DelPortTriggerEntry() {
var entryIdxList = "";
$("tbody tr td :checked").each(function() {
var entryIdx = $(this).parents("tr").prevAll("tr").length + 1;
entryIdxList = entryIdxList + entryIdx + ",";
});
if(""==entryIdxList) {
return;
}
var entryMap = new Map();
entryMap.put("RGW/firewall/del_port_trigger_index",entryIdxList);
var retXml = PostXml("firewall","delete_port_trigger_entry",entryMap);
if("OK" == $(retXml).find("setting_response").text()) {
GetFWPortTriggerInfo();
} else {
alert("delete port map entry failed.");
}
}
function AddPortTriggerEntry() {
ShowDlg("divPortTriggerSetDlg",300,100);
$("#lt_btnSave").click(function() {
if(!IsPort(GetPortFromElement("txtOutPort")) || !IsPort(GetPortFromElement("txtInPort"))) {
$("#lPortTriggerSetError").show();
$("#lPortTriggerSetError").text(jQuery.i18n.prop("lt_PortFormatError"));
return;
}
if(!IsRuleName( $("#txtPortTriggerRule").val())) {
$("#lPortTriggerSetError").show();
$("#lPortTriggerSetError").text(jQuery.i18n.prop("lt_RuleNameError"));
return;
}
var entryId = $("tbody tr").size() + 1;
var preTag = "RGW/firewall/port_trigger/entry_list/entry_" + entryId;
var entryMap = new Map();
entryMap.put(preTag+"/rule_name", $("#txtPortTriggerRule").val());
entryMap.put(preTag+"/out_port",GetPortFromElement("txtOutPort"));
entryMap.put(preTag+"/in_port",GetPortFromElement("txtInPort"));
entryMap.put(preTag+"/out_proto", $("#selPortTriggerOutProtocol").val());
entryMap.put(preTag+"/in_proto", $("#selPortTriggerInProtocol").val());
entryMap.put(preTag+"/enabled", $("#selPortTriggerStatus").val());
CloseDlg();
var retXml = PostXml("firewall","add_port_trigger_entry",entryMap);
if("OK" == $(retXml).find("setting_response").text()) {
GetFWPortTriggerInfo();
} else {
alert("edit port mapping entry failed.");
}
});
}
function GetFWPortTriggerInfo() {
$("#tbodyPortTrigger").empty();
$("#DeleteAllIpEntry").attr("checked",false);
$("#lt_portTrigger_btnDelete").hide();
var retXml = PostXml("firewall","fw_get_port_trigger_info");
var bFoundEntry = true;
var idx = 1;
while(bFoundEntry) {
var entryIdx = "entry_" + idx;
bFoundEntry = false;
$(retXml).find(entryIdx).each(function() {
bFoundEntry = true;
var rule = $(this).find("rule_name").text();
var outPort = $(this).find("out_port").text();
var inPort = $(this).find("in_port").text();
var outProto = $(this).find("out_proto").text();
var inProto = $(this).find("in_proto").text();
var enabled = $(this).find("enabled").text();
var portEntryInfo = rule + ";" + outPort + ";" + inPort + ";" + outProto + ";"
+ inProto + ";" + enabled;
var strStatus="";
if(1 == enabled) {
strStatus = jQuery.i18n.prop("lt_optEnableSwitch");
} else {
strStatus = jQuery.i18n.prop("lt_optDisabledSwitch");
}
var htmlTxt = "<tr style='cursor: pointer;'name='" + portEntryInfo + "'><td>" + rule + "</td><td>"
+ outPort + "</td><td>" + inPort + "</td><td>" + outProto + "</td><td>" + inProto + "</td><td>"
+ strStatus + "</td> <td><input type='checkbox'></td></tr>";
$("#tbodyPortTrigger").append(htmlTxt);
});
++idx;
$("tbody tr:last td:lt(6)").click(function() {
var entryIdx = $(this).parents("tr").prevAll("tr").length;
ModifyPortTriggerEntry(entryIdx);
});
}
$("#DeleteAllIpEntry").click(function() {
if($(this).attr("checked")) {
$("tbody :checkbox").attr("checked",true);
} else {
$("tbody :checkbox").attr("checked",false);
}
if($("tbody :checked").length>0) {
$("#lt_portTrigger_btnDelete").show();
} else {
$("#lt_portTrigger_btnDelete").hide();
}
});
$("tbody :checkbox").click(function() {
if($("tbody :checked").length == $("tbody tr").length) {
$("#DeleteAllIpEntry").attr("checked",true);
} else {
$("#DeleteAllIpEntry").attr("checked",false);
}
if($("tbody :checked").length>0) {
$("#lt_portTrigger_btnDelete").show();
} else {
$("#lt_portTrigger_btnDelete").hide();
}
});
}
function ModifyPortTriggerEntry(entryIdx) {
ShowDlg("divPortTriggerSetDlg",300,100);
var entryId = entryIdx + 1;
var selector = "tbody tr:eq(" + entryIdx+ ")";
var portTriggerEntryInfo = $(selector).attr("name").split(";");
$("#txtPortTriggerRule").val(portTriggerEntryInfo[0]);
SetPortToElement("txtOutPort",portTriggerEntryInfo[1]);
SetPortToElement("txtInPort",portTriggerEntryInfo[2]);
$("#selPortTriggerOutProtocol").val(portTriggerEntryInfo[3]);
$("#selPortTriggerInProtocol").val(portTriggerEntryInfo[4]);
$("#selPortTriggerStatus").val(portTriggerEntryInfo[5]);
$("#lt_btnSave").click(function() {
if(!IsPort(GetPortFromElement("txtOutPort")) || !IsPort(GetPortFromElement("txtInPort"))) {
$("#lPortTriggerSetError").show();
$("#lPortTriggerSetError").text(jQuery.i18n.prop("lt_PortFormatError"));
return;
}
if(!IsRuleName( $("#txtPortTriggerRule").val())) {
$("#lPortTriggerSetError").show();
$("#lPortTriggerSetError").text(jQuery.i18n.prop("lt_RuleNameError"));
return;
}
if(portTriggerEntryInfo[0] == $("#txtPortTriggerRule").val() && portTriggerEntryInfo[1] == GetPortFromElement("txtOutPort")
&& portTriggerEntryInfo[2] == GetPortFromElement("txtInPort")&& portTriggerEntryInfo[3] == $("#selPortTriggerOutProtocol").val()
&& portTriggerEntryInfo[4] == $("#selPortTriggerInProtocol").val() && portTriggerEntryInfo[5] == $("#selPortTriggerStatus").val()) {
CloseDlg();
return;
}
var preTag = "RGW/firewall/port_trigger/entry_list/entry_" + entryId;
var entryMap = new Map();
entryMap.put(preTag+"/rule_name", $("#txtPortTriggerRule").val());
entryMap.put(preTag+"/out_port",GetPortFromElement("txtOutPort"));
entryMap.put(preTag+"/in_port",GetPortFromElement("txtInPort"));
entryMap.put(preTag+"/out_proto", $("#selPortTriggerOutProtocol").val());
entryMap.put(preTag+"/in_proto", $("#selPortTriggerInProtocol").val());
entryMap.put(preTag+"/enabled", $("#selPortTriggerStatus").val());
CloseDlg();
var retXml = PostXml("firewall","edit_port_trigger_entry",entryMap);
if("OK" == $(retXml).find("setting_response").text()) {
GetFWPortTriggerInfo();
} else {
alert("edit port mapping entry failed.");
}
});//$("#lt_btnSave").click(function(){
}
return this;
}
})(jQuery);