123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- function logswitchGenPage() {
- var page = '<div id="logswitch_page">\
- <div class="maintitle">\
- <div>硬件适配器日志记录管理</div>\
- <div class="page_description_text">本地临时打开硬件适配器日志记录,方便及时排查硬件问题。有改动更新需重启应用方能生效。\
- </div>\
- </div>\
- <div id="logswitchContent" class="hide" style="display: block;">\
- </div>\
- </div>';
- $("#rightpagearea").prepend(page);
- if (typeof logswitchRenderPage == "function") {
- beforeRenderPage("logswitch");
- logswitchRenderPage();
- afterRenderPage("logswitch");
- }
- }
- var logswitchController = (function() {
- var devSectionPlaceHolder = '<div id="log_switch_{{devName}}_section" class="wps_connect_way_title " style="margin-top: 40px; padding-top: 40px;">{{devSectionName}}</div>\
- <div id="log_switch_{{devName}}_section_description" class="three_way_instruction maintitle" style="padding-bottom: 0px !important;" > </div>\
- <div id="log_switch_{{devName}}_switch_div" class="clearboth" style="padding-top: 15px;">\
- <div class="control-label" style="margin-top:3px;">\
- <span>日志开关</span>\
- </div>\
- <div class="controls">\
- <div id="log_switch_{{devName}}_switch" onclick="SwitchEx(this, RVC.VendorLogSwitchController.LogSwitch)" class="switch_on"></div>\
- </div>\
- </div>\
- <div id="log_switch_{{devName}}_level" class="clearboth" style="padding-top: 15px;">\
- <div class="control-label" style="margin-top:3px;">\
- <span>日志等级</span>\
- </div>\
- <div class="controls">\
- <div id="log_switch_{{devName}}_log_level_select_all">\
- <div id="log_switch_{{devName}}_log_level_select" class="select_on_normal" value="0" onclick="SelectItem(this)"></div>\
- <div id="log_switch_{{devName}}_log_level_select_list" class="select_list hide" style="display: none;">\
- <div id="log_switch_{{devName}}_log_level_select_list_item_fatal" option="1" class="select_medium" onclick=\"RVC.VendorLogSwitchController.LogLevelChange(this, \'1\')\">Fatal</div>\
- <div id="log_switch_{{devName}}_log_level_select_list_item_error" option="2" class="select_medium" onclick=\"RVC.VendorLogSwitchController.LogLevelChange(this, \'2\')\">Error</div>\
- <div id="log_switch_{{devName}}_log_level_select_list_item_warn" option="3" class="select_medium" onclick=\"RVC.VendorLogSwitchController.LogLevelChange(this, \'3\')\">Warn</div>\
- <div id="log_switch_{{devName}}_log_level_select_list_item_info" option="4" class="select_medium" onclick=\"RVC.VendorLogSwitchController.LogLevelChange(this, \'4\')\">Info</div>\
- <div id="log_switch_{{devName}}_log_level_select_list_item_trace" option="5" class="select_medium" onclick=\"RVC.VendorLogSwitchController.LogLevelChange(this, \'5\')\">Trace</div>\
- </div>\
- </div>\
- </div>\
- </div>';
- var hardwares = [];
- function SwithDevAdapterLogRecord(adapterName, record_on, record_level, failCallback)
- {
- let req = new Request();
- req.configType = 7; //GlobalCache
- req.section = 'AdapterLogSwith';
- req.option = true; //Write
- req.key = adapterName;
- req.reserved1 = 0;
- req.reserved2 = 0;
- if(record_on) {
- req.reserved3 = '1,' + record_level;
- } else {
- req.reserved3 = '0,' + record_level;
- }
- req.reserved4 = '';
- RVC.DeviceControlEntityCtrl.ReadConfigValue(req, function(ret) {
- if (ret.errorCode === 0) {
- utilShowToast('设置成功!');
- } else {
- utilStartAlertDialog("设置失败! ErrorCode: " + ErrorCodeStringfy(ret.errorCode), function(){
- if(failCallback) {
- failCallback();
- }
- });
- }
- });
- }
- RVC.VendorLogSwitchController = RVC.ObjController.extend({
- LogLevelChange: function(widget, value) {
- var thatWidget = widget;
- var hardwareName = '';
- for(var i=0; i<hardwares.length; ++i) {
- if(-1 !== widget.id.indexOf(hardwares[i])) {
- hardwareName = hardwares[i];
- console.log(widget.id + " " + widget.className + ' ' + hardwareName);
- break;
- }
- }
- if(hardwareName === '') {
- return;
- }
- var switchon = true;
- var switch_id = 'log_switch_' + hardwareName + '_switch';
- var classlist = $('#' + switch_id).attr('class');
- if (classlist.indexOf('switch_on') < 0) {
- switchon = false;
- }
- var recordLevel = value;
- SwithDevAdapterLogRecord(hardwareName, switchon, recordLevel);
- },
- LogSwitch: function(widget) {
- var thatWidget = widget;
- var switchon = false;
- var hardwareName = '';
- for(var i=0; i<hardwares.length; ++i) {
- if(-1 !== widget.id.indexOf(hardwares[i])) {
- hardwareName = hardwares[i];
- console.log(widget.id + " " + widget.className + ' ' + hardwareName);
- break;
- }
- }
- if(hardwareName === '') {
- return;
- }
- var classlist = $(widget).attr('class');
- if (classlist.indexOf('switch_on') >= 0) {
- switchon = true;
- }
- var select_id = 'log_switch_' + hardwareName + '_log_level_select';
- setSelectWidgetEnableState(select_id, switchon);
- var recordLevel = $('#' + select_id).attr('value');
- SwithDevAdapterLogRecord(hardwareName, switchon, recordLevel, function() {
- setSelectWidgetEnableState(select_id, !switchon);
- Switch(thatWidget);
- });
- }
- });
- function initEachDevLogStatus(index) {
- if(index >= hardwares.length) {
- return;
- }
- const adapterName = hardwares[index];
- var switch_id = 'log_switch_' + adapterName + '_switch';
- var select_id = 'log_switch_' + adapterName + '_log_level_select';
- console.log('adapterName: ' + adapterName + ' ' + switch_id + ' ' + select_id);
- let req = new Request();
- req.configType = 7; //GlobalCache
- req.section = 'AdapterLogSwith';
- req.option = false;
- req.key = adapterName;
- req.reserved1 = 0;
- req.reserved2 = 0;
- req.reserved3 = '';
- req.reserved4 = '';
- RVC.DeviceControlEntityCtrl.ReadConfigValue(req, function(ret) {
- if (ret.errorCode === 0) {
-
- var recordOn = false;
- var recordLevel = '2';
- let result = JSON.parse(ret[RVC.EntityController.sigResponseUUID])
- console.log(adapterName + ': ' + result.value);
- if(result.value !== '') {
- var values = result.value.split(',');
- if(values.length >= 1 && parseInt(values[0]) > 0) {
- recordOn = true;
- }
- if(values.length >= 2) {
- recordLevel = (values[1]);
- }
- }
- setSwitchState(switch_id, recordOn);
- showSelectedValue(select_id, recordLevel);
- setSelectWidgetEnableState(select_id, recordOn);
- //setSwitchEnableState(switch_id, true);
- //setSelectWidgetEnableState(select_id, true);
- } else {
- setSwitchEnableState(switch_id, false);
- setSelectWidgetEnableState(select_id, false);
- }
- initEachDevLogStatus(index+1);
- });
- }
- function initPage() {
- for (var i = 0; i < gMenu.length; i++) {
- var menuitems = gMenu[i];
- var hash = menuitems.pagename;
- if(hash === 'hardwareconfig') {
- if (menuitems.submenus) {
- var subitems = menuitems.submenus;
- for(var j = 0; j < subitems.length; j++) {
- hash = subitems[j].pagename;
- if(hash === 'adapters') {
- if (typeof subitems[j].submenus !== 'undefined') {
- var thrditems = subitems[j].submenus;
- for(var k = 0; k <thrditems.length; ++k) {
- hash = subitems[j].submenus[k].pagename;
- hardwares.push(hash);
- }
- }
- }
- }
- }
- }
- }
- for(var i=0; i<hardwares.length; ++i) {
- console.log('hash1: ' + hardwares[i]);
- var templateData = {
- devName: hardwares[i],
- devSectionName: gMenuDisplayName[hardwares[i]]
- };
- $('#logswitchContent').secureAppend(devSectionPlaceHolder, templateData);
-
- }
- setTimeout(function () {
- // for(var i=0; i<hardwares.length; ++i) {
- // const adapterName = hardwares[i];
- // var switch_id = 'log_switch_' + adapterName + '_switch';
- // var select_id = 'log_switch_' + adapterName + '_log_level_select';
- // setSwitchEnableState(switch_id, false);
- // setSelectWidgetEnableState(select_id, false);
- // }
- initEachDevLogStatus(0);
- }, 500);
- }
- var fistTime = true;
- function init() {
- if (fistTime) {
- fistTime = false;
- }
- initPage();
- }
-
- return { init: init };
- }());
- window.logswitchRenderPage = function () {
- logswitchController.init();
- };
|