b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 |
|
| 2 | (function($) {
|
| 3 |
|
| 4 | $.fn.objTimeSetting = function(InIt) {
|
| 5 |
|
| 6 | var gTimeZone,gDate,gTime,gNtpServerStatus,gNtpServer1,gNtpServer2;
|
| 7 | this.onLoad = function(flag) {
|
| 8 | if(flag) {
|
| 9 | LoadWebPage("//192.168.1.1/html/router/time_setting.html");
|
| 10 |
|
| 11 | $("#SelDhcpServerSwitch").change(function() {
|
| 12 | if("1"==$(this).val()) {
|
| 13 | $("#divDhcpInfo").hide();
|
| 14 | } else {
|
| 15 | $("#divDhcpInfo").show();
|
| 16 | }
|
| 17 | });
|
| 18 |
|
| 19 | $("#lt_tz_btnGetGmtTime").click(function() {
|
| 20 | var retXml = PostXml("router","router_invoke_ntp");
|
| 21 | if("OK" != $(retXml).find("setting_response").text()) {
|
| 22 | alert("router_invoke_ntp failed.");
|
| 23 | } else {
|
| 24 | GetTimeInfo();
|
| 25 | }
|
| 26 | });
|
| 27 |
|
| 28 | $("#SelNtpServerSwitch").click(function() {
|
| 29 | if(1 == $(this).val()) {
|
| 30 | $("#divNtpServer").show();
|
| 31 | } else {
|
| 32 | $("#divNtpServer").hide();
|
| 33 | }
|
| 34 | });
|
| 35 | } //end flag
|
| 36 |
|
| 37 |
|
| 38 | GetTimeInfo();
|
| 39 | }
|
| 40 |
|
| 41 | this.SaveData = function() {
|
| 42 | SetTimeInfo();
|
| 43 | }
|
| 44 |
|
| 45 | function GetTimeInfo() {
|
| 46 | var retXml = PostXml("router","router_get_time_info");
|
| 47 |
|
| 48 | gTimeZone = $(retXml).find("timezone").text();
|
| 49 | gDate = $(retXml).find("year").text() + "-"
|
| 50 | + $(retXml).find("month").text() + "-"
|
| 51 | + $(retXml).find("day").text();
|
| 52 |
|
| 53 | gTime = $(retXml).find("hour").text() + ":"
|
| 54 | + $(retXml).find("min").text() + ":"
|
| 55 | + $(retXml).find("sec").text();
|
| 56 |
|
| 57 |
|
| 58 | gNtpServerStatus = $(retXml).find("ntp_server_enable").text();
|
| 59 | gNtpServer1 = $(retXml).find("ntp_server_1").text();
|
| 60 | gNtpServer2 = $(retXml).find("ntp_server_2").text();
|
| 61 |
|
| 62 | $("#SelTimeZone").val(gTimeZone);
|
| 63 |
|
| 64 | SetDateToElement("txtdate",gDate)
|
| 65 | SetTimeToElement("txtTime",gTime);
|
| 66 |
|
| 67 | $("#SelNtpServerSwitch").val(gNtpServerStatus);
|
| 68 | if(1 == gNtpServerStatus) {
|
| 69 | $("#divNtpServer").show();
|
| 70 | $("#txtNtpServer1").val(gNtpServer1);
|
| 71 | $("#txtNtpServer2").val(gNtpServer2);
|
| 72 | } else {
|
| 73 | $("#divNtpServer").hide();
|
| 74 | }
|
| 75 | }
|
| 76 |
|
| 77 | function SetTimeInfo() {
|
| 78 | var time = GetTimeFromElement("txtTime");
|
| 79 | var date = GetDateFromElement("txtdate");
|
| 80 |
|
| 81 | if(!IsTime(time)) {
|
| 82 | $("#tzSetErrorLogs").show();
|
| 83 | $("#tzSetErrorLogs").text(jQuery.i18n.prop("lt_TimeFormatError"));
|
| 84 | return;
|
| 85 | }
|
| 86 |
|
| 87 | if(!IsData(date)) {
|
| 88 | $("#tzSetErrorLogs").show();
|
| 89 | $("#tzSetErrorLogs").text(jQuery.i18n.prop("lt_DateFormatError"));
|
| 90 | return;
|
| 91 | }
|
| 92 |
|
| 93 | var configMap = new Map();
|
| 94 | if(time != gTime) {
|
| 95 | configMap.put("RGW/time_setting/hour",$("#txtTime1").val());
|
| 96 | configMap.put("RGW/time_setting/min",$("#txtTime2").val());
|
| 97 | configMap.put("RGW/time_setting/sec",$("#txtTime3").val());
|
| 98 | }
|
| 99 |
|
| 100 | if(date != gDate) {
|
| 101 | configMap.put("RGW/time_setting/year",$("#txtdate1").val());
|
| 102 | configMap.put("RGW/time_setting/month",$("#txtdate2").val());
|
| 103 | configMap.put("RGW/time_setting/day",$("#txtdate3").val());
|
| 104 | }
|
| 105 |
|
| 106 | if(gTimeZone != $("#SelTimeZone").val()) {
|
| 107 | configMap.put("RGW/time_setting/timezone",$("#SelTimeZone").val());
|
| 108 | }
|
| 109 |
|
| 110 | if(gNtpServerStatus != $("#SelNtpServerSwitch").val()) {
|
| 111 | configMap.put("RGW/time_setting/ntp_server_enable",$("#SelNtpServerSwitch").val());
|
| 112 | }
|
| 113 |
|
| 114 | if(1 == $("#SelNtpServerSwitch").val()) {
|
| 115 | var ntpServer1 = $("#txtNtpServer1").val();
|
| 116 | var ntpServer2 = $("#txtNtpServer2").val();
|
| 117 |
|
| 118 | /* if(!IsUrl(ntpServer1) || !IsIPv4(ntpServer1)
|
| 119 | || !IsUrl(ntpServer2) || !IsIPv4(ntpServer2)) {
|
| 120 | $("#tzSetErrorLogs").show();
|
| 121 | $("#tzSetErrorLogs").text(jQuery.i18n.prop("lt_serverFormatError"));
|
| 122 | return;
|
| 123 | }*/
|
| 124 |
|
| 125 | if(gNtpServer1 != ntpServer1) {
|
| 126 | configMap.put("RGW/time_setting/ntp_server_1",ntpServer1);
|
| 127 | }
|
| 128 | if(gNtpServer2 != ntpServer2) {
|
| 129 | configMap.put("RGW/time_setting/ntp_server_2",ntpServer2);
|
| 130 | }
|
| 131 | }
|
| 132 |
|
| 133 | if(configMap.size() == 0) {
|
| 134 | return;
|
| 135 | }
|
| 136 |
|
| 137 | var retXml = PostXml("router","router_set_time_info",configMap);
|
| 138 | if("OK" != $(retXml).find("setting_response").text()) {
|
| 139 | alert("router_set_timg_info failed.");
|
| 140 | } else {
|
| 141 | GetTimeInfo();
|
| 142 | }
|
| 143 |
|
| 144 | }
|
| 145 |
|
| 146 | return this;
|
| 147 | }
|
| 148 | })(jQuery);
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|