2014-02-24 11:26:30 +01: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-04-24 12:46:26 +02:00
|
|
|
|
|
|
|
var BoxPage = (function (w) {
|
|
|
|
var _page;
|
2014-04-25 16:24:25 +02:00
|
|
|
var _list;
|
2014-04-24 12:46:26 +02:00
|
|
|
var _title;
|
|
|
|
var _intro;
|
2014-04-25 16:24:25 +02:00
|
|
|
var _drawItem;
|
|
|
|
var _updateItem;
|
|
|
|
var _joinNetworkItem;
|
|
|
|
|
2014-04-24 12:46:26 +02:00
|
|
|
var _networkStatus;
|
|
|
|
var _networkAPI = new NetworkAPI();
|
|
|
|
var _boxData = {};
|
|
|
|
var _retryRetrieveStatusDelay;
|
|
|
|
var _retryRetrieveStatusDelayTime = 3000;
|
|
|
|
var PAGE_ID = "#box";
|
2014-02-24 11:26:30 +01:00
|
|
|
|
|
|
|
var _self = this;
|
2014-04-24 12:46:26 +02:00
|
|
|
|
|
|
|
$.mobile.document.on( "pageinit", PAGE_ID, function( event, data ) {
|
|
|
|
//console.log("Box page pageinit");
|
|
|
|
_page = $(this);
|
2014-04-25 16:24:25 +02:00
|
|
|
_list = _page.find("ul[data-role=listview]");
|
2014-04-24 12:46:26 +02:00
|
|
|
_title = _page.find(".ui-title");
|
|
|
|
_intro = _page.find(".intro");
|
2014-02-24 11:26:30 +01:00
|
|
|
|
2014-04-25 16:24:25 +02:00
|
|
|
_drawItem = _page.find("#drawItem");
|
|
|
|
_updateItem = _page.find("#updateItem");
|
|
|
|
_joinNetworkItem = _page.find("#joinNetworkItem");
|
2014-04-24 12:46:26 +02:00
|
|
|
});
|
|
|
|
$.mobile.document.on( "pagebeforeshow", PAGE_ID, function( event, data ) {
|
|
|
|
console.log("Box page pagebeforeshow");
|
|
|
|
_boxData = d3d.util.getPageParams(PAGE_ID);
|
|
|
|
var boxURL = "http://"+_boxData.localip;
|
|
|
|
console.log(" _boxData: ",_boxData);
|
2014-02-24 11:26:30 +01:00
|
|
|
|
2014-04-24 12:46:26 +02:00
|
|
|
_title.text(_boxData.wifiboxid);
|
2014-05-01 11:37:25 +02:00
|
|
|
setNetworkStatus(NetworkAPI.STATUS.CONNECTED);
|
2014-02-24 11:26:30 +01:00
|
|
|
|
2014-04-24 12:46:26 +02:00
|
|
|
var drawLink = (_boxData.link)? _boxData.link : boxURL;
|
|
|
|
_page.find("#drawItem a").attr("href",drawLink);
|
2014-02-24 11:26:30 +01:00
|
|
|
|
2014-04-24 12:46:26 +02:00
|
|
|
_networkAPI.init(boxURL);
|
|
|
|
retrieveNetworkStatus();
|
|
|
|
});
|
|
|
|
|
|
|
|
function retrieveNetworkStatus() {
|
2014-05-01 18:37:29 +02:00
|
|
|
//console.log("retrieveNetworkStatus");
|
2014-04-24 12:46:26 +02:00
|
|
|
_networkAPI.status(function(data) {
|
2014-05-01 18:37:29 +02:00
|
|
|
//console.log("_networkAPI.status complete");
|
|
|
|
//console.log(" data: ",data);
|
2014-04-25 16:24:25 +02:00
|
|
|
data.status = parseInt(data.status,10);
|
2014-05-01 18:37:29 +02:00
|
|
|
//console.log(" data.status: ",data.status);
|
2014-04-24 12:46:26 +02:00
|
|
|
//console.log(_self.id,"NetworkPanel:retrievedStatus status: ",data.status,data.statusMessage);
|
|
|
|
//console.log(" networkPanel ",_element[0]," parent: ",_element.parent()[0]);
|
|
|
|
// ToDo: update _currentNetwork when available
|
|
|
|
|
2014-05-01 11:37:25 +02:00
|
|
|
setNetworkStatus(data.status);
|
2014-04-24 12:46:26 +02:00
|
|
|
|
|
|
|
/*// Keep checking for updates?
|
|
|
|
switch(data.status) {
|
|
|
|
case NetworkAPI.STATUS.CONNECTING:
|
|
|
|
case NetworkAPI.STATUS.CREATING:
|
|
|
|
clearTimeout(_retryRetrieveStatusDelay);
|
|
|
|
_retryRetrieveStatusDelay = setTimeout(_self.retrieveStatus,_retryRetrieveStatusDelayTime); // retry after delay
|
|
|
|
break;
|
|
|
|
}*/
|
|
|
|
//if(completeHandler) completeHandler(data.status);
|
|
|
|
}, function() {
|
|
|
|
//console.log("NetworkPanel:retrieveStatus failed");
|
|
|
|
clearTimeout(_retryRetrieveStatusDelay);
|
|
|
|
_retryRetrieveStatusDelay = setTimeout(_self.retrieveStatus, _retryRetrieveStatusDelayTime); // retry after delay
|
|
|
|
});
|
2014-02-24 11:26:30 +01:00
|
|
|
}
|
2014-04-25 16:24:25 +02:00
|
|
|
|
2014-05-01 11:37:25 +02:00
|
|
|
function setNetworkStatus(status) {
|
2014-05-01 18:37:29 +02:00
|
|
|
//console.log("setNetworkStatus: ",status);
|
2014-05-01 11:37:25 +02:00
|
|
|
var introText = "";
|
2014-04-24 12:46:26 +02:00
|
|
|
if(status === NetworkAPI.STATUS.CONNECTED) { // online
|
2014-05-01 18:37:29 +02:00
|
|
|
//console.log("online");
|
2014-04-28 16:55:57 +02:00
|
|
|
_drawItem.find("a").text("Draw");
|
2014-04-24 12:46:26 +02:00
|
|
|
// ToDo: Link to your app here?
|
|
|
|
// ToDo: Status
|
|
|
|
// ToDo: Control
|
2014-04-25 16:24:25 +02:00
|
|
|
_joinNetworkItem.toggleClass("ui-screen-hidden",true);
|
|
|
|
_updateItem.toggleClass("ui-screen-hidden",false);
|
|
|
|
// ToDo: retrieve update information
|
2014-04-24 12:46:26 +02:00
|
|
|
|
2014-05-01 11:37:25 +02:00
|
|
|
_joinNetworkItem.toggleClass("ui-screen-hidden",true);
|
|
|
|
|
2014-04-24 12:46:26 +02:00
|
|
|
} else { // offline
|
2014-05-01 18:37:29 +02:00
|
|
|
//console.log("offline");
|
2014-05-01 11:37:25 +02:00
|
|
|
introText = "Please connect your WiFi-Box to the internet. You can also use it offline, but then you won't be able to update.";
|
2014-04-24 12:46:26 +02:00
|
|
|
|
2014-04-25 16:24:25 +02:00
|
|
|
_joinNetworkItem.toggleClass("ui-screen-hidden",false);
|
2014-04-24 12:46:26 +02:00
|
|
|
|
2014-04-25 16:24:25 +02:00
|
|
|
var joinLink = _joinNetworkItem.find("a").attr("href");
|
2014-04-24 12:46:26 +02:00
|
|
|
joinLink = d3d.util.replaceURLParameters(joinLink,_boxData);
|
2014-04-25 16:24:25 +02:00
|
|
|
_joinNetworkItem.find("a").attr("href",joinLink);
|
2014-04-24 12:46:26 +02:00
|
|
|
|
2014-04-25 16:24:25 +02:00
|
|
|
_drawItem.find("a").text("Draw (offline)");
|
|
|
|
_updateItem.toggleClass("ui-screen-hidden",true);
|
2014-04-24 12:46:26 +02:00
|
|
|
|
|
|
|
// ToDo: Status
|
|
|
|
// ToDo: Control
|
2014-02-24 11:26:30 +01:00
|
|
|
}
|
|
|
|
|
2014-05-01 11:37:25 +02:00
|
|
|
_intro.text(introText);
|
|
|
|
_intro.toggleClass("ui-screen-hidden",(introText === ""));
|
|
|
|
|
2014-04-25 16:24:25 +02:00
|
|
|
// ToDo: update footer with network info
|
|
|
|
|
|
|
|
_list.listview('refresh'); // jQuery mobile enhance content
|
2014-05-01 11:37:25 +02:00
|
|
|
_networkStatus = status;
|
2014-02-24 11:26:30 +01:00
|
|
|
}
|
2014-04-24 12:46:26 +02:00
|
|
|
|
|
|
|
// to get to the box data we need the url
|
|
|
|
// only pagecontainer events contain url's
|
|
|
|
/*$.mobile.document.on( "pagecontainerbeforetransition", function( event, data ) {
|
|
|
|
//console.log("Box page pagebeforetransition");
|
|
|
|
var url = d3d.util.processURL(data.absUrl);
|
|
|
|
console.log(" url: ",url);
|
|
|
|
if(url.hash == PAGE_ID) {
|
|
|
|
_boxData = {
|
|
|
|
localip: url.parameters.localip,
|
|
|
|
wifiboxid: url.parameters.wifiboxid,
|
|
|
|
link: url.parameters.link,
|
|
|
|
url: "http://"+url.parameters.localip
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});*/
|
|
|
|
})(window);
|