diff --git a/js/ConnectingToNetworkPage.js b/js/ConnectingToNetworkPage.js index b25c61d..3a731a2 100644 --- a/js/ConnectingToNetworkPage.js +++ b/js/ConnectingToNetworkPage.js @@ -41,11 +41,11 @@ var form = data.prevPage.find("form"); // check if there are url params and // when encrypted if there was a form from a prev page - if(_pageData.encryption === "") { + if (_pageData.encryption === "") { _pageData.encryption = "none"; } - if(_pageData === undefined || - (_pageData.encryption !== "none" && form.length === 0)) { + if (_pageData === undefined) { // || (_pageData.encryption !== "none" && form.length === 0)) { + //RC: removed this check because it makes it more difficult to re-associate with a known network $.mobile.changePage("#boxes"); return; } @@ -84,8 +84,9 @@ }); } function joinNetwork() { - console.log(PAGE_ID+":joinNetwork"); - _networkAPI.associate(_pageData.ssid,_formData.password,true); + console.log(PAGE_ID+":joinNetwork",_formData.password); + //_networkAPI.associate(_pageData.ssid,_formData.password,true); //recreate=true + _networkAPI.associate(_pageData.ssid,_formData.password,false); _connectedChecking = false; } function onRefreshing() { diff --git a/js/JoinNetworkPage.js b/js/JoinNetworkPage.js index 199d819..a7017be 100644 --- a/js/JoinNetworkPage.js +++ b/js/JoinNetworkPage.js @@ -15,6 +15,7 @@ var _networkAPI = new NetworkAPI(); var _boxData = {}; var _refreshDelay; + var _knownSSIDs; var _refreshDelayTime = 3000; var PAGE_ID = "#join_network"; @@ -25,7 +26,8 @@ _page = $(this); _list = _page.find("ul[data-role=listview]"); //_joinOtherItem = _list.find("#joinOther"); - }); + }); + $.mobile.document.on( "pagebeforeshow", PAGE_ID, function( event, data ) { console.log("Join network page pagebeforeshow"); _boxData = d3d.util.getPageParams(PAGE_ID); @@ -37,12 +39,22 @@ console.log(" _boxData: ",_boxData); _networkAPI.init(boxURL); - refreshNetworks(); - }); + + _networkAPI.knownSSIDs(function(successData) { + console.log("known",successData); + _knownSSIDs = successData; + refreshNetworks(); + },function(failData) { + console.log("known networks fail"); + }); + + }); + $.mobile.document.on( "pagebeforehide", PAGE_ID, function( event, data ) { console.log("Join network page pagehide"); clearTimeout(_refreshDelay); - }); + }); + function refreshNetworks() { //console.log("JoinNetwork:refreshNetworks"); d3d.util.showLoader(); @@ -50,7 +62,9 @@ //console.log("JoinNetwork:refreshNetworks:scanned"); d3d.util.hideLoader(); _networks = {}; + // console.log('_knownSSIDs',_knownSSIDs); $.each(data.networks, function(index,network) { + network.known = _knownSSIDs.indexOf(network.ssid)>-1; _networks[network.ssid] = network; }); // update list @@ -66,25 +80,42 @@ var baseSecuredLink = _list.data("secured-target"); var linkParams = $.extend({}, _boxData); //console.log(" linkParams: ",linkParams); - $.each(_networks, function(index,network) { - //console.log(" network: ",network); + + var _ssids = $.map(_networks, function(obj) { + return obj.ssid; + }); + + _ssids.sort(function(a, b) { + return a.toLowerCase().localeCompare(b.toLowerCase()); + }); + + // $.each(_ssids, function(ssid) { + for (var i=0; i<_ssids.length; i++) { + var ssid = _ssids[i]; + + var network = _networks[ssid]; + linkParams.ssid = network.ssid; var secured = (network.encryption !== "none" && network.encryption !== ""); var link; - var icon = ""; + var icon = secured ? "lock" : "alert"; linkParams.encryption = network.encryption; - if(secured) { - link = d3d.util.replaceURLParameters(baseSecuredLink,linkParams); - icon = "lock"; - } else { + + if (!secured || network.known) { //skip the password page link = d3d.util.replaceURLParameters(baseConnectingLink,linkParams); + } else { + link = d3d.util.replaceURLParameters(baseSecuredLink,linkParams); } + //console.log(" link: ",link); + + var className = (network.known ? 'knownNetwork' : ''); //previously joined + _list.append( - $('
  • '+network.ssid+'
  • ') + $('
  • '+network.ssid+'
  • ') ); - }); + } //_list.append(_joinOtherItem); _list.listview('refresh'); // jQuery mobile enhance content } diff --git a/js/api/NetworkAPI.js b/js/api/NetworkAPI.js index 12befa5..201a96b 100644 --- a/js/api/NetworkAPI.js +++ b/js/api/NetworkAPI.js @@ -53,18 +53,39 @@ function NetworkAPI() { timeout: _timeoutTime, success: function(response){ //console.log("NetworkAPI:scan response: ",response); - if(response.status == "error" || response.status == "fail") { + if (response.status == "error" || response.status == "fail") { //console.log("NetworkAPI:scan failed: ",response); - if(failedHandler) failedHandler(response); + if (failedHandler) failedHandler(response); } else { - completeHandler(response.data); + if (completeHandler) completeHandler(response.data); } } }).fail(function() { //console.log("NetworkAPI:scan failed"); - if(failedHandler) failedHandler(); + if (failedHandler) failedHandler(); }); }; + + this.knownSSIDs = function(completeHandler,failedHandler) { + $.ajax({ + url: _wifiboxURL + "/network/known", + type: "GET", + dataType: 'json', + timeout: _timeoutTime, + success: function(response){ + if (response.status == "error" || response.status == "fail") { + if (failedHandler) failedHandler(response); + } else { + if (completeHandler) completeHandler(response.data.networks.map(function(obj) { + return obj.ssid; + })); + } + } + }).fail(function() { + if (failedHandler) failedHandler(); + }); + }; + this.status = function(completeHandler,failedHandler) { //console.log("NetworkAPI:status"); // After switching wifi network or creating a access point we delay the actual status @@ -144,9 +165,11 @@ function NetworkAPI() { console.log(" phrase: ",phrase); var postData = { ssid:ssid, - phrase:phrase, - recreate:recreate + phrase:phrase }; + // recreate:recreate //RC: when passing 'false' to the API it is still interpreteted as 'true' + // }; + console.log('postData',postData); $.ajax({ url: _wifiboxCGIBinURL + "/network/associate", type: "POST", @@ -154,10 +177,10 @@ function NetworkAPI() { dataType: 'json', timeout: _timeoutTime, success: function(response){ - //console.log("NetworkAPI:associate response: ",response); + // console.log("NetworkAPI:associate response: ",response); } }).fail(function() { - //console.log("NetworkAPI:associate: timeout (normal behavior)"); + // console.log("NetworkAPI:associate: timeout (normal behavior)"); }); _associateTime = new Date().getTime(); }; diff --git a/less/styles.less b/less/styles.less index 69d7c80..9f672f3 100644 --- a/less/styles.less +++ b/less/styles.less @@ -210,4 +210,8 @@ html head + body .ui-body-a.ui-focus { .ath-container:before { color: #F18DB1; } -} \ No newline at end of file +} + +li.knownNetwork a { + color: #5fba7d !important; +}