mirror of
https://github.com/Doodle3D/doodle3d-connect.git
synced 2024-12-26 02:23:48 +01:00
add feature to re-associate with a known network without having to type the password
This commit is contained in:
parent
c83eff6eb1
commit
b424daf038
@ -41,11 +41,11 @@
|
|||||||
var form = data.prevPage.find("form");
|
var form = data.prevPage.find("form");
|
||||||
// check if there are url params and
|
// check if there are url params and
|
||||||
// when encrypted if there was a form from a prev page
|
// when encrypted if there was a form from a prev page
|
||||||
if(_pageData.encryption === "") {
|
if (_pageData.encryption === "") {
|
||||||
_pageData.encryption = "none";
|
_pageData.encryption = "none";
|
||||||
}
|
}
|
||||||
if(_pageData === undefined ||
|
if (_pageData === undefined) { // || (_pageData.encryption !== "none" && form.length === 0)) {
|
||||||
(_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");
|
$.mobile.changePage("#boxes");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -84,8 +84,9 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
function joinNetwork() {
|
function joinNetwork() {
|
||||||
console.log(PAGE_ID+":joinNetwork");
|
console.log(PAGE_ID+":joinNetwork",_formData.password);
|
||||||
_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;
|
_connectedChecking = false;
|
||||||
}
|
}
|
||||||
function onRefreshing() {
|
function onRefreshing() {
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
var _networkAPI = new NetworkAPI();
|
var _networkAPI = new NetworkAPI();
|
||||||
var _boxData = {};
|
var _boxData = {};
|
||||||
var _refreshDelay;
|
var _refreshDelay;
|
||||||
|
var _knownSSIDs;
|
||||||
var _refreshDelayTime = 3000;
|
var _refreshDelayTime = 3000;
|
||||||
var PAGE_ID = "#join_network";
|
var PAGE_ID = "#join_network";
|
||||||
|
|
||||||
@ -25,7 +26,8 @@
|
|||||||
_page = $(this);
|
_page = $(this);
|
||||||
_list = _page.find("ul[data-role=listview]");
|
_list = _page.find("ul[data-role=listview]");
|
||||||
//_joinOtherItem = _list.find("#joinOther");
|
//_joinOtherItem = _list.find("#joinOther");
|
||||||
});
|
});
|
||||||
|
|
||||||
$.mobile.document.on( "pagebeforeshow", PAGE_ID, function( event, data ) {
|
$.mobile.document.on( "pagebeforeshow", PAGE_ID, function( event, data ) {
|
||||||
console.log("Join network page pagebeforeshow");
|
console.log("Join network page pagebeforeshow");
|
||||||
_boxData = d3d.util.getPageParams(PAGE_ID);
|
_boxData = d3d.util.getPageParams(PAGE_ID);
|
||||||
@ -37,12 +39,22 @@
|
|||||||
console.log(" _boxData: ",_boxData);
|
console.log(" _boxData: ",_boxData);
|
||||||
|
|
||||||
_networkAPI.init(boxURL);
|
_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 ) {
|
$.mobile.document.on( "pagebeforehide", PAGE_ID, function( event, data ) {
|
||||||
console.log("Join network page pagehide");
|
console.log("Join network page pagehide");
|
||||||
clearTimeout(_refreshDelay);
|
clearTimeout(_refreshDelay);
|
||||||
});
|
});
|
||||||
|
|
||||||
function refreshNetworks() {
|
function refreshNetworks() {
|
||||||
//console.log("JoinNetwork:refreshNetworks");
|
//console.log("JoinNetwork:refreshNetworks");
|
||||||
d3d.util.showLoader();
|
d3d.util.showLoader();
|
||||||
@ -50,7 +62,9 @@
|
|||||||
//console.log("JoinNetwork:refreshNetworks:scanned");
|
//console.log("JoinNetwork:refreshNetworks:scanned");
|
||||||
d3d.util.hideLoader();
|
d3d.util.hideLoader();
|
||||||
_networks = {};
|
_networks = {};
|
||||||
|
// console.log('_knownSSIDs',_knownSSIDs);
|
||||||
$.each(data.networks, function(index,network) {
|
$.each(data.networks, function(index,network) {
|
||||||
|
network.known = _knownSSIDs.indexOf(network.ssid)>-1;
|
||||||
_networks[network.ssid] = network;
|
_networks[network.ssid] = network;
|
||||||
});
|
});
|
||||||
// update list
|
// update list
|
||||||
@ -66,25 +80,42 @@
|
|||||||
var baseSecuredLink = _list.data("secured-target");
|
var baseSecuredLink = _list.data("secured-target");
|
||||||
var linkParams = $.extend({}, _boxData);
|
var linkParams = $.extend({}, _boxData);
|
||||||
//console.log(" linkParams: ",linkParams);
|
//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;
|
linkParams.ssid = network.ssid;
|
||||||
|
|
||||||
var secured = (network.encryption !== "none" && network.encryption !== "");
|
var secured = (network.encryption !== "none" && network.encryption !== "");
|
||||||
var link;
|
var link;
|
||||||
var icon = "";
|
var icon = secured ? "lock" : "alert";
|
||||||
linkParams.encryption = network.encryption;
|
linkParams.encryption = network.encryption;
|
||||||
if(secured) {
|
|
||||||
link = d3d.util.replaceURLParameters(baseSecuredLink,linkParams);
|
if (!secured || network.known) { //skip the password page
|
||||||
icon = "lock";
|
|
||||||
} else {
|
|
||||||
link = d3d.util.replaceURLParameters(baseConnectingLink,linkParams);
|
link = d3d.util.replaceURLParameters(baseConnectingLink,linkParams);
|
||||||
|
} else {
|
||||||
|
link = d3d.util.replaceURLParameters(baseSecuredLink,linkParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log(" link: ",link);
|
//console.log(" link: ",link);
|
||||||
|
|
||||||
|
var className = (network.known ? 'knownNetwork' : ''); //previously joined
|
||||||
|
|
||||||
_list.append(
|
_list.append(
|
||||||
$('<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.append(_joinOtherItem);
|
||||||
_list.listview('refresh'); // jQuery mobile enhance content
|
_list.listview('refresh'); // jQuery mobile enhance content
|
||||||
}
|
}
|
||||||
|
@ -53,18 +53,39 @@ function NetworkAPI() {
|
|||||||
timeout: _timeoutTime,
|
timeout: _timeoutTime,
|
||||||
success: function(response){
|
success: function(response){
|
||||||
//console.log("NetworkAPI:scan response: ",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);
|
//console.log("NetworkAPI:scan failed: ",response);
|
||||||
if(failedHandler) failedHandler(response);
|
if (failedHandler) failedHandler(response);
|
||||||
} else {
|
} else {
|
||||||
completeHandler(response.data);
|
if (completeHandler) completeHandler(response.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).fail(function() {
|
}).fail(function() {
|
||||||
//console.log("NetworkAPI:scan failed");
|
//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) {
|
this.status = function(completeHandler,failedHandler) {
|
||||||
//console.log("NetworkAPI:status");
|
//console.log("NetworkAPI:status");
|
||||||
// After switching wifi network or creating a access point we delay the actual 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);
|
console.log(" phrase: ",phrase);
|
||||||
var postData = {
|
var postData = {
|
||||||
ssid:ssid,
|
ssid:ssid,
|
||||||
phrase:phrase,
|
phrase:phrase
|
||||||
recreate:recreate
|
|
||||||
};
|
};
|
||||||
|
// recreate:recreate //RC: when passing 'false' to the API it is still interpreteted as 'true'
|
||||||
|
// };
|
||||||
|
console.log('postData',postData);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: _wifiboxCGIBinURL + "/network/associate",
|
url: _wifiboxCGIBinURL + "/network/associate",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
@ -154,10 +177,10 @@ function NetworkAPI() {
|
|||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
timeout: _timeoutTime,
|
timeout: _timeoutTime,
|
||||||
success: function(response){
|
success: function(response){
|
||||||
//console.log("NetworkAPI:associate response: ",response);
|
// console.log("NetworkAPI:associate response: ",response);
|
||||||
}
|
}
|
||||||
}).fail(function() {
|
}).fail(function() {
|
||||||
//console.log("NetworkAPI:associate: timeout (normal behavior)");
|
// console.log("NetworkAPI:associate: timeout (normal behavior)");
|
||||||
});
|
});
|
||||||
_associateTime = new Date().getTime();
|
_associateTime = new Date().getTime();
|
||||||
};
|
};
|
||||||
|
@ -210,4 +210,8 @@ html head + body .ui-body-a.ui-focus {
|
|||||||
.ath-container:before {
|
.ath-container:before {
|
||||||
color: #F18DB1;
|
color: #F18DB1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
li.knownNetwork a {
|
||||||
|
color: #5fba7d !important;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user