From 0dcd18d4911c935a69c3c1084adcf5a0020d2741 Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Fri, 25 Apr 2014 16:24:25 +0200 Subject: [PATCH] Better filenames --- js/{Box.js => BoxPage.js} | 61 +++++++++++------------- js/{boxes.js => BoxesPage.js} | 20 ++++---- js/JoinNetwork.js | 71 ---------------------------- js/JoinNetworkPage.js | 89 +++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 114 deletions(-) rename js/{Box.js => BoxPage.js} (72%) rename js/{boxes.js => BoxesPage.js} (78%) delete mode 100644 js/JoinNetwork.js create mode 100644 js/JoinNetworkPage.js diff --git a/js/Box.js b/js/BoxPage.js similarity index 72% rename from js/Box.js rename to js/BoxPage.js index b782aa2..d34007b 100644 --- a/js/Box.js +++ b/js/BoxPage.js @@ -8,8 +8,13 @@ var BoxPage = (function (w) { var _page; + var _list; var _title; var _intro; + var _drawItem; + var _updateItem; + var _joinNetworkItem; + var _networkStatus; var _networkAPI = new NetworkAPI(); var _boxData = {}; @@ -22,9 +27,13 @@ var BoxPage = (function (w) { $.mobile.document.on( "pageinit", PAGE_ID, function( event, data ) { //console.log("Box page pageinit"); _page = $(this); + _list = _page.find("ul[data-role=listview]"); _title = _page.find(".ui-title"); _intro = _page.find(".intro"); + _drawItem = _page.find("#drawItem"); + _updateItem = _page.find("#updateItem"); + _joinNetworkItem = _page.find("#joinNetworkItem"); }); $.mobile.document.on( "pagebeforeshow", PAGE_ID, function( event, data ) { console.log("Box page pagebeforeshow"); @@ -47,9 +56,8 @@ var BoxPage = (function (w) { _networkAPI.status(function(data) { console.log("_networkAPI.status complete"); console.log(" data: ",data); - if(data.status !== "" && typeof data.status === 'string') { - data.status = parseInt(data.status,10); - } + data.status = parseInt(data.status,10); + console.log(" data.status: ",data.status); //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 @@ -71,55 +79,40 @@ var BoxPage = (function (w) { _retryRetrieveStatusDelay = setTimeout(_self.retrieveStatus, _retryRetrieveStatusDelayTime); // retry after delay }); } + function setNetworkStatus(status,data) { console.log("setNetworkStatus: ",status,data); + console.log(" _updateItem: ",_updateItem); if(status === NetworkAPI.STATUS.CONNECTED) { // online - _page.find("#drawItem a").text("Draw"); - // ToDo: Link to update page (auto retrieve if available) + console.log("online"); + _drawItem.find("#a").text("Draw"); // ToDo: Link to your app here? // ToDo: Status // ToDo: Control - _page.find("#joinNetworkItem").toggleClass("ui-screen-hidden",true); + _joinNetworkItem.toggleClass("ui-screen-hidden",true); + _updateItem.toggleClass("ui-screen-hidden",false); + // ToDo: retrieve update information } else { // offline + console.log("offline"); _intro.text("Please connect your WiFi-Box to the internet. You can also use it offline but then you aren't able to update."); - var joinNetworkItem = _page.find("#joinNetworkItem"); - joinNetworkItem.toggleClass("ui-screen-hidden",false); + _joinNetworkItem.toggleClass("ui-screen-hidden",false); - var joinLink = joinNetworkItem.find("a").attr("href"); + var joinLink = _joinNetworkItem.find("a").attr("href"); joinLink = d3d.util.replaceURLParameters(joinLink,_boxData); - joinNetworkItem.find("a").attr("href",joinLink); + _joinNetworkItem.find("a").attr("href",joinLink); - _page.find("#drawItem a").text("Draw (offline)"); + _drawItem.find("a").text("Draw (offline)"); + _updateItem.toggleClass("ui-screen-hidden",true); // ToDo: Status // ToDo: Control } - // update info - /*switch(status) { - case NetworkAPI.STATUS.CONNECTED: - //console.log(" data.ssid: ",data.ssid); - if(data.ssid == "") { - _currentNetwork = undefined; - //data.status = NetworkAPI.STATUS.NOT_CONNECTED; - setStatus(NetworkAPI.STATUS.NOT_CONNECTED); - } else { - _currentNetwork = data.ssid; - } - break; - case NetworkAPI.STATUS.CONNECTING: - if(_selectedNetwork != undefined) { - targetNetwork = _selectedNetwork; - } else if(_currentNetwork != undefined) { - targetNetwork = _currentNetwork; - } - case NetworkAPI.STATUS.CREATING: - case NetworkAPI.STATUS.CREATED: - _currentNetwork = undefined; - break; - }*/ + // ToDo: update footer with network info + + _list.listview('refresh'); // jQuery mobile enhance content _networkStatus = data.status; } diff --git a/js/boxes.js b/js/BoxesPage.js similarity index 78% rename from js/boxes.js rename to js/BoxesPage.js index 9780c54..f78a5e1 100644 --- a/js/boxes.js +++ b/js/BoxesPage.js @@ -7,7 +7,7 @@ */ var BoxesPage = (function (w) { - var connectAPI = new ConnectAPI(); // TODO add _ + var _connectAPI = new ConnectAPI(); var _page; var _list; @@ -20,18 +20,18 @@ var BoxesPage = (function (w) { _list = _page.find("#boxeslist"); _findItem = _list.find("#findItem"); - connectAPI.refreshing = onRefreshing; - connectAPI.listUpdated = onListUpdated; - connectAPI.boxAppeared = onBoxAppeared; - connectAPI.boxDisapeared = onBoxDisapeared; + _connectAPI.refreshing = onRefreshing; + _connectAPI.listUpdated = onListUpdated; + _connectAPI.boxAppeared = onBoxAppeared; + _connectAPI.boxDisapeared = onBoxDisapeared; }); $.mobile.document.on( "pagebeforeshow", PAGE_ID, function( event, data ) { //console.log("Boxes page pagebeforeshow"); - connectAPI.start(); + _connectAPI.start(); }); $.mobile.document.on( "pagehide", PAGE_ID, function( event, data ) { //console.log("Boxes page pagehide"); - connectAPI.stop(); + _connectAPI.stop(); }); function onRefreshing() { @@ -46,8 +46,10 @@ var BoxesPage = (function (w) { function onBoxAppeared(boxData) { console.log("onBoxAppeared: ",boxData.localip); - var link = "#box?localip="+boxData.localip+"&wifiboxid="+boxData.wifiboxid; - if(boxData.link) { link += "&link="+boxData.link; } + var linkParams = {localip: boxData.localip,wifiboxid: boxData.wifiboxid}; + if(boxData.link) { linkParams.link = boxData.link; } + var link = "#box"; + link = d3d.util.replaceURLParameters(link,linkParams); var id = boxData.localip.replace(/\./g,"-"); var linkElement = $(""+boxData.wifiboxid+""); var box = $("
  • "); diff --git a/js/JoinNetwork.js b/js/JoinNetwork.js deleted file mode 100644 index 1162407..0000000 --- a/js/JoinNetwork.js +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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. - */ - -(function (w) { - var _page; - var _list; - var _networks; -// var _networkStatus; -// var _networkAPI = new NetworkAPI(); -// var _boxData = {}; -// var _retryRetrieveStatusDelay; -// var _retryRetrieveStatusDelayTime = 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]"); - console.log(" list: ",_list); - }); - $.mobile.document.on( "pagebeforeshow", PAGE_ID, function( event, data ) { - console.log("Join network page pagebeforeshow"); - _boxData = d3d.util.getPageParams(PAGE_ID); - var boxURL = "http://"+_boxData.localip; - console.log(" _boxData: ",_boxData); - - _networkAPI.init(boxURL); - refreshNetworks(); - }); - function refreshNetworks(completeHandler) { - console.log("JoinNetwork:refreshNetworks"); - _api.scan(function(data) { // completed - console.log("JoinNetwork:refreshNetworks:scanned"); - - fillNetworks(data.networks) - _networks = {}; - $.each(data.networks, function(index,network) { - _networks[network.ssid] = network; - }); - - if(completeHandler) completeHandler(); - }); - } - function fillNetworks(networks) { - _list.empty(); - $.each(networks, function(index,network) { - - var joinLink = joinNetworkItem.find("a").attr("href"); - joinLink = d3d.util.replaceURLParameters(joinLink,_boxData); - joinNetworkItem.find("a").attr("href",joinLink); - - - var link = "#network_connecting"; - link = d3d.util.replaceURLParameters(link,_boxData); - //var item = $("
  • "); - - _list.append( - //$("").val(network.ssid).html(network.ssid) - ); - }); - _list.listview('refresh'); // jQuery mobile enhance content - } - -})(window); \ No newline at end of file diff --git a/js/JoinNetworkPage.js b/js/JoinNetworkPage.js new file mode 100644 index 0000000..4818d2b --- /dev/null +++ b/js/JoinNetworkPage.js @@ -0,0 +1,89 @@ +/* + * 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. + */ + +(function JoinNetworkPage(w) { + + var _page; + var _list; + var _joinOtherItem; + var _networks; + var _networkAPI = new NetworkAPI(); + var _boxData = {}; + var _refreshDelay; + 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]"); + _joinOtherItem = _list.find("#joinOther"); + console.log(" list: ",_list); + }); + $.mobile.document.on( "pagebeforeshow", PAGE_ID, function( event, data ) { + console.log("Join network page pagebeforeshow"); + _boxData = d3d.util.getPageParams(PAGE_ID); + var boxURL = "http://"+_boxData.localip; + console.log(" _boxData: ",_boxData); + + _networkAPI.init(boxURL); + refreshNetworks(); + }); + $.mobile.document.on( "pagehide", PAGE_ID, function( event, data ) { + console.log("Join network page pagehide"); + clearTimeout(_refreshDelay); + }); + function refreshNetworks() { + console.log("JoinNetwork:refreshNetworks"); + d3d.util.showLoader(); + _networkAPI.scan(function(data) { // completed + console.log("JoinNetwork:refreshNetworks:scanned"); + d3d.util.hideLoader(); + _networks = {}; + $.each(data.networks, function(index,network) { + _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); + console.log(" linkParams: ",linkParams); + $.each(_networks, function(index,network) { + console.log(" network: ",network); + linkParams.ssid = network.ssid; + + var secured = (network.encryption !== "none" && network.encryption !== "") + var link; + var icon = ""; + if(secured) { + linkParams.encryption = network.encryption; + link = d3d.util.replaceURLParameters(baseSecuredLink,linkParams); + icon = "lock"; + } else { + link = d3d.util.replaceURLParameters(baseConnectingLink,linkParams); + } + console.log(" link: ",link); + _list.append( + $('
  • '+network.ssid+'
  • ') + ); + }); + _list.append(_joinOtherItem); + _list.listview('refresh'); // jQuery mobile enhance content + } +})(window); +//new JoinNetworkPage(); \ No newline at end of file