mirror of
https://github.com/Doodle3D/doodle3d-connect.git
synced 2024-12-25 01:53:48 +01:00
re-associate / reconnect to known networks
This commit is contained in:
parent
7db7086a25
commit
46ac18e817
@ -44,8 +44,10 @@
|
||||
if(_pageData.encryption === "") {
|
||||
_pageData.encryption = "none";
|
||||
}
|
||||
if(_pageData === undefined ||
|
||||
(_pageData.encryption !== "none" && form.length === 0)) {
|
||||
// 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;
|
||||
}
|
||||
@ -85,7 +87,8 @@
|
||||
}
|
||||
function joinNetwork() {
|
||||
console.log(PAGE_ID+":joinNetwork");
|
||||
_networkAPI.associate(_pageData.ssid,_formData.password,true);
|
||||
//_networkAPI.associate(_pageData.ssid,_formData.password,true); //recreate=true
|
||||
_networkAPI.associate(_pageData.ssid,_formData.password,false);
|
||||
_connectedChecking = false;
|
||||
}
|
||||
function onRefreshing() {
|
||||
|
@ -15,6 +15,7 @@
|
||||
var _networkAPI = new NetworkAPI();
|
||||
var _boxData = {};
|
||||
var _refreshDelay;
|
||||
var _knownSSIDs;
|
||||
var _refreshDelayTime = 3000;
|
||||
var PAGE_ID = "#join_network";
|
||||
|
||||
@ -26,6 +27,7 @@
|
||||
_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,20 +39,32 @@
|
||||
console.log(" _boxData: ",_boxData);
|
||||
|
||||
_networkAPI.init(boxURL);
|
||||
|
||||
_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();
|
||||
_networkAPI.scan(function(data) { // completed
|
||||
//console.log("JoinNetwork:refreshNetworks:scanned");
|
||||
// console.log("JoinNetwork:refreshNetworks:scanned");
|
||||
// console.log(data);
|
||||
d3d.util.hideLoader();
|
||||
_networks = {};
|
||||
$.each(data.networks, function(index,network) {
|
||||
network.known = _knownSSIDs.indexOf(network.ssid)>-1;
|
||||
_networks[network.ssid] = network;
|
||||
});
|
||||
// update list
|
||||
@ -60,32 +74,53 @@
|
||||
_refreshDelay = setTimeout(refreshNetworks, _refreshDelayTime);
|
||||
});
|
||||
}
|
||||
|
||||
function updateList() {
|
||||
_list.empty();
|
||||
var baseConnectingLink = _list.data("connecting-target");
|
||||
var baseSecuredLink = _list.data("secured-target");
|
||||
var linkParams = $.extend({}, _boxData);
|
||||
//console.log(" linkParams: ",linkParams);
|
||||
$.each(_networks, function(index,network) {
|
||||
// $.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);
|
||||
}
|
||||
|
||||
var className = (network.known ? 'knownNetwork' : ''); //previously joined
|
||||
|
||||
//console.log(" link: ",link);
|
||||
_list.append(
|
||||
$('<li data-icon="'+icon+'"><a href="'+link+'">'+network.ssid+'</a></li>')
|
||||
// $('<li data-icon="'+icon+'"><a href="'+link+'">'+network.ssid+'</a></li>')
|
||||
$('<li class="'+className+'" data-icon="'+icon+'"><a href="'+link+'">'+network.ssid+'</a></li>')
|
||||
);
|
||||
});
|
||||
}
|
||||
//_list.append(_joinOtherItem);
|
||||
_list.listview('refresh'); // jQuery mobile enhance content
|
||||
}
|
||||
|
||||
})(window);
|
@ -57,7 +57,7 @@ function NetworkAPI() {
|
||||
//console.log("NetworkAPI:scan failed: ",response);
|
||||
if(failedHandler) failedHandler(response);
|
||||
} else {
|
||||
completeHandler(response.data);
|
||||
if (completeHandler) completeHandler(response.data);
|
||||
}
|
||||
}
|
||||
}).fail(function() {
|
||||
@ -65,6 +65,31 @@ function NetworkAPI() {
|
||||
if(failedHandler) failedHandler();
|
||||
});
|
||||
};
|
||||
|
||||
this.knownSSIDs = function(completeHandler,failedHandler) {
|
||||
$.ajax({
|
||||
url: _wifiboxURL + "/network/known",
|
||||
type: "GET",
|
||||
dataType: 'json',
|
||||
timeout: _timeoutTime,
|
||||
success: function(response){
|
||||
console.log("knownSSIDs",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() {
|
||||
console.log("knownSSIDs fail");
|
||||
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,8 +169,7 @@ function NetworkAPI() {
|
||||
console.log(" phrase: ",phrase);
|
||||
var postData = {
|
||||
ssid:ssid,
|
||||
phrase:phrase,
|
||||
recreate:recreate
|
||||
phrase:phrase
|
||||
};
|
||||
$.ajax({
|
||||
url: _wifiboxCGIBinURL + "/network/associate",
|
||||
|
@ -250,3 +250,6 @@ html head + body .ui-body-a.ui-focus {
|
||||
/*color: #93CAF4;*/
|
||||
}
|
||||
|
||||
li.knownNetwork a {
|
||||
color: #5fba7d !important;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user