0
0
mirror of https://github.com/Doodle3D/doodle3d-connect.git synced 2024-12-25 18:13:48 +01:00

Update intro according to new boxes system

This commit is contained in:
peteruithoven 2014-02-25 14:24:54 +01:00
parent 4018794184
commit fa636a3fcc

View File

@ -24,6 +24,7 @@ var $preloader;
var spinner; var spinner;
var boxes = {}; var boxes = {};
var numBoxes = 0;
var networkAPI = new NetworkAPI(); var networkAPI = new NetworkAPI();
var connectAPI = new ConnectAPI(); var connectAPI = new ConnectAPI();
@ -77,10 +78,8 @@ function retrieveList() {
// if web is not accessible try to find the box as an accesspoint // if web is not accessible try to find the box as an accesspoint
// if not found, we look for a wired box // if not found, we look for a wired box
networkAPI.alive(apBox.localip,boxTimeoutTime,function() { networkAPI.alive(apBox.localip,boxTimeoutTime,function() {
console.log("found apBox");
updateList([apBox]); updateList([apBox]);
}, function() { }, function() {
console.log("not found apBox");
updateList([connectedBox]); updateList([connectedBox]);
}); });
clearTimeout(retrieveListDelay); clearTimeout(retrieveListDelay);
@ -93,7 +92,7 @@ function updateList(foundBoxes) {
numBoxesChecking = 0; numBoxesChecking = 0;
numBoxesFound = 0; numBoxesFound = 0;
if (boxes===undefined) boxes = []; if (foundBoxes===undefined) foundBoxes = [];
// remove displayed, but not found boxes // remove displayed, but not found boxes
jQuery.each(boxes, function (index,box) { jQuery.each(boxes, function (index,box) {
@ -121,11 +120,9 @@ function checkBox(boxData) {
addBox(boxData); addBox(boxData);
numBoxesFound++; numBoxesFound++;
numBoxesChecking--; numBoxesChecking--;
updateIntro();
}, function() { }, function() {
removeBox(boxData.localip); removeBox(boxData.localip);
numBoxesChecking--; numBoxesChecking--;
updateIntro();
}); });
} }
function getBox(localip) { function getBox(localip) {
@ -138,6 +135,8 @@ function addBox(boxData) {
box.init(boxData,$list); box.init(boxData,$list);
box.destroyedHandler = boxDestroyedHandler; box.destroyedHandler = boxDestroyedHandler;
boxes[box.localip] = box; boxes[box.localip] = box;
numBoxes++;
updateIntro();
} }
function removeBox(localip,force) { function removeBox(localip,force) {
var box = getBox(localip); var box = getBox(localip);
@ -150,12 +149,13 @@ function removeBox(localip,force) {
function boxDestroyedHandler(box) { function boxDestroyedHandler(box) {
//console.log("boxDestroyedHandler"); //console.log("boxDestroyedHandler");
delete boxes[box.localip]; delete boxes[box.localip];
numBoxes--;
updateIntro();
} }
function updateIntro() { function updateIntro() {
$intro.fadeIn(); //console.log("updateIntro, numBoxes: ",numBoxes);
if(numBoxesChecking <= 0) { if(numBoxes > 0) {
if(numBoxesFound > 0) {
$intro.html("Found the following boxes near you:"); $intro.html("Found the following boxes near you:");
$hint.fadeOut(); $hint.fadeOut();
} else { } else {
@ -163,5 +163,4 @@ function updateIntro() {
$hint.fadeIn(); $hint.fadeIn();
} }
$preloader.fadeOut(1000); $preloader.fadeOut(1000);
}
} }