0
0
mirror of https://github.com/Doodle3D/doodle3d-connect.git synced 2024-12-26 02:23:48 +01:00
doodle3d-connect/js/BoxPage.js

114 lines
3.5 KiB
JavaScript
Raw Permalink Normal View History

/*
* 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
2014-05-12 14:44:21 +02:00
(function (w) {
2014-04-24 12:46:26 +02:00
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;
2014-05-14 10:57:53 +02:00
//var _updateItem;
2014-04-25 16:24:25 +02:00
var _joinNetworkItem;
2014-05-07 17:15:48 +02:00
var _defaultItems;
2014-04-25 16:24:25 +02:00
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";
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-05-07 17:15:48 +02:00
_defaultItems = _list.children();
_drawItem = _list.find("#drawItem");
2014-05-14 10:57:53 +02:00
//_updateItem = _list.find("#updateItem");
2014-05-07 17:15:48 +02:00
_joinNetworkItem = _list.find("#joinNetworkItem");
// make sure draw link is opened in same WebApp (added to homescreen)
// and it doesn't start a browser
$.stayInWebApp("#box #drawItem a",true);
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);
if(_boxData === undefined) {
$.mobile.changePage("#boxes");
return;
}
2014-04-24 12:46:26 +02:00
var boxURL = "http://"+_boxData.localip;
2014-05-07 23:36:31 +02:00
//console.log(" _boxData: ",_boxData);
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-04-24 12:46:26 +02:00
var drawLink = (_boxData.link)? _boxData.link : boxURL;
_page.find("#drawItem a").attr("href",drawLink);
2014-04-24 12:46:26 +02:00
_networkAPI.init(boxURL);
retrieveNetworkStatus();
});
$.mobile.document.on( "pagebeforehide", PAGE_ID, function( event, data ) {
clearTimeout(_retryRetrieveStatusDelay);
});
2014-04-24 12:46:26 +02:00
function retrieveNetworkStatus() {
_networkAPI.status(function(data) {
2014-04-25 16:24:25 +02:00
data.status = parseInt(data.status,10);
2014-05-01 11:37:25 +02:00
setNetworkStatus(data.status);
2014-04-24 12:46:26 +02:00
}, function() {
clearTimeout(_retryRetrieveStatusDelay);
_retryRetrieveStatusDelay = setTimeout(_self.retrieveStatus, _retryRetrieveStatusDelayTime); // retry after delay
});
}
2014-04-25 16:24:25 +02:00
2014-05-01 11:37:25 +02:00
function setNetworkStatus(status) {
2014-05-07 17:15:48 +02:00
console.log(PAGE_ID+":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
2014-05-07 17:15:48 +02:00
// display the right buttons
_defaultItems.toggleClass("ui-screen-hidden",false);
2014-05-01 11:37:25 +02:00
_joinNetworkItem.toggleClass("ui-screen-hidden",true);
2014-05-07 17:15:48 +02:00
// ToDo: retrieve update information
2014-05-01 11:37:25 +02:00
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-05-07 17:15:48 +02:00
_drawItem.find("a").text("Draw (offline)");
// display the right buttons
_defaultItems.toggleClass("ui-screen-hidden",true);
_drawItem.toggleClass("ui-screen-hidden",false);
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-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-04-24 12:46:26 +02:00
})(window);