From d224eb87d8ef8a0e29b0d68049c75eb4515ca16d Mon Sep 17 00:00:00 2001 From: Jimmy Huang Date: Tue, 4 Mar 2014 11:46:23 -0800 Subject: [PATCH] Fixes TIVI-2825 - WiFi/Wired status not stable Fixes an issue where everytime the connman page is loaded, the technology buttons turns off and on, because it removes all the html5 elements and then recreates them later. Now it's smart enough to only create the element if the element doesn't exist, or it will just update its existing status. Change-Id: I00f4fffe3aa5220db5f17a7cf8797b5e9ac76469 Signed-off-by: Jimmy Huang --- index.html | 9 --------- js/panel-connman.js | 43 ++++++++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/index.html b/index.html index 8875445..da8eb80 100644 --- a/index.html +++ b/index.html @@ -85,15 +85,6 @@

Technologies

-
    -
  • - - -
  • -
    diff --git a/js/panel-connman.js b/js/panel-connman.js index 8d1ac8b..c093d23 100644 --- a/js/panel-connman.js +++ b/js/panel-connman.js @@ -17,7 +17,6 @@ function connmanPanelInit() { wsAPI.subscribeEvents(connmanEventReceived); console.log('Get all the available technologies'); - $('#connman_technologies').html(''); settings.connman.getTechnologies(function(technologies) { for (var i = 0; i < technologies.length; i++) { var technology = technologies[i]; @@ -30,14 +29,26 @@ function connmanPanelInit() { (function(t) { t.getPowered(function(is_powered) { t.prop.Powered = is_powered; - connmanConstructTechnologyElement(t); + if ($('#toggle_connman_' + t.prop.Type).length <= 0) { + /* element doesn't exist, create it */ + connmanConstructTechnologyElement(t); + } else { + /* element already exist */ + connmanToggleTechnology(t.prop.Type, is_powered); + } }, function(e) { t.prop.Powered = false; connmanConstructTechnologyElement(t); }); })(technology); } else { - connmanConstructTechnologyElement(technology); + if ($('#toggle_connman_' + technology.prop.Type).length <= 0) { + /* element doesn't exist, create it */ + connmanConstructTechnologyElement(technology); + } else { + /* element already exist */ + connmanToggleTechnology(technology.prop.Type, technology.prop.Powered); + } } } }, function(e) { @@ -213,7 +224,7 @@ function connmanHandlePropertyChanged(id, property) { var index = id.lastIndexOf('/'); var technology = id.substring(index + 1); if (property[1] === true) { - connmanToggleOn(technology); + connmanToggleTechnology(technology, true); if (technology === 'wifi') { setTimeout(function() { /* add a 1 sec delay */ @@ -221,7 +232,7 @@ function connmanHandlePropertyChanged(id, property) { }, 1000); } } else { - connmanToggleOff(technology); + connmanToggleTechnology(technology, false); } } @@ -398,7 +409,7 @@ function connmanConstructTechnologyElement(technology) { console.log('Connman technology ' + technology.prop.Type + ' is powered: ' + technology.prop.Powered); if (technology.prop.Powered) { - connmanToggleOn(technology.prop.Type); + connmanToggleTechnology(technology.prop.Type, true); if ($('ul#listview_services_available li').length === 0) { /* connman only supports wifi scan */ if (technology.prop.Type === 'wifi') { @@ -410,7 +421,7 @@ function connmanConstructTechnologyElement(technology) { } } } else { - connmanToggleOff(technology.prop.Type); + connmanToggleTechnology(technology.prop.Type, false); } $('#toggle_connman_' + technology.prop.Type).change(function() { @@ -757,17 +768,15 @@ function connmanUpdateServicePanel(service) { $('#listview_connman_service').listview('refresh'); } -function connmanToggleOn(technology_type) { +function connmanToggleTechnology(technology_type, powered) { setTimeout(function() { - $('#toggle_connman_' + technology_type).val('on').slider('refresh'); - console.log('Turn on toggle #toggle_connman_' + technology_type); - }, 1000); -} - -function connmanToggleOff(technology_type) { - setTimeout(function() { - $('#toggle_connman_' + technology_type).val('off').slider('refresh'); - console.log('Turn off toggle #toggle_connman_' + technology_type); + if (powered) { + $('#toggle_connman_' + technology_type).val('on').slider('refresh'); + console.log('Turn on toggle #toggle_connman_' + technology_type); + } else { + $('#toggle_connman_' + technology_type).val('off').slider('refresh'); + console.log('Turn off toggle #toggle_connman_' + technology_type); + } }, 1000); } -- 2.7.4