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( - $('