2014-04-25 16:24:25 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the Doodle3D project (http://doodle3d.com).
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013, Doodle3D
|
|
|
|
* This software is licensed under the terms of the GNU GPL v2 or later.
|
|
|
|
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
|
|
|
*/
|
|
|
|
|
2014-05-12 14:44:21 +02:00
|
|
|
(function (w) {
|
2014-04-25 16:24:25 +02:00
|
|
|
|
|
|
|
var _page;
|
|
|
|
var _list;
|
2014-05-01 13:12:30 +02:00
|
|
|
//var _joinOtherItem;
|
2014-04-25 16:24:25 +02:00
|
|
|
var _networks;
|
|
|
|
var _networkAPI = new NetworkAPI();
|
|
|
|
var _boxData = {};
|
|
|
|
var _refreshDelay;
|
2017-06-21 11:35:29 +02:00
|
|
|
var _knownSSIDs;
|
2014-04-25 16:24:25 +02:00
|
|
|
var _refreshDelayTime = 3000;
|
|
|
|
var PAGE_ID = "#join_network";
|
|
|
|
|
|
|
|
var _self = this;
|
|
|
|
|
|
|
|
$.mobile.document.on( "pageinit", PAGE_ID, function( event, data ) {
|
|
|
|
console.log("Join network page pageinit");
|
|
|
|
_page = $(this);
|
|
|
|
_list = _page.find("ul[data-role=listview]");
|
2014-05-01 13:12:30 +02:00
|
|
|
//_joinOtherItem = _list.find("#joinOther");
|
2017-06-21 11:35:29 +02:00
|
|
|
});
|
|
|
|
|
2014-04-25 16:24:25 +02:00
|
|
|
$.mobile.document.on( "pagebeforeshow", PAGE_ID, function( event, data ) {
|
|
|
|
console.log("Join network page pagebeforeshow");
|
|
|
|
_boxData = d3d.util.getPageParams(PAGE_ID);
|
2014-05-14 12:00:02 +02:00
|
|
|
if(_boxData === undefined) {
|
|
|
|
$.mobile.changePage("#boxes");
|
|
|
|
return;
|
|
|
|
}
|
2014-04-25 16:24:25 +02:00
|
|
|
var boxURL = "http://"+_boxData.localip;
|
|
|
|
console.log(" _boxData: ",_boxData);
|
|
|
|
|
|
|
|
_networkAPI.init(boxURL);
|
2017-06-21 11:35:29 +02:00
|
|
|
|
|
|
|
_networkAPI.knownSSIDs(function(successData) {
|
|
|
|
console.log("known",successData);
|
|
|
|
_knownSSIDs = successData;
|
|
|
|
refreshNetworks();
|
|
|
|
},function(failData) {
|
|
|
|
console.log("known networks fail");
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-05-12 14:53:01 +02:00
|
|
|
$.mobile.document.on( "pagebeforehide", PAGE_ID, function( event, data ) {
|
2014-04-25 16:24:25 +02:00
|
|
|
console.log("Join network page pagehide");
|
|
|
|
clearTimeout(_refreshDelay);
|
2017-06-21 11:35:29 +02:00
|
|
|
});
|
|
|
|
|
2014-04-25 16:24:25 +02:00
|
|
|
function refreshNetworks() {
|
2014-05-01 13:12:30 +02:00
|
|
|
//console.log("JoinNetwork:refreshNetworks");
|
2014-04-25 16:24:25 +02:00
|
|
|
d3d.util.showLoader();
|
|
|
|
_networkAPI.scan(function(data) { // completed
|
2014-05-01 13:12:30 +02:00
|
|
|
//console.log("JoinNetwork:refreshNetworks:scanned");
|
2014-04-25 16:24:25 +02:00
|
|
|
d3d.util.hideLoader();
|
|
|
|
_networks = {};
|
2017-06-21 11:35:29 +02:00
|
|
|
// console.log('_knownSSIDs',_knownSSIDs);
|
2014-04-25 16:24:25 +02:00
|
|
|
$.each(data.networks, function(index,network) {
|
2017-06-21 11:35:29 +02:00
|
|
|
network.known = _knownSSIDs.indexOf(network.ssid)>-1;
|
2014-04-25 16:24:25 +02:00
|
|
|
_networks[network.ssid] = network;
|
|
|
|
});
|
|
|
|
// update list
|
|
|
|
updateList();
|
|
|
|
// keep refreshing
|
|
|
|
clearTimeout(_refreshDelay);
|
|
|
|
_refreshDelay = setTimeout(refreshNetworks, _refreshDelayTime);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function updateList() {
|
|
|
|
_list.empty();
|
|
|
|
var baseConnectingLink = _list.data("connecting-target");
|
|
|
|
var baseSecuredLink = _list.data("secured-target");
|
|
|
|
var linkParams = $.extend({}, _boxData);
|
2014-05-01 13:12:30 +02:00
|
|
|
//console.log(" linkParams: ",linkParams);
|
2017-06-21 11:35:29 +02:00
|
|
|
|
|
|
|
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];
|
|
|
|
|
2014-04-25 16:24:25 +02:00
|
|
|
linkParams.ssid = network.ssid;
|
|
|
|
|
2014-04-25 16:52:02 +02:00
|
|
|
var secured = (network.encryption !== "none" && network.encryption !== "");
|
2014-04-25 16:24:25 +02:00
|
|
|
var link;
|
2017-06-21 11:35:29 +02:00
|
|
|
var icon = secured ? "lock" : "alert";
|
2014-05-22 11:26:52 +02:00
|
|
|
linkParams.encryption = network.encryption;
|
2017-06-21 11:35:29 +02:00
|
|
|
|
|
|
|
if (!secured || network.known) { //skip the password page
|
2014-04-25 16:24:25 +02:00
|
|
|
link = d3d.util.replaceURLParameters(baseConnectingLink,linkParams);
|
2017-06-21 11:35:29 +02:00
|
|
|
} else {
|
|
|
|
link = d3d.util.replaceURLParameters(baseSecuredLink,linkParams);
|
2014-04-25 16:24:25 +02:00
|
|
|
}
|
2017-06-21 11:35:29 +02:00
|
|
|
|
2014-05-01 13:12:30 +02:00
|
|
|
//console.log(" link: ",link);
|
2017-06-21 11:35:29 +02:00
|
|
|
|
|
|
|
var className = (network.known ? 'knownNetwork' : ''); //previously joined
|
|
|
|
|
2014-04-25 16:24:25 +02:00
|
|
|
_list.append(
|
2017-06-21 11:35:29 +02:00
|
|
|
$('<li class="'+className+'" data-icon="'+icon+'"><a href="'+link+'">'+network.ssid+'</a></li>')
|
2014-04-25 16:24:25 +02:00
|
|
|
);
|
2017-06-21 11:35:29 +02:00
|
|
|
}
|
2014-05-01 13:12:30 +02:00
|
|
|
//_list.append(_joinOtherItem);
|
2014-04-25 16:24:25 +02:00
|
|
|
_list.listview('refresh'); // jQuery mobile enhance content
|
|
|
|
}
|
2014-05-12 14:44:21 +02:00
|
|
|
})(window);
|