Fixes TIVI-2825 - WiFi/Wired status not stable 71/17171/1
authorJimmy Huang <jimmy.huang@intel.com>
Tue, 4 Mar 2014 19:46:23 +0000 (11:46 -0800)
committerJimmy Huang <jimmy.huang@intel.com>
Tue, 4 Mar 2014 19:46:23 +0000 (11:46 -0800)
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 <jimmy.huang@intel.com>
index.html
js/panel-connman.js

index 8875445..da8eb80 100644 (file)
                 <p>Technologies</p>
             </div>
             <div id="connman_technologies">
-                <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
-                    <li data-role="fieldcontain">
-                        <label for="toggle_connman_wifi" class="ui-slider">WiFi</label>
-                        <select data-role="slider" name="toggle_connman_wifi" id="toggle_connman_wifi" class="ui-slider-switch">
-                            <option value="off">Off</option>
-                            <option value="on">On</option>
-                        </select>
-                    </li>
-                </ul>
             </div>
             <div id="connman_tethering">
                 <ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset">
index 8d1ac8b..c093d23 100644 (file)
@@ -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);
 }