From 1523ba322765d4c11b55ffae4383395f2aa6064e Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Tue, 4 Feb 2014 14:34:03 +0100 Subject: [PATCH] Refactored openap --- js/api/NetworkAPI.js | 15 ++++++++++++++ js/settings/NetworkPanel.js | 39 +++++++++++-------------------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/js/api/NetworkAPI.js b/js/api/NetworkAPI.js index 2186985..9bb0133 100644 --- a/js/api/NetworkAPI.js +++ b/js/api/NetworkAPI.js @@ -91,6 +91,21 @@ function NetworkAPI() { }); }; + this.openAP = function() { + console.log("NetworkAPI:openAP"); + $.ajax({ + url: _wifiboxCGIBinURL + "/network/openap", + type: "POST", + dataType: 'json', + timeout: _timeoutTime, + success: function(response){ + console.log("NetworkAPI:openAP response: ",response); + } + }).fail(function() { + console.log("NetworkAPI:openAP: timeout (normal behavior)"); + }); + }; + this.signin = function() { $.ajax({ url: self.wifiboxCGIBinURL + "/network/signin", diff --git a/js/settings/NetworkPanel.js b/js/settings/NetworkPanel.js index 46ff183..26e925e 100644 --- a/js/settings/NetworkPanel.js +++ b/js/settings/NetworkPanel.js @@ -361,33 +361,16 @@ function NetworkPanel() { this.createAP = function() { console.log("createAP"); - if (communicateWithWifibox) { + // save network related settings and on complete, create access point + _self.saveSettings(_self.readForm(),function(success) { + if(!success) return; + setAPModeState(AP_MODE_STATE.CREATING_AP,""); + _api.openAP(); - // save network related settings and on complete, create access point - _self.saveSettings(_self.readForm(),function(success) { - if(!success) return; - setAPModeState(AP_MODE_STATE.CREATING_AP); // get latest substituted ssid - $.ajax({ - url: _wifiboxCGIBinURL + "/network/openap", - type: "POST", - dataType: 'json', - timeout: _timeoutTime, - success: function(response){ - console.log("Settings:createAP response: ",response); - } - }).fail(function() { - console.log("Settings:createAP: timeout (normal behavior)"); - //clearTimeout(self.retrySaveSettingsDelay); - //self.retrySaveSettingsDelay = setTimeout(function() { self.saveSettings() },self.retryDelay); // retry after delay - }); - - setAPModeState(AP_MODE_STATE.CREATING_AP,""); - - // after switching wifi network or creating a access point we delay the status retrieval - // because the webserver needs time to switch - clearTimeout(_retrieveNetworkStatusDelay); - _retrieveNetworkStatusDelay = setTimeout(function() { _self.retrieveNetworkStatus(true); }, _retrieveNetworkStatusDelayTime); - }); - } - };*/ + // after switching wifi network or creating a access point we delay the status retrieval + // because the webserver needs time to switch it's status + clearTimeout(_retrieveNetworkStatusDelay); + _retrieveNetworkStatusDelay = setTimeout(function() { _self.retrieveNetworkStatus(true); }, _retrieveNetworkStatusDelayTime); + }); + }; }