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
|
|
|
|
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;
|
2017-07-11 12:33:09 +02:00
|
|
|
// var _intro;
|
2014-04-25 16:24:25 +02:00
|
|
|
var _drawItem;
|
2017-06-20 21:42:49 +02:00
|
|
|
var _printItem;
|
2014-05-23 19:09:46 +02:00
|
|
|
var _updateItem;
|
2017-05-16 09:55:32 +02:00
|
|
|
var _settingsItem;
|
2017-06-20 21:42:49 +02:00
|
|
|
var _controlItem;
|
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();
|
2014-05-23 19:09:46 +02:00
|
|
|
var _updateAPI = new UpdateAPI();
|
2014-04-24 12:46:26 +02:00
|
|
|
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");
|
2017-07-11 12:33:09 +02:00
|
|
|
// _intro = _page.find(".intro");
|
2014-02-24 11:26:30 +01:00
|
|
|
|
2014-05-07 17:15:48 +02:00
|
|
|
_defaultItems = _list.children();
|
|
|
|
_drawItem = _list.find("#drawItem");
|
2014-05-23 19:09:46 +02:00
|
|
|
_updateItem = _list.find("#updateItem");
|
2017-05-16 09:55:32 +02:00
|
|
|
_settingsItem = _list.find("#settingsItem");
|
2017-06-20 21:42:49 +02:00
|
|
|
_controlItem = _list.find("#controlItem");
|
2014-05-07 17:15:48 +02:00
|
|
|
_joinNetworkItem = _list.find("#joinNetworkItem");
|
2017-06-20 21:42:49 +02:00
|
|
|
_printItem = _list.find("#printItem");
|
|
|
|
|
2014-05-13 14:46:35 +02:00
|
|
|
// make sure draw link is opened in same WebApp (added to homescreen)
|
|
|
|
// and it doesn't start a browser
|
|
|
|
$.stayInWebApp("#box #drawItem a",true);
|
2017-07-11 12:33:09 +02:00
|
|
|
});
|
|
|
|
|
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);
|
2014-05-14 12:00:02 +02:00
|
|
|
if(_boxData === undefined) {
|
|
|
|
$.mobile.changePage("#boxes");
|
|
|
|
return;
|
|
|
|
}
|
2014-04-24 12:46:26 +02:00
|
|
|
var boxURL = "http://"+_boxData.localip;
|
2014-02-24 11:26:30 +01:00
|
|
|
|
2017-07-11 12:33:09 +02:00
|
|
|
//store the localip to be able to retrieve it in main.js when opening from Transform
|
|
|
|
localStorage.setItem("localip",_boxData.localip);
|
|
|
|
|
2014-04-24 12:46:26 +02:00
|
|
|
_title.text(_boxData.wifiboxid);
|
2017-07-11 12:33:09 +02:00
|
|
|
$(".infoWiFiBoxId").text(_boxData.wifiboxid);
|
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
|
|
|
|
2017-07-11 12:33:09 +02:00
|
|
|
$("#filemanagerItem a").attr("href",drawLink + "/filemanager");
|
|
|
|
|
2014-04-24 12:46:26 +02:00
|
|
|
_networkAPI.init(boxURL);
|
2014-05-23 19:09:46 +02:00
|
|
|
_updateAPI.init(boxURL);
|
2015-06-17 10:31:19 +02:00
|
|
|
|
|
|
|
setNetworkStatus(NetworkAPI.STATUS.CONNECTED);
|
|
|
|
retrieveNetworkStatus();
|
2017-06-20 21:42:49 +02:00
|
|
|
|
|
|
|
|
2014-04-24 12:46:26 +02:00
|
|
|
});
|
2014-05-12 14:53:01 +02:00
|
|
|
$.mobile.document.on( "pagebeforehide", PAGE_ID, function( event, data ) {
|
2014-05-12 14:43:59 +02:00
|
|
|
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-02-24 11:26:30 +01: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);
|
2017-07-11 12:33:09 +02:00
|
|
|
// var introText = "";
|
2017-05-16 12:26:54 +02:00
|
|
|
|
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");
|
2017-07-11 12:33:09 +02:00
|
|
|
// _drawItem.find("h2").text("Draw / Sketch");
|
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);
|
2017-06-20 21:42:49 +02:00
|
|
|
_printItem.toggleClass("ui-screen-hidden",false);
|
2014-05-01 11:37:25 +02:00
|
|
|
_joinNetworkItem.toggleClass("ui-screen-hidden",true);
|
2014-05-23 19:09:46 +02:00
|
|
|
|
2017-05-16 12:26:54 +02:00
|
|
|
//update link
|
2014-05-23 19:09:46 +02:00
|
|
|
var updateLink = _updateItem.find("a").attr("href");
|
|
|
|
updateLink = d3d.util.replaceURLParameters(updateLink,_boxData);
|
|
|
|
_updateItem.find("a").attr("href",updateLink);
|
2017-07-11 12:33:09 +02:00
|
|
|
|
|
|
|
$("#collapsibleWiFiBox").collapsible("option", "collapsed",true);
|
2014-05-01 11:37:25 +02:00
|
|
|
|
2014-05-23 22:59:38 +02:00
|
|
|
retrieveUpdateStatus();
|
|
|
|
|
2014-04-24 12:46:26 +02:00
|
|
|
} else { // offline
|
2014-05-01 18:37:29 +02:00
|
|
|
//console.log("offline");
|
2017-07-11 12:33:09 +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
|
|
|
|
2017-07-11 12:33:09 +02:00
|
|
|
// _drawItem.find("h2").text("Draw / Sketch (local)");
|
2017-06-20 21:42:49 +02:00
|
|
|
|
2014-05-07 17:15:48 +02:00
|
|
|
// 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);
|
2017-05-16 12:26:54 +02:00
|
|
|
|
2017-07-11 12:33:09 +02:00
|
|
|
$("#collapsibleWiFiBox").collapsible("option", "collapsed",false);
|
|
|
|
// $("#collapsibleApps").collapsible("option", "collapsed",false);
|
|
|
|
|
2017-05-16 12:26:54 +02:00
|
|
|
//joinLink
|
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-02-24 11:26:30 +01:00
|
|
|
}
|
|
|
|
|
2017-07-11 12:33:09 +02:00
|
|
|
// _intro.text(introText);
|
|
|
|
// _intro.toggleClass("ui-screen-hidden",(introText === ""));
|
2014-05-01 11:37:25 +02:00
|
|
|
|
2017-05-16 12:26:54 +02:00
|
|
|
//settingsLink
|
|
|
|
var settingsLink = _settingsItem.find("a").attr("href");
|
|
|
|
settingsLink = d3d.util.replaceURLParameters(settingsLink,_boxData);
|
|
|
|
_settingsItem.find("a").attr("href",settingsLink);
|
|
|
|
_settingsItem.toggleClass("ui-screen-hidden",false);
|
|
|
|
|
2017-07-11 12:33:09 +02:00
|
|
|
//updateLink
|
2017-06-20 21:42:49 +02:00
|
|
|
var controlLink = _controlItem.find("a").attr("href");
|
|
|
|
controlLink = d3d.util.replaceURLParameters(controlLink,_boxData);
|
|
|
|
_controlItem.find("a").attr("href",controlLink);
|
|
|
|
_controlItem.toggleClass("ui-screen-hidden",false);
|
2017-07-11 12:33:09 +02:00
|
|
|
|
|
|
|
//networkSettingsLink
|
|
|
|
// var networksettingsLink = $("#networksettingsItem a").attr("href");
|
|
|
|
// networksettingsLink = d3d.util.replaceURLParameters(networksettingsLink,_boxData);
|
|
|
|
// $("#networksettingsItem a").attr("href",networksettingsLink);
|
2017-06-20 21:42:49 +02:00
|
|
|
|
|
|
|
//printLink
|
|
|
|
var printLink = _printItem.find("a").attr("href");
|
|
|
|
printLink = d3d.util.replaceURLParameters(printLink,_boxData);
|
|
|
|
_printItem.find("a").attr("href",printLink);
|
2017-07-11 12:33:09 +02:00
|
|
|
|
2017-06-20 21:42:49 +02:00
|
|
|
|
|
|
|
if (d3d && d3d.pageParams && d3d.pageParams.uuid) {
|
|
|
|
_printItem.show();
|
2017-07-11 12:33:09 +02:00
|
|
|
$("#collapsiblePrinter").collapsible("option", "collapsed",false);
|
|
|
|
// $( ".selector" ).collapsible( "option", "collapsed", false );
|
|
|
|
|
2017-06-20 21:42:49 +02:00
|
|
|
} else {
|
|
|
|
_printItem.hide();
|
|
|
|
}
|
|
|
|
|
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-05-23 19:09:46 +02:00
|
|
|
|
|
|
|
function retrieveUpdateStatus() {
|
|
|
|
console.log(PAGE_ID+":retrieveUpdateStatus");
|
|
|
|
var updateCounter = _list.find("#updateItem .ui-li-count");
|
|
|
|
updateCounter.hide();
|
|
|
|
_updateAPI.status(function(data) { // completed
|
|
|
|
console.log("UpdateAPI:refresh:completed");
|
|
|
|
var canUpdate = data.can_update;
|
|
|
|
updateCounter.text(canUpdate? 1 : 0);
|
|
|
|
updateCounter.show();
|
|
|
|
});
|
|
|
|
}
|
2014-04-24 12:46:26 +02:00
|
|
|
})(window);
|