blob: 59354d27f25e19b033a442895ddbe3f897cc910d [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001function restartDevice(service) {
2 showLoading("restarting");
3 service.restart({}, function (data) {
4 if (data && data.result == "success") {
5 successOverlay();
6 } else {
7 errorOverlay();
8 }
9 }, $.noop);
10}
11function signalFormat(signal) {
12 if (signal) {
13 if (signal > 0) {
14 return "-" + signal + " dBm";
15 } else {
16 return signal + " dBm";
17 }
18 } else {
19 return "— —";
20 }
21}
22function convertSignal(data) {
23 var type_2g = ["GSM", "GPRS", "EDGE", "G", "E"];
24 var type_3g = ["UMTS", "HSDPA", "HSUPA", "HSPA", "HSPA+", "DC-HSPA+", "WCDMA", "TD-SCDMA", "TD", "3G", "TD_SCDMA"];
25 var type_4g = ["LTE", "4G", "FDD", "TDD", "TDD-LTE", "FDD-LTE", "TDD_LTE", "FDD_LTE"];
26 var network_type = data.sub_network_type ? data.sub_network_type : (data.network_type ? data.network_type : '');
27 if ($.inArray(network_type, type_2g) != -1) {
28 return data.rssi;
29 } else if ($.inArray(network_type, type_3g) != -1) {
30 return data.rscp;
31 } else if ($.inArray(network_type, type_4g) != -1) {
32 return data.lte_rsrp;
33 }
34}
35
36function verifyDeviceInfo(field) {
37 if (field && field != "" && field != "0.0.0.0") {
38 return field;
39 } else {
40 return "— —";
41 }
42}
43$(document).ready(function () {
44 $("body").click(function (evt) {
45 var $popover = $(".popover");
46 var $target = $(evt.target);
47 if ((evt.target.id != $popover.data('source') && $target.parents('.popover').length == 0) || $target.hasClass("popover-close")) {
48 popover.close();
49 }
50 });
51});
52var popover = {
53 popoverEle: null,
54 _init: function () {
55 if (this.popoverEle == null) {
56 $("body").append('<div class="popover"></div>');
57 this.popoverEle = $(".popover");
58 }
59 },
60 open: function (opt) {
61 this._init();
62 var offset = opt.target.offset();
63 var top = offset.top + opt.target.outerHeight();
64 this.popoverEle.html(opt.html).css({
65 width: opt.width,
66 left: offset.left,
67 top: top
68 }).data({
69 source: opt.target[0].id
70 }).translate();
71 setTimeout(function () {
72 popover.popoverEle.show();
73 }, 100);
74 this.popoverEle.translate();
75 opt.validation && opt.validation.apply();
76 },
77 close: function () {
78 this.popoverEle && this.popoverEle.fadeOut();
79 },
80 show: function () {
81 this.popoverEle && this.popoverEle.show();
82 },
83 hide: function () {
84 this.popoverEle && this.popoverEle.hide();
85 }
86};
87function isWifiConnected(user_ip_addr, station_list) {
88 return !!_.find(station_list, function (station) {
89 return station.ip_addr == user_ip_addr;
90 });
91}
92function trim(stringToTrim) {
93 return stringToTrim.replace(/^\s+|\s+$/g, "");
94}
95
96function renderCustomElement(container) {
97 if (!container) {
98 container = $("#container");
99 }
100 var radios = container.find("input[type='radio']");
101 var checkboxes = container.find("input[type='checkbox']");
102 $.each(radios, function (i, n) {
103 var $el = $(n),
104 ch = 'checked',
105 checkAction = $el.prop('checked') ? true : false;
106 $el.closest('.radio')[checkAction ? 'addClass' : 'removeClass'](ch) && checkAction ? $el.attr(ch, true) : $el.removeAttr(ch);
107 });
108 $.each(checkboxes, function (i, n) {
109 var $el = $(n),
110 ch = 'checked',
111 checkAction = $el.prop('checked') ? true : false;
112 $el.closest('.checkbox')[checkAction ? 'addClass' : 'removeClass'](ch) && checkAction ? $el.attr(ch, true) : $el.removeAttr(ch);
113 });
114}
115
116function getSelectValFromChosen(choices) {
117 var choicesNums = [];
118 $.each(choices, function (i, n) {
119 var arr = $(n).text().split('/');
120 choicesNums.push(arr[arr.length - 1]);
121 });
122 return choicesNums;
123}
124function syncSelectAndChosen(select, choices) {
125 var choicesNums = getSelectValFromChosen(choices);
126 select.val(choicesNums);
127 return choicesNums;
128}
129
130function getPercent(numerator, denominator, accuracy) {
131 if (accuracy) {
132 accuracy = accuracy * 10;
133 } else {
134 accuracy = 100;
135 }
136 return roundToTwoDecimalNumber(numerator / denominator * accuracy) + "%";
137}
138function checkConnectedStatus(modemConnStatus, rj45ConnStatus, apConnStatus) {
139 return modemConnStatus == "ppp_connected" || rj45ConnStatus == "working" || apConnStatus == "connect";
140}
141
142function enableBtn(ele) {
143 ele.removeAttr("disabled").removeClass("disabled");
144}
145function replaceSpaceWithNbsp(str) {
146 return str.replace(/ /g, '&nbsp;');
147}
148function URLEncodeComponent(url) {
149 return encodeURIComponent(url);
150}
151function URLEncode(url) {
152 return encodeURI(url);
153}
154function checkCableMode(currentMode) {
155 return currentMode == "PPPOE" || currentMode == "AUTO_PPPOE";
156}
157function disableBtn(ele) {
158 ele.attr("disabled", "disabled").removeClass("focusIn").addClass("disabled");
159}
160var Escape = {
161 html: function (string) {
162 return (string + '').replace(/[&<>"'\/`]/g, Escape._htmlReplacer);
163 },
164 regex: function (string) {
165 return (string + '').replace(/[\-$\^*()+\[\]{}|\\,.?\s]/g, '\\$&');
166 },
167 _htmlReplacer: function (match) {
168 return Escape.HTML_CHARS[match];
169 },
170 HTML_CHARS: {
171 '&': '&amp;',
172 '<': '&lt;',
173 '>': '&gt;',
174 '"': '&quot;',
175 "'": '&#x27;',
176 '/': '&#x2F;',
177 '`': '&#x60;'
178 }
179};
180function roundToTwoDecimalNumber(num) {
181 return Math.round(num * 100) / 100;
182}
183function HTMLEncode(html) {
184 return Escape.html(html);
185}
186function HTMLDecode(text) {
187 var temp = document.createElement("div");
188 temp.innerHTML = text;
189 var output = temp.innerText || temp.textContent;
190 output = output.replace(new RegExp("&nbsp;", "gm"), " ");
191 temp = null;
192 return output;
193}
194function getDisplayVolume1(volume, isSpeed) {
195 volume = parseInt(volume, 10);
196 if (volume == "" || volume == "0") {
197 return "";
198 }
199 var needReverse = false;
200 if (volume < 0) {
201 needReverse = true;
202 volume = 0 - volume;
203 }
204 var numberOfBytesInOneB = 1;
205 var numberOfBytesInOneKB = numberOfBytesInOneB * 1024;
206 var numberOfBytesInOneMB = numberOfBytesInOneKB * 1024;
207 var numberOfBytesInOneGB = numberOfBytesInOneMB * 1024;
208 var numberOfBytesInOneTB = numberOfBytesInOneGB * 1024;
209 var labelForOneB = isSpeed ? 'b' : 'B';
210 var labelForOneKB = isSpeed ? 'Kb' : 'KB';
211 var labelForOneMB = isSpeed ? 'Mb' : 'MB';
212 var labelForOneGB = isSpeed ? 'Gb' : 'GB';
213 var labelForOneTB = isSpeed ? 'Tb' : 'TB';
214 if (isSpeed) {
215 volume = volume * 8;
216 }
217 var vol = volume / numberOfBytesInOneTB;
218 var displayString = roundToTwoDecimalNumber(vol) + labelForOneTB;
219 if (vol < 0.5) {
220 vol = volume / numberOfBytesInOneGB;
221 displayString = roundToTwoDecimalNumber(vol) + labelForOneGB;
222 if (vol < 0.5) {
223 vol = volume / numberOfBytesInOneMB;
224 displayString = roundToTwoDecimalNumber(vol) + labelForOneMB;
225 if (isSpeed) {
226 if (vol < 0.5) {
227 vol = volume / numberOfBytesInOneKB;
228 displayString = roundToTwoDecimalNumber(vol) + labelForOneKB;
229 if (vol < 0.5) {
230 vol = volume;
231 displayString = roundToTwoDecimalNumber(vol) + labelForOneB;
232 }
233 }
234 }
235 }
236 }
237 if (needReverse) {
238 displayString = "-" + displayString;
239 }
240 return displayString;
241}
242function getDisplayVolume(volume, isSpeed) {
243 volume = parseInt(volume, 10);
244 if (volume == "" || volume == "0") {
245 return "";
246 }
247 var needReverse = false;
248 if (volume < 0) {
249 needReverse = true;
250 volume = 0 - volume;
251 }
252 var numberOfBytesInOneB = 1;
253 var numberOfBytesInOneKB = numberOfBytesInOneB * 1024;
254 var numberOfBytesInOneMB = numberOfBytesInOneKB * 1024;
255 var numberOfBytesInOneGB = numberOfBytesInOneMB * 1024;
256 var numberOfBytesInOneTB = numberOfBytesInOneGB * 1024;
257 var labelForOneB = isSpeed ? 'b' : 'B';
258 var labelForOneKB = isSpeed ? 'Kb' : 'KB';
259 var labelForOneMB = isSpeed ? 'Mb' : 'MB';
260 var labelForOneGB = isSpeed ? 'Gb' : 'GB';
261 var labelForOneTB = isSpeed ? 'Tb' : 'TB';
262 if (isSpeed) {
263 volume = volume * 8;
264 }
265 var vol = volume / numberOfBytesInOneTB;
266 var displayString = roundToTwoDecimalNumber(vol) + labelForOneTB;
267 if (vol < 0.5) {
268 vol = volume / numberOfBytesInOneGB;
269 displayString = roundToTwoDecimalNumber(vol) + labelForOneGB;
270 if (vol < 0.5) {
271 vol = volume / numberOfBytesInOneMB;
272 displayString = roundToTwoDecimalNumber(vol) + labelForOneMB;
273 if (vol < 0.5) {
274 vol = volume / numberOfBytesInOneKB;
275 displayString = roundToTwoDecimalNumber(vol) + labelForOneKB;
276 if (vol < 0.5) {
277 vol = volume;
278 displayString = roundToTwoDecimalNumber(vol) + labelForOneB;
279 }
280 }
281 }
282 }
283 if (needReverse) {
284 displayString = "-" + displayString;
285 }
286 return displayString;
287}
288function transUnit(data, isSpeed) {
289 var result = getDisplayVolume1(data, isSpeed);
290 if (result == "") {
291 result = isSpeed ? "0b" : "0MB";
292 }
293 if (isSpeed) {
294 result += "/s";
295 }
296 return result;
297}
298function transTimeUnit(data) {
299 data = parseFloat(data);
300 if (data == "") {
301 return result = "0hour";
302 }
303 var needReverse = false;
304 if (data < 0) {
305 needReverse = true;
306 data = 0 - data;
307 }
308 var labelForOneMinute = 'minute';
309 var labelForOneHour = 'hour';
310 var vol = data / 3600;
311 var result = roundToTwoDecimalNumber(vol) + labelForOneHour;
312 if (vol < 1) {
313 vol = data / 60;
314 result = roundToTwoDecimalNumber(vol) + labelForOneMinute;
315 }
316 if (needReverse) {
317 result = "-" + result;
318 }
319 return result;
320}
321function transSecond2Time(secs) {
322 secs = parseInt(secs, 10);
323 var isNegative = false;
324 if (secs < 0) {
325 isNegative = true;
326 secs = 0 - secs;
327 }
328 var hour = Math.floor(secs / 3600);
329 secs = secs % 3600;
330 var minu = Math.floor(secs / 60);
331 secs = secs % 60;
332 return (isNegative ? '-' : '') + leftInsert(hour, 2, '0') + ":" + leftInsert(minu, 2, '0') + ":" + leftInsert(secs, 2, '0');
333}
334function leftInsert(value, length, placeholder) {
335 var len = value.toString().length;
336 for (; len < length; len++) {
337 value = placeholder + value;
338 }
339 return value;
340}
341
342var _timeoutStack = [];
343var _intervalStack = [];
344function addTimeout(code, delay) {
345 var time = window.setTimeout(code, delay);
346 _timeoutStack.push(time);
347 return time;
348}
349function addInterval(code, delay) {
350 var time = window.setInterval(code, delay);
351 _intervalStack.push(time);
352 return time;
353}
354function clearTimer() {
355 clearTimeoutTimer();
356 clearIntervalTimer();
357}
358function clearTimeoutTimer() {
359 for (var i = 0; i < _timeoutStack.length; i++) {
360 window.clearTimeout(_timeoutStack[i]);
361 }
362 _timeoutStack = [];
363}
364function clearIntervalTimer() {
365 for (var i = 0; i < _intervalStack.length; i++) {
366 window.clearInterval(_intervalStack[i]);
367 }
368 _intervalStack = [];
369}
370$(document).ready(function () {
371 $("[manualControl!=true].checkbox").live("click", function (event) {
372 var $this = $(this);
373 if ($this.hasClass('disable')) {
374 return false;
375 }
376 var checkbox = $this.find("input:checkbox");
377 if (checkbox.attr("checked")) {
378 checkbox.removeAttr("checked");
379 } else {
380 checkbox.attr("checked", "checked");
381 }
382 checkCheckbox(checkbox);
383 event.stopPropagation();
384 return true;
385 });
386 $('input[type="text"][noAction!="true"],input[type="password"][noAction!="true"],select').live("focusin", function (event) {
387 $(this).addClass("focusIn");
388 }).live("focusout", function (event) {
389 $(this).removeClass("focusIn");
390 });
391 $(".form-note .notes-title").live('click', function () {
392 var $this = $(this);
393 $this.siblings("ul.notes-content:first").slideToggle();
394 $this.toggleClass("notes-dot");
395 });
396});
397var GSM7_Table = ["000A", "000C", "000D", "0020", "0021", "0022", "0023", "0024", "0025", "0026", "0027", "0028", "0029", "002A", "002B", "002C", "002D", "002E", "002F", "0030", "0031", "0032", "0033", "0034", "0035", "0036", "0037", "0038", "0039", "003A", "003A", "003B", "003C", "003D", "003E", "003F", "0040", "0041", "0042", "0043", "0044", "0045", "0046", "0047", "0048", "0049", "004A", "004B", "004C", "004D", "004E", "004F", "0050", "0051", "0052", "0053", "0054", "0055", "0056", "0057", "0058", "0059", "005A", "005B", "005C", "005D", "005E", "005F", "0061", "0062", "0063", "0064", "0065", "0066", "0067", "0068", "0069", "006A", "006B", "006C", "006D", "006E", "006F", "0070", "0071", "0072", "0073", "0074", "0075", "0076", "0077", "0078", "0079", "007A", "007B", "007C", "007D", "007E", "00A0", "00A1", "00A3", "00A4", "00A5", "00A7", "00BF", "00C4", "00C5", "00C6", "00C7", "00C9", "00D1", "00D6", "00D8", "00DC", "00DF", "00E0", "00E4", "00E5", "00E6", "00E8", "00E9", "00EC", "00F1", "00F2", "00F6", "00F8", "00F9", "00FC", "0393", "0394", "0398", "039B", "039E", "03A0", "03A3", "03A6", "03A8", "03A9", "20AC"];
398var GSM7_Table_Extend = ["007B", "007D", "005B", "005D", "007E", "005C", "005E", "20AC", "007C"];
399function getEncodeType(strMessage) {
400 var encodeType = "GSM7_default";
401 var gsm7_extend_char_len = 0;
402 if (!strMessage) {
403 return {
404 encodeType: encodeType,
405 extendLen: gsm7_extend_char_len
406 };
407 }
408 for (var i = 0; i < strMessage.length; i++) {
409 var charCode = strMessage.charCodeAt(i).toString(16).toUpperCase();
410 while (charCode.length != 4) {
411 charCode = "0" + charCode;
412 }
413 if ($.inArray(charCode, GSM7_Table_Extend) != -1) {
414 gsm7_extend_char_len++;
415 }
416 if ($.inArray(charCode, GSM7_Table) == -1) {
417 encodeType = "UNICODE";
418 gsm7_extend_char_len = 0;
419 break;
420 }
421 }
422 return {
423 encodeType: encodeType,
424 extendLen: gsm7_extend_char_len
425 };
426}
427function encodeMessage(textString) {
428 var haut = 0;
429 var result = '';
430 if (!textString)
431 return result;
432 for (var i = 0; i < textString.length; i++) {
433 var b = textString.charCodeAt(i);
434 if (haut != 0) {
435 if (0xDC00 <= b && b <= 0xDFFF) {
436 result += dec2hex(0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00));
437 haut = 0;
438 continue;
439 } else {
440 haut = 0;
441 }
442 }
443 if (0xD800 <= b && b <= 0xDBFF) {
444 haut = b;
445 } else {
446 cp = dec2hex(b);
447 while (cp.length < 4) {
448 cp = '0' + cp;
449 }
450 result += cp;
451 }
452 }
453 return result;
454}
455var specialChars = ['000D', '000A', '0009', '0000'];
456var specialCharsIgnoreWrap = ['0009', '0000'];
457function decodeMessage(str, ignoreWrap) {
458 if (!str)
459 return "";
460 var specials = specialCharsIgnoreWrap;
461 return str.replace(/([A-Fa-f0-9]{1,4})/g, function (matchstr, parens) {
462 if ($.inArray(parens, specials) == -1) {
463 return hex2char(parens);
464 } else {
465 return '';
466 }
467 });
468}
469function dec2hex(textString) {
470 return (textString + 0).toString(16).toUpperCase();
471}
472function hex2char(hex) {
473 var result = '';
474 var n = parseInt(hex, 16);
475 if (n <= 0xFFFF) {
476 result += String.fromCharCode(n);
477 } else if (n <= 0x10FFFF) {
478 n -= 0x10000;
479 result += String.fromCharCode(0xD800 | (n >> 10)) + String.fromCharCode(0xDC00 | (n & 0x3FF));
480 }
481 return result;
482}
483function renderCheckbox() {
484 var checkboxToggle = $(".checkboxToggle");
485 checkboxToggle.each(function () {
486 checkBoxesSize($(this));
487 });
488 var checkboxes = $(".checkbox").not("[class*='checkboxToggle']").find("input:checkbox");
489 if (checkboxes.length == 0) {
490 disableCheckbox(checkboxToggle);
491 } else {
492 enableCheckbox(checkboxToggle);
493 }
494 checkboxes.each(function () {
495 checkCheckbox($(this));
496 });
497}
498function checkBoxesSize(selectAll) {
499 var target = selectAll.attr("target");
500 var boxSize = $("#" + target + " .checkbox input:checkbox").length;
501 var checkedBoxSize = $("#" + target + " .checkbox input:checkbox:checked").length;
502 var checkbox = selectAll.find("input:checkbox");
503 if (boxSize != 0 && boxSize == checkedBoxSize) {
504 checkbox.attr("checked", "checked");
505 } else {
506 checkbox.removeAttr("checked");
507 }
508 checkP(checkbox);
509}
510function checkSelectAll(selectAll, target) {
511 var theCheckbox = $("#" + target + " .checkbox input:checkbox");
512 if (selectAll.attr("checked")) {
513 theCheckbox.attr("checked", "checked");
514 } else {
515 theCheckbox.removeAttr("checked");
516 }
517 theCheckbox.each(function () {
518 checkCheckbox($(this));
519 });
520}
521function checkCheckbox(checkbox) {
522 if (checkbox.closest("p.checkbox").hasClass("checkboxToggle")) {
523 checkSelectAll(checkbox, checkbox.closest("p.checkbox").attr("target"));
524 }
525 checkP(checkbox);
526 checkBoxesSize($("#" + checkbox.attr("target")));
527}
528function checkP(checkbox) {
529 if (checkbox.attr("checked")) {
530 checkbox.closest("p.checkbox").addClass("checkbox_selected");
531 } else {
532 checkbox.closest("p.checkbox").removeClass("checkbox_selected");
533 }
534}
535function removeChecked(id) {
536 $("#" + id).removeClass("checkbox_selected").find("input:checkbox").removeAttr("checked");
537}
538function disableCheckbox(checkbox) {
539 var chk = checkbox.find("input:checkbox");
540 if (chk.attr("checked")) {
541 checkbox.addClass('checked_disable');
542 } else {
543 checkbox.addClass('disable');
544 }
545}
546function enableCheckbox(checkbox) {
547 checkbox.removeClass('disable').removeClass("checked_disable");
548}
549function tryToDisableCheckAll(checkbox, len) {
550 if (len == 0) {
551 disableCheckbox(checkbox);
552 } else {
553 enableCheckbox(checkbox);
554 }
555}
556
557function escapeMessage(msg) {
558 return msg;
559}
560function parseTime(date) {
561 if (date.indexOf("+") > -1) {
562 date = date.substring(0, date.lastIndexOf("+"));
563 }
564 var dateArr;
565 if (date.indexOf(",") > -1) {
566 dateArr = date.split(",");
567 } else {
568 dateArr = date.split(";");
569 }
570 if (dateArr.length == 0) {
571 return "";
572 } else {
573 var time = dateArr[0] + "-" + dateArr[1] + "-" + dateArr[2] + " " + leftInsert(dateArr[3], 2, '0') + ":" + leftInsert(dateArr[4], 2, '0') + ":"
574 +leftInsert(dateArr[5], 2, '0');
575 return time;
576 }
577}
578function transTime(data) {
579 var dateArr = data.split(",");
580 if (dateArr.length == 0 || ("," + data + ",").indexOf(",,") != -1) {
581 return "";
582 } else {
583 var time = dateArr[0] + "/" + dateArr[1] + "/" + dateArr[2] + " " + leftInsert(dateArr[3], 2, '0') + ":" + leftInsert(dateArr[4], 2, '0') + ":"
584 +leftInsert(dateArr[5], 2, '0');
585 return time;
586 }
587}
588function getSmsCount(str) {
589 var encodeType = getEncodeType(str);
590 var len = str.length,
591 gsm7 = encodeType.encodeType != "UNICODE",
592 needChunking = false,
593 chunkSize = 0;
594 if (gsm7) {
595 needChunking = (len + encodeType.extendLen) > 160;
596 chunkSize = 153;
597 } else {
598 needChunking = len > 70;
599 chunkSize = 67;
600 }
601 if (needChunking) {
602 return Math.ceil((len + encodeType.extendLen) / chunkSize);
603 } else {
604 return 1;
605 }
606}
607function getInsertPos(textbox) {
608 var iPos = 0;
609 if (textbox.selectionStart || textbox.selectionStart == "0") {
610 iPos = textbox.selectionStart;
611 } else if (document.selection) {
612 textbox.focus();
613 var range = document.selection.createRange();
614 var rangeCopy = range.duplicate();
615 rangeCopy.moveToElementText(textbox);
616 while (range.compareEndPoints("StartToStart", rangeCopy) > 0) {
617 range.moveStart("character", -1);
618 iPos++;
619 }
620 }
621 return iPos;
622}
623function setInsertPos(textbox, iPos) {
624 textbox.focus();
625 if (textbox.selectionStart || textbox.selectionStart == "0") {
626 textbox.selectionStart = iPos;
627 textbox.selectionEnd = iPos;
628 } else if (document.selection) {
629 var range = textbox.createTextRange();
630 range.moveStart("character", iPos);
631 range.collapse(true);
632 range.select();
633 }
634}
635function isIntNum(input, num) {
636 for (var i = 1; i < 6; i++) {
637 if (input == i * num) {
638 return true;
639 }
640 }
641 return false;
642}
643
644function transUnixTime(millisecond) {
645 var time = new Date(parseInt(millisecond, 10));
646 var year = time.getFullYear();
647 var month = leftPad(time.getMonth() + 1, 2, "0");
648 var date = leftPad(time.getDate(), 2, "0");
649 var hour = leftPad(time.getHours(), 2, "0");
650 var minute = leftPad(time.getMinutes(), 2, "0");
651 var second = leftPad(time.getSeconds(), 2, "0");
652 return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
653}
654function leftPad(value, length, placeholder) {
655 var len = value.toString().length;
656 for (; len < length; len++) {
657 value = placeholder + value;
658 }
659 return value;
660};
661function convertNumberToId(number) {
662 return number.replace(/[\+\*#]/g, '_');
663}
664function getLastNumber(number, len) {
665 if (number.length > len) {
666 return convertNumberToId(number.substring(number.length - len, number.length));
667 }
668 return convertNumberToId(number);
669}
670function fixTableHeight() {
671 if ($.browser.msie) {
672 var heightTimer = setInterval(function () {
673 var $table = $(".fixTableScroll")[0];
674 if ($table) {
675 var scrollHeight = $table.scrollHeight;
676 if (scrollHeight != 0) {
677 $table.style.height = scrollHeight + 20;
678 window.clearInterval(heightTimer);
679 }
680 } else {
681 window.clearInterval(heightTimer);
682 }
683 }, 300);
684 }
685}
686function refreshTableHeight() {
687 if ($.browser.msie) {
688 $(".fixTableScroll")[0].style.height = $(".fixTableScroll .ko-grid-container")[0].scrollHeight + 35;
689 }
690}
691
692function popup(option) {
693 $.modal.close();
694 var minHeight = option.minHeight || 140;
695 $('#confirm').modal({
696 zIndex: 3000,
697 position: ["30%"],
698 overlayId: 'confirm-overlay',
699 containerId: 'confirm-container',
700 escClose: false,
701 minHeight: minHeight
702 });
703 var $confirmDiv = $('div#confirm');
704 $('#confirmImg', $confirmDiv).attr('src', option.img);
705 $('#popTitle', $confirmDiv).html($.i18n.prop(option.title));
706 if (typeof option.msg != 'string') {
707 var params = [option.msg.msg];
708 params.push(option.msg.params);
709 $('.message', $confirmDiv).html($.i18n.prop.apply(null, _.flatten(params)));
710 } else {
711 $('.message', $confirmDiv).html($.i18n.prop(option.msg));
712 }
713 var $promptDiv = $("div.promptDiv", $confirmDiv);
714 if (option.showInput === true) {
715 $promptDiv.show();
716 $("input#promptInput", $promptDiv).val(option.defaultValue ? option.defaultValue : "");
717 $(".promptErrorLabel", $promptDiv).empty();
718 } else {
719 $promptDiv.hide();
720 }
721 window.setTimeout(function () {
722 $(':input:enabled:visible:first', '#confirm-container').focus();
723 }, 0);
724}
725function showSettingWindow(title, htmlPath, jsPath, minWidth, minHeight, callback) {
726 var option = {
727 title: title,
728 htmlPath: htmlPath,
729 jsPath: jsPath,
730 minHeight: minHeight,
731 minWidth: minWidth
732 };
733 var callbackIsFunction = $.isFunction(callback);
734 var callbackIsPojo = $.isPlainObject(callback);
735 popupSettingWindow(option);
736}
737function popupSettingWindow(option) {
738 $.modal.close();
739 var minHeight = option.minHeight || 140;
740 var minWidth = option.minWidth || 400;
741 var subContainer = $("#htmlContainer");
742 var tmplPath = 'text!tmpl/' + option.htmlPath + '.html';
743 require([tmplPath, option.jsPath], function (tmpl, viewModel) {
744 subContainer.stop(true, true);
745 subContainer.hide();
746 subContainer.html(tmpl);
747 viewModel.init();
748 $('#htmlContainer').translate();
749 subContainer.show();
750 $('#htmlContainer').css("opacity", 50);
751 });
752 $('#popupSettingWindow').modal({
753 zIndex: 3000,
754 position: ["30%"],
755 escClose: false,
756 minWidth: minWidth,
757 minHeight: minHeight,
758 maxWidth: 400,
759 opacity: 50
760 });
761}
762function hidePopupSettingWindow() {
763 $("#popupSettingWindow").remove();
764 $.modal.close();
765}
766function showInfo(msgObj, minHeight) {
767 var option = {
768 title: 'info',
769 img: 'pic/res_info.png',
770 msg: msgObj,
771 minHeight: minHeight
772 };
773 popup(option);
774 $('#yesbtn, #nobtn').hide();
775 $('#okbtn').unbind('click').click(function () {
776 $.modal.close();
777 }).show();
778}
779function showPrompt(msgObj, callback, minHeight, defaultValue, checkPromptInput, NobtnCallback) {
780 var option = {
781 title: 'prompt',
782 img: 'pic/res_confirm.png',
783 msg: msgObj,
784 minHeight: minHeight,
785 showInput: true,
786 defaultValue: defaultValue
787 };
788 popup(option);
789 $('#yesbtn, #nobtn').unbind('click').show();
790 $('#okbtn').hide();
791 $('#yesbtn').click(function () {
792 if ($.isFunction(checkPromptInput)) {
793 if (!checkPromptInput()) {
794 return false;
795 };
796 }
797 if ($.isFunction(callback)) {
798 if (callback()) {
799 $.modal.close();
800 }
801 }
802 });
803 $('#nobtn').click(function () {
804 if ($.isFunction(NobtnCallback)) {
805 NobtnCallback();
806 }
807 $.modal.close();
808 });
809 if ($.isFunction(checkPromptInput)) {
810 $("#promptInput", "#confirm").unbind('input propertychange').bind('input propertychange', function () {
811 if ($.isFunction(checkPromptInput)) {
812 checkPromptInput();
813 }
814 });
815 }
816 $("#promptInput", "#confirm").unbind('keypress').bind('keypress', function (event) {
817 if (event.keyCode == 13) {
818 $('#yesbtn').trigger("click");
819 }
820 });
821}
822function showConfirm(msgObj, callback, minHeight, yesTrans, noTrans) {
823 if (yesTrans) {
824 $('#yesbtn').attr("data-trans", yesTrans);
825 } else {
826 $('#yesbtn').attr("data-trans", "yes");
827 }
828 if (noTrans) {
829 $('#nobtn').attr("data-trans", noTrans);
830 } else {
831 $('#nobtn').attr("data-trans", "no");
832 }
833 $('#yesbtn, #nobtn').translate();
834 var option = {
835 title: 'confirm',
836 img: 'pic/res_confirm.png',
837 msg: msgObj,
838 minHeight: minHeight
839 };
840 popup(option);
841 $('#yesbtn, #nobtn').show();
842 $('#okbtn').hide();
843 var callbackIsFunction = $.isFunction(callback);
844 var callbackIsPojo = $.isPlainObject(callback);
845 $('#yesbtn').unbind('click').click(function () {
846 $.modal.close();
847 if (callbackIsFunction) {
848 callback();
849 } else if (callbackIsPojo && $.isFunction(callback.ok)) {
850 callback.ok();
851 }
852 });
853 $('#nobtn').unbind('click').click(function () {
854 $.modal.close();
855 if (callbackIsPojo && $.isFunction(callback.no)) {
856 callback.no();
857 }
858 });
859}
860function showAlert(msgObj, callback, minHeight) {
861 var option = {
862 title: 'alert',
863 img: 'pic/res_alert.png',
864 msg: msgObj,
865 minHeight: minHeight
866 };
867 popup(option);
868 $('#yesbtn, #nobtn').hide();
869 $('#okbtn').unbind('click').click(function () {
870 $.modal.close();
871 if ($.isFunction(callback)) {
872 callback();
873 }
874 }).show();
875}
876function loadingMsgChange(msg) {
877 $('#loadMsg').html($.i18n.prop(msg));
878}
879function hideLoading() {
880 $('#confirm-overlay').css("cursor", "default");
881 $.modal.close();
882 $('#loadMsg').html('');
883}
884function getRandomInt(n) {
885 return Math.round(Math.random() * n);
886}
887function getCurrentDatetime() {
888 var d = new Date();
889 return d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes()
890 + ":" + d.getSeconds();
891}
892function getRandomDatetime() {
893 var d = new Date();
894 return d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate() + " " + getRandomInt(24) + ":" + getRandomInt(60)
895 + ":" + getRandomInt(60);
896}
897function getRandomDatetimeSep() {
898 var d = new Date();
899 return d.getFullYear() + "," + (d.getMonth() + 1) + "," + d.getDate() + "," + getRandomInt(24) + "," + getRandomInt(60)
900 + "," + getRandomInt(60);
901}
902function getCurrentTimeString(theTime) {
903 var time = "";
904 var d = theTime ? theTime : new Date();
905 time += (d.getFullYear() + "").substring(2) + ";";
906 time += getTwoDigit((d.getMonth() + 1)) + ";" + getTwoDigit(d.getDate()) + ";" + getTwoDigit(d.getHours()) + ";"
907 +getTwoDigit(d.getMinutes()) + ";" + getTwoDigit(d.getSeconds()) + ";";
908 if (d.getTimezoneOffset() < 0) {
909 time += "+" + (0 - d.getTimezoneOffset() / 60);
910 } else {
911 time += (0 - d.getTimezoneOffset() / 60);
912 }
913 return time;
914}
915function getTwoDigit(num) {
916 num += "";
917 while (num.length < 2) {
918 num = "0" + num;
919 }
920 return num;
921}
922function showLoading(msg, content, contentAlert) {
923 if (msg) {
924 $('#loadMsg').html($.i18n.prop(msg));
925 } else {
926 $('#loadMsg').html('');
927 }
928 $('#loading').modal({
929 zIndex: 3000,
930 position: ['30%'],
931 overlayId: 'confirm-overlay',
932 containerId: 'confirm-container',
933 minHeight: 140,
934 persist: true,
935 focus: false,
936 escClose: false
937 });
938 var loading = $("#loading #loading_container");
939 var a = "<a href='javascript:void(0)'>&nbsp;</a>";
940 if (content) {
941 loading.html(content + a);
942 } else {
943 loading.html(a);
944 }
945 if (contentAlert) {
946 $('#loading #loading_wording').html($.i18n.prop(contentAlert));
947 } else {
948 $("#loading #loading_wording").html("");
949 }
950 $("a:last", loading).focus().hide();
951}
952function hideProgressBar() {
953 $.modal.close();
954 setProgressBar(0);
955 $('#barMsg').html('');
956}
957function setProgressBar(percents) {
958 jQuery("#bar").width(400 * percents / 100);
959 jQuery("#barValue").text(percents + "%");
960}
961
962function showProgressBar(msg, content) {
963 if (msg) {
964 $('#barMsg').html($.i18n.prop(msg));
965 }
966 $('#progress').modal({
967 zIndex: 3000,
968 position: ['30%'],
969 overlayId: 'confirm-overlay',
970 containerId: 'confirm-container',
971 minHeight: 140,
972 persist: true,
973 focus: false,
974 escClose: false
975 });
976 if (content) {
977 $("#progress #progress_container").html(content);
978 } else {
979 $("#progress #progress_container").html("");
980 }
981}
982
983function showInfoMsg(msg, nameText, tmp) {
984 $.modal.close();
985 if (msg) {
986 $('#result-image', '#result-overlay').removeClass().addClass(nameText);
987 $('#result_wording').html('<h2>' + $.i18n.prop(msg) + '</h2>');
988 }
989 $('#result-overlay').modal({
990 zIndex: 3000,
991 position: ['30%'],
992 overlayId: 'confirm-overlay',
993 containerId: 'confirm-container',
994 minHeight: 140,
995 persist: true,
996 focus: false,
997 escClose: false
998 });
999 var count = 3;
1000 var overlayTimer = setInterval(function () {
1001 count--;
1002 if (count == 0) {
1003 clearInterval(overlayTimer);
1004 if ($('#result-overlay:visible').length > 0) {
1005 $.modal.close();
1006 }
1007 }
1008 }, 1000);
1009}
1010function errorOverlay(msg, isContinueLoading) {
1011 showInfoMsg(msg ? msg : 'error_info', 'overlay-error', !isContinueLoading);
1012}
1013function successOverlay(msg, isContinueLoading) {
1014 showInfoMsg(msg ? msg : 'success_info', 'overlay-success', !isContinueLoading);
1015}
1016function transOption(transid, isChannel) {
1017 if (isChannel) {
1018 return function (item) {
1019 if (item.value != 0) {
1020 var val = item.value.split("_");
1021 return val[1] + "MHz " + $.i18n.prop(transid + '_' + val[0]);
1022 } else {
1023 return $.i18n.prop(transid + '_0');
1024 }
1025 };
1026 }
1027 return function (item) {
1028 return $.i18n.prop(transid + '_' + item.value);
1029 };
1030}
1031function getFileType(fileName) {
1032 var ext = fileName.split('.').pop().toLowerCase();
1033 for (type in extMap) {
1034 if ($.inArray(ext, extMap[type]) != -1) {
1035 return type;
1036 }
1037 }
1038 return "file";
1039}
1040var extMap = {
1041 mp3: ["mp3", "wma", "wav"],
1042 film: ["mp4", "avi", "rm", "rmvb", "3gp", "mpeg"],
1043 picture: ["jpeg", "jpg", "gif", "bmp", "png"],
1044 pdf: ['pdf'],
1045 rar: ['rar', '7z', 'zip', 'gzip', 'gz', 'tar'],
1046 doc: ['doc', 'docx'],
1047 ppt: ['ppt', 'pptx'],
1048 xls: ['xls', 'xlsx'],
1049 xml: ['xml']
1050};
1051function checkRange(str, min, max) {
1052 var intVal = parseInt(str, 10);
1053 return !(intVal > max || intVal < min);
1054}
1055function transProtocolValue(proto) {
1056 switch (proto) {
1057 case "TCP":
1058 case "UDP":
1059 case "ICMP":
1060 return proto;
1061 case "TCP&UDP":
1062 return "TCP+UDP";
1063 case "None":
1064 default:
1065 return "ALL";
1066 }
1067}
1068function transProtocol(proto) {
1069 var type = "ALL";
1070 if ("1" == proto)
1071 type = "TCP";
1072 else if ("2" == proto)
1073 type = "UDP";
1074 else if ("3" == proto)
1075 type = "TCP+UDP";
1076 else if ("4" == proto)
1077 type = "ICMP";
1078 else if ("5" == proto)
1079 type = "ALL";
1080 return type;
1081}
1082function updateLength(sms_content) {
1083 var length = 0;
1084 var tmpchr;
1085 var index = 0;
1086 for (var i = 0; i < sms_content.length; i++) {
1087 tmpchr = sms_content.charAt(i);
1088 length = length + 1;
1089 if ((tmpchr == "[") || (tmpchr == "]") || (tmpchr == "{") || (tmpchr == "}") || (tmpchr == "|") || (tmpchr == "\\") || (tmpchr == "^") || (tmpchr == "~") || (tmpchr == "€")) {
1090 length = length + 1;
1091 }
1092 index = i;
1093 if (length == 765) {
1094 break;
1095 }
1096 if (length > 765) {
1097 index = i - 1;
1098 length = length - 2;
1099 break;
1100 }
1101 }
1102 return {
1103 index: index,
1104 length: length
1105 };
1106}
1107function clearValidateMsg(areaId) {
1108 areaId = areaId || '*';
1109 $(areaId + ' label.error').remove();
1110}
1111function isErrorObject(object) {
1112 return typeof object.errorType === 'string';
1113}
1114var manualLogout = false;