mirror of
https://github.com/Doodle3D/doodle3d-client.git
synced 2025-06-11 09:23:17 +02:00
Settings refactoring & JS file Reorganising
This commit is contained in:
143
js/settings/FormPanel.js
Normal file
143
js/settings/FormPanel.js
Normal file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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 FormPanel() {
|
||||
|
||||
var _configAPI = new ConfigAPI();
|
||||
var _retryDelay = 2000;
|
||||
var _retrySaveSettingsDelay;
|
||||
// ui elements
|
||||
var _element;
|
||||
|
||||
var _self;
|
||||
|
||||
FormPanel.prototype.init = function(wifiboxURL,wifiboxCGIBinURL,panelElement) {
|
||||
console.log("FormPanel:init");
|
||||
// make _self the scope of which init was called?
|
||||
// needed to have the subclass instance access the same counter
|
||||
_self = this;
|
||||
_element = panelElement;
|
||||
//_configAPI.init(wifiboxURL,wifiboxCGIBinURL);
|
||||
|
||||
console.log(" calling _self.readForm from FormPanel:init");
|
||||
_self.readForm();
|
||||
//console.log(" calling this.readForm from FormPanel:init");
|
||||
//this.readForm();
|
||||
//console.log(" calling _self2.readForm from FormPanel:init");
|
||||
//_self2.readForm();
|
||||
};
|
||||
|
||||
//this.readForm = function(form) {
|
||||
FormPanel.prototype.readForm = function(form) {
|
||||
console.log("FormPanel:readForm");
|
||||
/*if(!form) form = _element; // if no form specified, read whole panel form
|
||||
//console.log("FormPanel");
|
||||
var settings = {};
|
||||
// Read all selects
|
||||
var selects = form.find("select");
|
||||
selects.each( function(index,element) {
|
||||
var elem = $(element);
|
||||
//var fieldName = elem.attr('name');
|
||||
if(elem.attr('name') != "") {
|
||||
settings[elem.attr('name')] = elem.val();
|
||||
}
|
||||
});
|
||||
// Read all inputs
|
||||
var inputs = form.find("input");
|
||||
inputs.each( function(index,element) {
|
||||
var elem = $(element);
|
||||
if(elem.attr('name') != "") {
|
||||
switch(elem.attr("type")) {
|
||||
case "text":
|
||||
case "number":
|
||||
settings[elem.attr('name')] = elem.val();
|
||||
break;
|
||||
case "checkbox":
|
||||
settings[elem.attr('name')] = elem.prop('checked');
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
// Read all textareas
|
||||
var textareas = form.find("textarea");
|
||||
textareas.each( function(index,element) {
|
||||
var elem = $(element);
|
||||
settings[elem.attr('name')] = elem.val();
|
||||
});
|
||||
console.log(" settings: ",settings);
|
||||
return settings;*/
|
||||
};
|
||||
|
||||
/*this.fillForm = function(settings,form) {
|
||||
console.log("FormPanel:fillForm");
|
||||
if(!form) form = _element; // if no form specified, fill whole panel form
|
||||
console.log(" settings: ",settings);
|
||||
console.log(" form: ",form);
|
||||
//fill form with loaded settings
|
||||
var selects = form.find("select");
|
||||
selects.each( function(index,element) {
|
||||
var elem = $(element);
|
||||
elem.val(settings[elem.attr('name')]);
|
||||
});
|
||||
var inputs = form.find("input");
|
||||
inputs.each( function(index,element) {
|
||||
var elem = $(element);
|
||||
//console.log("printer setting input: ",index,element.attr("type"),element.attr('name')); //,element);
|
||||
switch(elem.attr("type")) {
|
||||
case "text":
|
||||
case "number":
|
||||
elem.val(settings[elem.attr('name')]);
|
||||
break;
|
||||
case "checkbox":
|
||||
elem.prop('checked', settings[elem.attr('name')]);
|
||||
break;
|
||||
}
|
||||
});
|
||||
var textareas = form.find("textarea");
|
||||
textareas.each( function(index,element) {
|
||||
var elem = $(element);
|
||||
var value = settings[elem.attr('name')];
|
||||
elem.val(value);
|
||||
});
|
||||
};
|
||||
|
||||
this.saveSettings = function(newSettings,complete) {
|
||||
console.log("FormPanel:saveSettings");
|
||||
console.log(" newSettings: ",newSettings);
|
||||
console.log(" form: ",form);
|
||||
_configAPI.save(newSettings,function(data) {
|
||||
var validation = data.validation;
|
||||
console.log(" validation: ",validation);
|
||||
clearValidationErrors();
|
||||
var validated = true;
|
||||
$.each(validation, function(key, val) {
|
||||
if (val != "ok") {
|
||||
console.log("ERROR: setting '" + key + "' not successfully set. Message: " + val);
|
||||
displayValidationError(key,val);
|
||||
validated = false;
|
||||
}
|
||||
});
|
||||
settings.substituted_ssid = data.substituted_ssid;
|
||||
if(complete) complete(validated);
|
||||
}, function() {
|
||||
console.log("Settings:saveSettings: failed");
|
||||
clearTimeout(_retrySaveSettingsDelay);
|
||||
_retrySaveSettingsDelay = setTimeout(function() { _self.saveSettings(newSettings,complete); },_retryDelay); // retry after delay
|
||||
});
|
||||
};
|
||||
function displayValidationError(key,msg) {
|
||||
var formElement = _element.find("[name|='"+key+"']");
|
||||
formElement.addClass("error");
|
||||
var errorMsg = "<p class='errorMsg'>"+msg+"</p>";
|
||||
formElement.after(errorMsg);
|
||||
};
|
||||
function clearValidationErrors() {
|
||||
_element.find(".errorMsg").remove();
|
||||
_element.find(".error").removeClass("error");
|
||||
};*/
|
||||
}
|
389
js/settings/NetworkPanel.js
Normal file
389
js/settings/NetworkPanel.js
Normal file
@ -0,0 +1,389 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// prototype inheritance
|
||||
// http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/
|
||||
NetworkPanel.prototype = new FormPanel();
|
||||
function NetworkPanel() {
|
||||
|
||||
// network client mode states
|
||||
/*var CLIENT_MODE_STATE = {
|
||||
NOT_CONNECTED: "not connected", // also used as first item in networks list
|
||||
CONNECTED: "connected",
|
||||
CONNECTING: "connecting",
|
||||
CONNECTING_FAILED: "connecting failed"
|
||||
};
|
||||
var _clientModeState = CLIENT_MODE_STATE.NOT_CONNECTED;
|
||||
|
||||
// network access point mode states
|
||||
var AP_MODE_STATE = {
|
||||
NO_AP: "no ap", // also used as first item in networks list
|
||||
AP: "ap",
|
||||
CREATING_AP: "creating ap"
|
||||
};
|
||||
var _apModeState = AP_MODE_STATE.NO_AP;
|
||||
// network mode
|
||||
var NETWORK_MODE = {
|
||||
NEITHER: "neither",
|
||||
CLIENT: "clientMode",
|
||||
ACCESS_POINT: "accessPointMode"
|
||||
};
|
||||
var _networkMode = NETWORK_MODE.NETWORK_MODE_NEITHER;
|
||||
|
||||
var _api = new NetworkAPI();
|
||||
var _networks = {};
|
||||
var _currentNetwork; // the ssid of the network the box is on
|
||||
var _selectedNetwork; // the ssid of the selected network in the client mode settings
|
||||
var _currentLocalIP = "";
|
||||
|
||||
var _currentAP;
|
||||
|
||||
var _retryRetrieveStatusDelayTime = 1000;
|
||||
var _retryRetrieveStatusDelay;
|
||||
// after switching wifi network or creating a access point we delay the status retrieval
|
||||
// because the webserver needs time to switch
|
||||
var _retrieveNetworkStatusDelayTime = 1000;
|
||||
var _retrieveNetworkStatusDelay;
|
||||
|
||||
// ui elements
|
||||
var _element;
|
||||
var _networkSelector;
|
||||
var _apFieldSet;
|
||||
var _clientFieldSet;
|
||||
var _apRadioButton;
|
||||
var _clientRadioButton;
|
||||
var _btnRefresh
|
||||
var _btnConnect;
|
||||
var _btnCreate;
|
||||
var _passwordField;
|
||||
var _passwordLabel;
|
||||
var _clientStateDisplay;
|
||||
var _apModeStateDisplay;*/
|
||||
|
||||
var _self = this;
|
||||
|
||||
this.init = function(wifiboxURL,wifiboxCGIBinURL,panelElement) {
|
||||
console.log("NetworkPanel:init");
|
||||
// super call:
|
||||
_self.constructor.prototype.init.call(_self,wifiboxURL,wifiboxCGIBinURL,panelElement);
|
||||
|
||||
console.log(" calling readForm from NetworkPanel:init");
|
||||
_self.readForm();
|
||||
|
||||
/*_api.init(wifiboxURL,wifiboxCGIBinURL);
|
||||
|
||||
_element = panelElement;
|
||||
_apRadioButton = _element.find("#ap");
|
||||
_clientRadioButton = _element.find("#client");
|
||||
_btnRefresh = _element.find("#refreshNetworks");
|
||||
_btnConnect = _element.find("#connectToNetwork");
|
||||
_btnCreate = _element.find("#createAP");
|
||||
_networkSelector = _element.find("#network");
|
||||
_apFieldSet = _element.find("#apSettings");
|
||||
_clientFieldSet = _element.find("#clientSettings");
|
||||
_passwordField = _element.find("#password");
|
||||
_passwordLabel = _element.find("#passwordLabel");
|
||||
_clientStateDisplay = _element.find("#clientModeState");
|
||||
_apModeStateDisplay = _element.find("#apModeState");
|
||||
|
||||
_apRadioButton.parent().on('touchstart mousedown',showAPSettings);
|
||||
_clientRadioButton.parent().on('touchstart mousedown',showClientSettings);
|
||||
_btnRefresh.on('touchstart mousedown',onRefreshClick);
|
||||
_btnConnect.on('touchstart mousedown',_self.connectToNetwork);
|
||||
_btnCreate.on('touchstart mousedown',_self.createAP);
|
||||
_networkSelector.change(networkSelectorChanged);*/
|
||||
}
|
||||
/*
|
||||
* Handlers
|
||||
*/
|
||||
/*
|
||||
function showAPSettings() {
|
||||
_apFieldSet.show();
|
||||
_clientFieldSet.hide();
|
||||
};
|
||||
function showClientSettings() {
|
||||
_clientFieldSet.show();
|
||||
_apFieldSet.hide();
|
||||
};
|
||||
function onRefreshClick() {
|
||||
_btnRefresh.attr("disabled", true);
|
||||
_self.refreshNetworks(function() {
|
||||
_btnRefresh.removeAttr("disabled");
|
||||
})
|
||||
}
|
||||
function networkSelectorChanged(e) {
|
||||
var selectedOption = $(this).find("option:selected");
|
||||
_self.selectNetwork(selectedOption.val());
|
||||
};
|
||||
|
||||
this.update = function() {
|
||||
console.log("NetworkPanel:update");
|
||||
_self.refreshNetworks();
|
||||
_self.retrieveStatus(false);
|
||||
}
|
||||
this.refreshNetworks = function(completeHandler) {
|
||||
console.log("NetworkPanel:refreshNetworks");
|
||||
_api.scan(function(data) {
|
||||
//console.log("NetworkPanel:scanned");
|
||||
_networks = {};
|
||||
var foundCurrentNetwork = false;
|
||||
// fill network selector
|
||||
_networkSelector.empty();
|
||||
_networkSelector.append(
|
||||
$("<option></option>").val(CLIENT_MODE_STATE.NOT_CONNECTED).html(CLIENT_MODE_STATE.NOT_CONNECTED)
|
||||
);
|
||||
$.each(data.networks, function(index,element) {
|
||||
if(element.ssid == _currentNetwork) {
|
||||
foundCurrentNetwork = true;
|
||||
}
|
||||
_networkSelector.append(
|
||||
$("<option></option>").val(element.ssid).html(element.ssid)
|
||||
);
|
||||
_networks[element.ssid] = element;
|
||||
});
|
||||
if(foundCurrentNetwork) {
|
||||
_networkSelector.val(_currentNetwork);
|
||||
_self.selectNetwork(_currentNetwork);
|
||||
}
|
||||
if(completeHandler) completeHandler();
|
||||
});
|
||||
};
|
||||
|
||||
this.retrieveStatus = function(connecting) {
|
||||
//console.log("NetworkPanel:retrieveStatus");
|
||||
_api.status(function(data) {
|
||||
if(typeof data.status === 'string') {
|
||||
data.status = parseInt(data.status);
|
||||
}
|
||||
console.log("NetworkPanel:retrievedStatus status: ",data.status,data.statusMessage);
|
||||
|
||||
// Determine which network settings to show
|
||||
switch(data.status) {
|
||||
case NetworkAPI.STATUS.NOT_CONNECTED:
|
||||
setNetworkMode(NETWORK_MODE.NEITHER);
|
||||
break;
|
||||
case NetworkAPI.STATUS.CONNECTING_FAILED:
|
||||
case NetworkAPI.STATUS.CONNECTING:
|
||||
case NetworkAPI.STATUS.CONNECTED:
|
||||
setNetworkMode(NETWORK_MODE.CLIENT);
|
||||
|
||||
if(data.status == SettingsWindow.API_CONNECTED) {
|
||||
_networkSelector.val(data.ssid);
|
||||
|
||||
_currentNetwork = data.ssid;
|
||||
_currentLocalIP = data.localip;
|
||||
_self.selectNetwork(data.ssid);
|
||||
} else {
|
||||
_currentLocalIP = "";
|
||||
}
|
||||
break;
|
||||
case NetworkAPI.STATUS.CREATING:
|
||||
case NetworkAPI.STATUS.CREATED:
|
||||
setNetworkMode(NETWORK_MODE.ACCESS_POINT);
|
||||
|
||||
_currentNetwork = undefined;
|
||||
_self.selectNetwork(CLIENT_MODE_STATE.NOT_CONNECTED);
|
||||
_networkSelector.val(CLIENT_MODE_STATE.NOT_CONNECTED);
|
||||
|
||||
if(data.ssid && data.status == SettingsWindow.API_CREATED) {
|
||||
_currentAP = data.ssid;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// update status message
|
||||
switch(data.status) {
|
||||
case NetworkAPI.STATUS.CONNECTING_FAILED:
|
||||
setClientModeState(CLIENT_MODE_STATE.CONNECTING_FAILED,data.statusMessage);
|
||||
setAPModeState(AP_MODE_STATE.NO_AP,"");
|
||||
break;
|
||||
case NetworkAPI.STATUS.NOT_CONNECTED:
|
||||
setClientModeState(CLIENT_MODE_STATE.NOT_CONNECTED,"");
|
||||
setAPModeState(AP_MODE_STATE.NO_AP,"");
|
||||
break;
|
||||
case NetworkAPI.STATUS.CONNECTING:
|
||||
setClientModeState(CLIENT_MODE_STATE.CONNECTING,"");
|
||||
setAPModeState(AP_MODE_STATE.NO_AP,"");
|
||||
break;
|
||||
case NetworkAPI.STATUS.CONNECTED:
|
||||
setClientModeState(CLIENT_MODE_STATE.CONNECTED,"");
|
||||
setAPModeState(AP_MODE_STATE.NO_AP,"");
|
||||
break;
|
||||
case NetworkAPI.STATUS.CREATING:
|
||||
setClientModeState(CLIENT_MODE_STATE.NOT_CONNECTED,"");
|
||||
setAPModeState(AP_MODE_STATE.CREATING_AP,"");
|
||||
break;
|
||||
case NetworkAPI.STATUS.CREATED:
|
||||
setClientModeState(CLIENT_MODE_STATE.NOT_CONNECTED,"");
|
||||
setAPModeState(AP_MODE_STATE.AP,"");
|
||||
break;
|
||||
}
|
||||
|
||||
// Keep checking for updates?
|
||||
if(connecting) {
|
||||
switch(data.status) {
|
||||
case NetworkAPI.STATUS.CONNECTING:
|
||||
case NetworkAPI.STATUS.CREATING:
|
||||
clearTimeout(_retryRetrieveStatusDelay);
|
||||
_retryRetrieveStatusDelay = setTimeout(function() { _self.retrieveStatus(connecting); },_retryRetrieveStatusDelayTime); // retry after delay
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, function() {
|
||||
console.log("NetworkPanel:retrieveStatus failed");
|
||||
clearTimeout(_retryRetrieveStatusDelay);
|
||||
_retryRetrieveStatusDelay = setTimeout(function() { _self.retrieveStatus(connecting); }, _retryRetrieveStatusDelayTime); // retry after delay
|
||||
});
|
||||
};
|
||||
function setNetworkMode(mode) {
|
||||
//console.log("NetworkPanel:setNetworkMode: ",mode);
|
||||
if(mode == _networkMode) return;
|
||||
switch(mode) {
|
||||
case NETWORK_MODE.NEITHER:
|
||||
_apFieldSet.show();
|
||||
_clientFieldSet.show();
|
||||
break;
|
||||
case NETWORK_MODE.CLIENT:
|
||||
_clientRadioButton.prop('checked',true);
|
||||
_apFieldSet.hide();
|
||||
_clientFieldSet.show();
|
||||
break;
|
||||
case NETWORK_MODE.ACCESS_POINT:
|
||||
_apRadioButton.prop('checked',true);
|
||||
_apFieldSet.show();
|
||||
_clientFieldSet.hide();
|
||||
break;
|
||||
}
|
||||
// TODO
|
||||
//self.updatePanel.setNetworkMode(mode);
|
||||
_networkMode = mode;
|
||||
}
|
||||
|
||||
this.selectNetwork = function(ssid) {
|
||||
console.log("select network: ",ssid);
|
||||
if(ssid == "") return;
|
||||
//console.log(" checked");
|
||||
_selectedNetwork = ssid;
|
||||
if(_networks == undefined || ssid == CLIENT_MODE_STATE.NOT_CONNECTED) {
|
||||
hideWiFiPassword();
|
||||
} else {
|
||||
var network = _networks[ssid];
|
||||
if(network.encryption == "none") {
|
||||
hideWiFiPassword();
|
||||
} else {
|
||||
showWiFiPassword();
|
||||
}
|
||||
_passwordField.val("");
|
||||
}
|
||||
};
|
||||
function showWiFiPassword() {
|
||||
_passwordLabel.show();
|
||||
_passwordField.show();
|
||||
};
|
||||
function hideWiFiPassword() {
|
||||
_passwordLabel.hide();
|
||||
_passwordField.hide();
|
||||
};
|
||||
|
||||
function setClientModeState(state,statusMessage) {
|
||||
var msg = "";
|
||||
switch(state) {
|
||||
case SettingsWindow.NOT_CONNECTED:
|
||||
_btnConnect.removeAttr("disabled");
|
||||
msg = "Not connected";
|
||||
break;
|
||||
case SettingsWindow.CONNECTED:
|
||||
_btnConnect.removeAttr("disabled");
|
||||
|
||||
msg = "Connected to: <b>"+_currentNetwork+"</b>.";
|
||||
if(_currentLocalIP != undefined && _currentLocalIP != "") {
|
||||
var a = "<a href='http://"+_currentLocalIP+"' target='_black'>"+_currentLocalIP+"</a>";
|
||||
msg += " (IP: "+a+")";
|
||||
}
|
||||
break;
|
||||
case SettingsWindow.CONNECTING:
|
||||
_btnConnect.attr("disabled", true);
|
||||
msg = "Connecting... Reconnect by connecting your device to <b>"+_selectedNetwork+"</b> and going to <a href='http://connect.doodle3d.com'>connect.doodle3d.com</a>";
|
||||
break;
|
||||
case SettingsWindow.CONNECTING_FAILED:
|
||||
_btnConnect.removeAttr("disabled");
|
||||
msg = statusMessage;
|
||||
break;
|
||||
}
|
||||
_clientStateDisplay.html(msg);
|
||||
_clientModeState = state;
|
||||
};
|
||||
function setAPModeState(state,statusMessage) {
|
||||
var msg = "";
|
||||
switch(state) {
|
||||
case SettingsWindow.NO_AP:
|
||||
_btnCreate.removeAttr("disabled");
|
||||
msg = "Not currently a access point";
|
||||
break;
|
||||
case SettingsWindow.AP:
|
||||
_btnCreate.removeAttr("disabled");
|
||||
msg = "Is access point: <b>"+_currentAP+"</b>";
|
||||
break;
|
||||
case SettingsWindow.CREATING_AP:
|
||||
_btnCreate.attr("disabled", true);
|
||||
msg = "Creating access point... Reconnect by connecting your device to <b>"+settings.substituted_ssid+"</b> and going to <a href='http://draw.doodle3d.com'>draw.doodle3d.com</a>";
|
||||
break;
|
||||
}
|
||||
_apModeStateDisplay.html(msg);
|
||||
_apModeState = state;
|
||||
};
|
||||
|
||||
this.connectToNetwork = function() {
|
||||
console.log("NetworkPanel:connectToNetwork");
|
||||
if(_selectedNetwork == undefined) return;
|
||||
|
||||
// save network related settings and on complete, connect to network
|
||||
_self.saveSettings(_self.readForm(),function(validated) {
|
||||
if(!validated) return;
|
||||
_api.associate(_selectedNetwork,_passwordField.val(),true);
|
||||
});
|
||||
setClientModeState(CLIENT_MODE_STATE.CONNECTING,"");
|
||||
|
||||
// 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);
|
||||
};
|
||||
|
||||
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); // 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);
|
||||
});
|
||||
}
|
||||
};*/
|
||||
}
|
84
js/settings/PrinterPanel.js
Normal file
84
js/settings/PrinterPanel.js
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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 PrinterPanel() {
|
||||
this.wifiboxURL;
|
||||
this.element;
|
||||
|
||||
this.retryDelay = 1000;
|
||||
this.retryDelayer; // setTimout instance
|
||||
//this.timeoutTime = 3000;
|
||||
|
||||
this.printerType;
|
||||
this.printerSettingsNames;
|
||||
|
||||
var self = this;
|
||||
|
||||
this.init = function(wifiboxURL,element) {
|
||||
self.wifiboxURL = wifiboxURL;
|
||||
self.element = element;
|
||||
|
||||
self.printerSelector = element.find("#printerType");
|
||||
self.printerSelector.change(self.printerSelectorChanged);
|
||||
|
||||
var formElements = element.find("[name]");
|
||||
self.printerSettingsNames = [];
|
||||
formElements.each( function(index,element) {
|
||||
self.printerSettingsNames.push(element.name);
|
||||
});
|
||||
|
||||
var gcodePanel = element.find("#gcodePanel");
|
||||
gcodePanel.coolfieldset({collapsed:true});
|
||||
}
|
||||
this.printerSelectorChanged = function(e) {
|
||||
console.log("PrinterPanel:printerSelectorChanged");
|
||||
console.log("self: ", self);
|
||||
self.printerType = self.printerSelector.find("option:selected").val();
|
||||
self.savePrinterType(self.loadPrinterSettings);
|
||||
}
|
||||
|
||||
this.savePrinterType = function(complete) {
|
||||
console.log("PrinterPanel:savePrinterType");
|
||||
var postData = {};
|
||||
postData[self.printerSelector.attr("name")] = self.printerType;
|
||||
console.log("postData: ",postData);
|
||||
$.ajax({
|
||||
url: self.wifiboxURL + "/config/",
|
||||
type: "POST",
|
||||
dataType: 'json',
|
||||
data: postData,
|
||||
success: function(response){
|
||||
console.log("PrinterPanel:savePrinterType response: ",response);
|
||||
if(complete) complete();
|
||||
}
|
||||
}).fail(function() {
|
||||
console.log("PrinterPanel:savePrinterType: failed");
|
||||
});
|
||||
}
|
||||
this.loadPrinterSettings = function() {
|
||||
console.log("PrinterPanel:loadPrinterSettings");
|
||||
console.log(" self.printerSettingsNames: ",self.printerSettingsNames);
|
||||
var getData = {};
|
||||
$.each(self.printerSettingsNames, function(key, val) {
|
||||
getData[val] = "";
|
||||
});
|
||||
console.log("getData: ",getData);
|
||||
$.ajax({
|
||||
url: self.wifiboxURL + "/config/",
|
||||
dataType: 'json',
|
||||
data: getData,
|
||||
success: function(response){
|
||||
console.log("PrinterPanel:loadPrinterSettings response: ",response);
|
||||
|
||||
self.fillForm(response.data,self.element);
|
||||
}
|
||||
}).fail(function() {
|
||||
console.log("PrinterPanel:loadPrinterSettings: failed");
|
||||
});
|
||||
}
|
||||
}
|
409
js/settings/SettingsWindow.js
Normal file
409
js/settings/SettingsWindow.js
Normal file
@ -0,0 +1,409 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
//these settings are defined in the firmware (conf_defaults.lua) and will be initialized in loadSettings()
|
||||
var settings = {};
|
||||
var settingsPopup;
|
||||
//wrapper to prevent scoping issues in showSettings()
|
||||
function openSettingsWindow() {
|
||||
settingsWindow.loadSettings(function() { // reload settings
|
||||
settingsPopup.open();
|
||||
});
|
||||
}
|
||||
|
||||
function SettingsWindow() {
|
||||
this.wifiboxURL;
|
||||
this.wifiboxCGIBinURL;
|
||||
this.window;
|
||||
this.btnOK;
|
||||
this.form;
|
||||
this.timeoutTime = 3000;
|
||||
this.saveSettingsTimeoutTime = 8000;
|
||||
this.retryDelay = 2000; // retry setTimout delay
|
||||
|
||||
this.retryLoadSettingsDelay; // retry setTimout instance
|
||||
this.retrySaveSettingsDelay; // retry setTimout instance
|
||||
this.retryResetSettingsDelay; // retry setTimout instance
|
||||
|
||||
this.restoreStateField
|
||||
this.restoredStateHideDelayTime = 3000;
|
||||
this.restoredStateHideDelay; // setTimout instance
|
||||
|
||||
// Events
|
||||
SettingsWindow.SETTINGS_LOADED = "settingsLoaded";
|
||||
|
||||
this.updatePanel = new UpdatePanel();
|
||||
this.printerPanel = new PrinterPanel();
|
||||
var _networkPanel = new NetworkPanel();
|
||||
|
||||
var self = this;
|
||||
|
||||
this.init = function(wifiboxURL,wifiboxCGIBinURL) {
|
||||
|
||||
console.log("EARLY initialize network panel");
|
||||
//var _networkPanel = new NetworkPanel();
|
||||
_networkPanel.init(wifiboxURL,wifiboxCGIBinURL);
|
||||
|
||||
|
||||
this.wifiboxURL = wifiboxURL;
|
||||
this.wifiboxCGIBinURL = wifiboxCGIBinURL;
|
||||
|
||||
this.window = $("#popupSettings");
|
||||
this.btnOK = this.window.find(".btnOK");
|
||||
settingsPopup = new Popup($("#popupSettings"), $("#popupMask"));
|
||||
settingsPopup.setEnterEnabled(false);
|
||||
settingsPopup.setAutoCloseEnabled(false);
|
||||
|
||||
this.btnOK.on('touchstart mousedown',settingsPopup.commit);
|
||||
$("#popupSettings").bind("onPopupCancel", function() { settingsPopup.close(); } );
|
||||
$("#popupSettings").bind("onPopupCommit", self.submitwindow);
|
||||
|
||||
//this.window.find("#settingsContainer").load("settings.html", function() {
|
||||
console.log("Settings:finished loading settings.html, now loading settings...");
|
||||
|
||||
self.form = self.window.find("form");
|
||||
self.form.submit(function (e) { self.submitwindow(e); });
|
||||
|
||||
$.ajax({
|
||||
url: self.wifiboxURL + "/printer/listall",
|
||||
dataType: 'json',
|
||||
timeout: self.timeoutTime,
|
||||
success: function(response) {
|
||||
console.log("Settings:printer/listall response: ",response.data.printers);
|
||||
console.log(" this: ",this);
|
||||
// network panel
|
||||
console.log("initialize network panel");
|
||||
var $networkPanelElement = self.form.find("#networkPanel");
|
||||
_networkPanel.init(wifiboxURL,wifiboxCGIBinURL,$networkPanelElement);
|
||||
|
||||
$.each(response.data.printers, function(key, value) {
|
||||
// console.log(key,value);
|
||||
$('#printerType').append($('<option>').text(value).attr('value', key));
|
||||
});
|
||||
|
||||
self.loadSettings();
|
||||
|
||||
self.restoreStateField = self.form.find("#restoreState");
|
||||
self.btnRestoreSettings = self.form.find("#restoreSettings");
|
||||
self.btnRestoreSettings.on('touchstart mousedown',self.resetSettings);
|
||||
|
||||
// update panel
|
||||
var $updatePanelElement = self.form.find("#updatePanel");
|
||||
self.updatePanel.init(wifiboxURL,$updatePanelElement);
|
||||
|
||||
// printer panel
|
||||
var $printerPanelElement = self.form.find("#printerPanel");
|
||||
self.printerPanel.init(wifiboxURL,$printerPanelElement);
|
||||
self.printerPanel.fillForm = self.fillForm;
|
||||
|
||||
|
||||
}
|
||||
}).fail(function() {
|
||||
console.log("FATAL ERROR: Settings:printer/listall failed");
|
||||
});
|
||||
//}); //this.window.find
|
||||
|
||||
}; //this.init
|
||||
|
||||
this.openSettings = function() {
|
||||
self.loadSettings(function() { // reload settings
|
||||
settingsPopup.open();
|
||||
});
|
||||
};
|
||||
|
||||
// this.closeSettings = function(complete) {
|
||||
// settingsPopup.close(complete);
|
||||
// };
|
||||
|
||||
this.submitwindow = function(e) {
|
||||
self.btnOK.attr("disabled",true);
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
self.saveSettings(self.readForm(),function(success){
|
||||
if(success) {
|
||||
settingsPopup.close();
|
||||
self.signin();
|
||||
}
|
||||
self.btnOK.removeAttr("disabled");
|
||||
});
|
||||
|
||||
clearTimeout(self.retryRetrieveNetworkStatusDelay);
|
||||
};
|
||||
|
||||
this.loadSettings = function(complete) {
|
||||
if (!communicateWithWifibox) {
|
||||
console.log(" communicateWithWifibox is false: settings aren't being loaded from wifibox...");
|
||||
return;
|
||||
}
|
||||
console.log("Settings:loadSettings() >> getting new data...");
|
||||
|
||||
$.ajax({
|
||||
url: this.wifiboxURL + "/config/all",
|
||||
dataType: 'json',
|
||||
timeout: this.timeoutTime,
|
||||
success: function(response){
|
||||
console.log("Settings:loadSettings response: ",response);
|
||||
settings = response.data;
|
||||
console.log(" settings: ",settings);
|
||||
self.fillForm(settings);
|
||||
$(document).trigger(SettingsWindow.SETTINGS_LOADED);
|
||||
if(complete) complete();
|
||||
}
|
||||
}).fail(function() {
|
||||
console.log("Settings:loadSettings: failed");
|
||||
clearTimeout(self.retryLoadSettingsDelay);
|
||||
self.retryLoadSettingsDelay = setTimeout(function() { self.loadSettings(); },self.retryDelay); // retry after delay
|
||||
});
|
||||
|
||||
_networkPanel.update();
|
||||
};
|
||||
|
||||
this.fillForm = function(settings,form) {
|
||||
if(!form) form = this.form; // if no form specified, fill whole form
|
||||
|
||||
//fill form with loaded settings
|
||||
var selects = form.find("select");
|
||||
selects.each( function(index,element) {
|
||||
var elem = $(element);
|
||||
elem.val(settings[elem.attr('name')]);
|
||||
});
|
||||
var inputs = form.find("input");
|
||||
inputs.each( function(index,element) {
|
||||
var elem = $(element);
|
||||
//console.log("printer setting input: ",index,element.attr("type"),element.attr('name')); //,element);
|
||||
switch(elem.attr("type")) {
|
||||
case "text":
|
||||
case "number":
|
||||
elem.val(settings[elem.attr('name')]);
|
||||
break;
|
||||
case "checkbox":
|
||||
elem.prop('checked', settings[elem.attr('name')]);
|
||||
break;
|
||||
}
|
||||
});
|
||||
var textareas = form.find("textarea");
|
||||
textareas.each( function(index,element) {
|
||||
var elem = $(element);
|
||||
var value = settings[elem.attr('name')];
|
||||
elem.val(value);
|
||||
});
|
||||
};
|
||||
|
||||
this.saveSettings = function(newSettings,complete) {
|
||||
settings = newSettings; // store new settings in global settings
|
||||
if (communicateWithWifibox) {
|
||||
$.ajax({
|
||||
url: self.wifiboxCGIBinURL + "/config",
|
||||
type: "POST",
|
||||
data: newSettings,
|
||||
dataType: 'json',
|
||||
timeout: self.saveSettingsTimeoutTime,
|
||||
success: function(response){
|
||||
console.log("Settings:saveSettings response: ",response);
|
||||
if(response.status == "error") {
|
||||
clearTimeout(self.retrySaveSettingsDelay);
|
||||
self.retrySaveSettingsDelay = setTimeout(function() { self.saveSettings(settings,complete); },self.retryDelay); // retry after delay
|
||||
} else {
|
||||
var data = response.data;
|
||||
var validation = data.validation;
|
||||
self.clearValidationErrors();
|
||||
var validated = true;
|
||||
$.each(validation, function(key, val) {
|
||||
if (val != "ok") {
|
||||
console.log("ERROR: setting '" + key + "' not successfully set. Message: " + val);
|
||||
self.displayValidationError(key,val);
|
||||
validated = false;
|
||||
}
|
||||
});
|
||||
settings.substituted_ssid = data.substituted_ssid;
|
||||
if(complete) complete(validated);
|
||||
}
|
||||
}
|
||||
}).fail(function() {
|
||||
console.log("Settings:saveSettings: failed");
|
||||
clearTimeout(self.retrySaveSettingsDelay);
|
||||
self.retrySaveSettingsDelay = setTimeout(function() { self.saveSettings(settings,complete); },self.retryDelay); // retry after delay
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.resetSettings = function() {
|
||||
console.log("resetSettings");
|
||||
self.btnRestoreSettings.attr("disabled", true);
|
||||
|
||||
clearTimeout(self.restoredStateHideDelay);
|
||||
|
||||
self.setRestoreState("Restoring...");
|
||||
|
||||
//console.log(" self.wifiboxURL: ",self.wifiboxURL);
|
||||
|
||||
if (communicateWithWifibox) {
|
||||
$.ajax({
|
||||
url: self.wifiboxCGIBinURL + "/config/resetall",
|
||||
type: "POST",
|
||||
dataType: 'json',
|
||||
timeout: this.timeoutTime,
|
||||
success: function(response){
|
||||
console.log("Settings:resetSettings response: ",response);
|
||||
if(response.status == "error") {
|
||||
clearTimeout(self.retryResetSettingsDelay);
|
||||
self.retryResetSettingsDelay = setTimeout(function() { self.resetSettings(); },self.retryDelay); // retry after delay
|
||||
} else {
|
||||
settings = response.data;
|
||||
console.log(" settings: ",settings);
|
||||
self.fillForm(settings);
|
||||
$(document).trigger(SettingsWindow.SETTINGS_LOADED);
|
||||
|
||||
self.btnRestoreSettings.removeAttr("disabled");
|
||||
self.setRestoreState("Settings restored");
|
||||
// auto hide status
|
||||
clearTimeout(self.restoredStateHideDelay);
|
||||
self.restoredStateHideDelay = setTimeout(function() { self.setRestoreState(""); },self.restoredStateHideDelayTime);
|
||||
}
|
||||
}
|
||||
}).fail(function() {
|
||||
console.log("Settings:resetSettings: failed");
|
||||
clearTimeout(self.retryResetSettingsDelay);
|
||||
self.retryResetSettingsDelay = setTimeout(function() { self.resetSettings(); },self.retryDelay); // retry after delay
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.setRestoreState = function(text) {
|
||||
self.restoreStateField.html(text);
|
||||
};
|
||||
|
||||
this.displayValidationError = function(key,msg) {
|
||||
var formElement = self.form.find("[name|='"+key+"']");
|
||||
formElement.addClass("error");
|
||||
var errorMsg = "<p class='errorMsg'>"+msg+"</p>";
|
||||
formElement.after(errorMsg);
|
||||
};
|
||||
|
||||
this.clearValidationErrors = function() {
|
||||
self.form.find(".errorMsg").remove();
|
||||
self.form.find(".error").removeClass("error");
|
||||
};
|
||||
|
||||
this.readForm = function() {
|
||||
//console.log("SettingsWindow:readForm");
|
||||
var settings = {};
|
||||
var selects = self.form.find("select");
|
||||
selects.each( function(index,element) {
|
||||
var elem = $(element);
|
||||
//var fieldName = elem.attr('name');
|
||||
if(elem.attr('name') != "") {
|
||||
settings[elem.attr('name')] = elem.val();
|
||||
}
|
||||
});
|
||||
|
||||
var inputs = self.form.find("input");
|
||||
inputs.each( function(index,element) {
|
||||
var elem = $(element);
|
||||
if(elem.attr('name') != "") {
|
||||
switch(elem.attr("type")) {
|
||||
case "text":
|
||||
case "number":
|
||||
settings[elem.attr('name')] = elem.val();
|
||||
break;
|
||||
case "checkbox":
|
||||
settings[elem.attr('name')] = elem.prop('checked');
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var textareas = self.form.find("textarea");
|
||||
textareas.each( function(index,element) {
|
||||
var elem = $(element);
|
||||
settings[elem.attr('name')] = elem.val();
|
||||
});
|
||||
//console.log(settings);
|
||||
return settings;
|
||||
};
|
||||
|
||||
this.signin = function() {
|
||||
|
||||
// TODO use api.network
|
||||
|
||||
};
|
||||
|
||||
this.downloadlogs = function() {
|
||||
window.location.href = self.wifiboxURL + "/info/logfiles";
|
||||
};
|
||||
|
||||
this.downloadGcode = function() {
|
||||
var gcode = generate_gcode();
|
||||
if (gcode!=undefined) {
|
||||
var blob = new Blob([gcode.join("\n")], {type: "text/plain;charset=utf-8"});
|
||||
saveAs(blob, "doodle3d.gcode");
|
||||
}
|
||||
};
|
||||
|
||||
this.downloadSvg = function() {
|
||||
var svg = saveToSvg();
|
||||
if (svg!=undefined) {
|
||||
var blob = new Blob([svg], {type: "text/plain;charset=utf-8"});
|
||||
saveAs(blob, "doodle3d.svg");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*************************
|
||||
*
|
||||
*
|
||||
* FROM DOODLE3D.INI
|
||||
*
|
||||
*/
|
||||
//TODO: find all references to these variables, replace them and finally remove these.
|
||||
var objectHeight = 20;
|
||||
var layerHeight = .2;
|
||||
//var wallThickness = .5;
|
||||
//var hop = 0;
|
||||
//var speed = 70;
|
||||
//var travelSpeed = 200;
|
||||
var enableTraveling = true;
|
||||
//var filamentThickness = 2.89;
|
||||
var minScale = .3;
|
||||
var maxScale = 1;
|
||||
var shape = "%";
|
||||
var twists = 0;
|
||||
//var useSubLayers = true;
|
||||
//var debug = false; // debug moved to main.js
|
||||
var loglevel = 2;
|
||||
//var zOffset = 0;
|
||||
var serverport = 8888;
|
||||
var autoLoadImage = "hand.txt";
|
||||
var loadOffset = [0, 0]; // x en y ?
|
||||
var showWarmUp = true;
|
||||
var loopAlways = false;
|
||||
var firstLayerSlow = true;
|
||||
var useSubpathColors = false;
|
||||
var autoWarmUp = true;
|
||||
//var maxObjectHeight = 150;
|
||||
var maxScaleDifference = .1;
|
||||
var frameRate = 60;
|
||||
var quitOnEscape = true;
|
||||
var screenToMillimeterScale = .3; // 0.3
|
||||
//var targetTemperature = 220;
|
||||
//var simplifyiterations = 10;
|
||||
//var simplifyminNumPoints = 15;
|
||||
//var simplifyminDistance = 3;
|
||||
//var retractionspeed = 50;
|
||||
//var retractionminDistance = 5;
|
||||
//var retractionamount = 3;
|
||||
var sideis3D = true;
|
||||
var sidevisible = true;
|
||||
var sidebounds = [900, 210, 131, 390];
|
||||
var sideborder = [880, 169, 2, 471];
|
||||
var windowbounds = [0, 0, 800, 500];
|
||||
var windowcenter = true;
|
||||
var windowfullscreen = false;
|
||||
var autoWarmUpCommand = "M104 S230";
|
||||
//var checkTemperatureInterval = 3;
|
||||
var autoWarmUpDelay = 3;
|
262
js/settings/UpdatePanel.js
Normal file
262
js/settings/UpdatePanel.js
Normal file
@ -0,0 +1,262 @@
|
||||
/*
|
||||
* 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 UpdatePanel() {
|
||||
this.wifiboxURL;
|
||||
this.element;
|
||||
|
||||
this.statusCheckInterval = 1000;
|
||||
this.statusCheckDelayer; // setTimout instance
|
||||
this.installedDelay = 90*1000; // Since we can't retrieve status during installation we show the installed text after a fixed delay
|
||||
this.installedDelayer; // setTimout instance
|
||||
this.retryDelay = 1000;
|
||||
this.retryDelayer; // setTimout instance
|
||||
//this.timeoutTime = 3000;
|
||||
|
||||
this.canUpdate = false;
|
||||
this.currentVersion = "";
|
||||
this.newestVersion;
|
||||
this.progress;
|
||||
this.imageSize;
|
||||
|
||||
// states from api, see Doodle3D firmware src/script/d3d-updater.lua
|
||||
UpdatePanel.NONE = 1; // default state
|
||||
UpdatePanel.DOWNLOADING = 2;
|
||||
UpdatePanel.DOWNLOAD_FAILED = 3;
|
||||
UpdatePanel.IMAGE_READY = 4; // download successfull and checked
|
||||
UpdatePanel.INSTALLING = 5;
|
||||
UpdatePanel.INSTALLED = 6;
|
||||
UpdatePanel.INSTALL_FAILED = 7;
|
||||
|
||||
this.state; // update state from api
|
||||
this.stateText = ""; // update state text from api
|
||||
|
||||
this.networkMode; // network modes from SettingsWindow
|
||||
|
||||
var self = this;
|
||||
|
||||
this.init = function(wifiboxURL,updatePanelElement) {
|
||||
|
||||
this.wifiboxURL = wifiboxURL;
|
||||
|
||||
this.element = updatePanelElement;
|
||||
this.retainCheckbox = this.element.find("#retainConfiguration");
|
||||
this.btnUpdate = this.element.find("#update");
|
||||
this.statusDisplay = this.element.find("#updateState");
|
||||
this.infoDisplay = this.element.find("#updateInfo");
|
||||
|
||||
this.retainCheckbox.change(this.retainChanged);
|
||||
this.btnUpdate.click(this.update);
|
||||
|
||||
this.checkStatus(false);
|
||||
}
|
||||
this.retainChanged = function(e) {
|
||||
console.log("UpdatePanel:retainChanged");
|
||||
|
||||
self.setState(self.state,true);
|
||||
}
|
||||
this.update = function() {
|
||||
console.log("UpdatePanel:update");
|
||||
self.downloadUpdate();
|
||||
}
|
||||
this.downloadUpdate = function() {
|
||||
console.log("UpdatePanel:downloadUpdate");
|
||||
$.ajax({
|
||||
url: self.wifiboxURL + "/update/download",
|
||||
type: "POST",
|
||||
dataType: 'json',
|
||||
success: function(response){
|
||||
console.log("UpdatePanel:downloadUpdate response: ",response);
|
||||
}
|
||||
}).fail(function() {
|
||||
console.log("UpdatePanel:downloadUpdate: failed");
|
||||
});
|
||||
self.setState(UpdatePanel.DOWNLOADING);
|
||||
self.startCheckingStatus();
|
||||
}
|
||||
this.installUpdate = function() {
|
||||
console.log("UpdatePanel:installUpdate");
|
||||
|
||||
// should personal sketches and settings be retained over update?
|
||||
var retain = self.retainCheckbox.prop('checked');
|
||||
console.log(" retain: ",retain);
|
||||
|
||||
self.stopCheckingStatus();
|
||||
postData = {no_retain:!retain}
|
||||
$.ajax({
|
||||
url: self.wifiboxURL + "/update/install",
|
||||
type: "POST",
|
||||
data: postData,
|
||||
dataType: 'json',
|
||||
success: function(response){
|
||||
console.log("UpdatePanel:installUpdate response: ",response);
|
||||
}
|
||||
}).fail(function() {
|
||||
console.log("UpdatePanel:installUpdate: no respons (there shouldn't be)");
|
||||
});
|
||||
self.setState(UpdatePanel.INSTALLING);
|
||||
|
||||
clearTimeout(self.installedDelayer);
|
||||
self.installedDelayer = setTimeout(function() { self.setState(UpdatePanel.INSTALLED) },self.installedDelay);
|
||||
}
|
||||
|
||||
this.startCheckingStatus = function() {
|
||||
clearTimeout(self.statusCheckDelayer);
|
||||
clearTimeout(self.retryDelayer);
|
||||
self.statusCheckDelayer = setTimeout(function() { self.checkStatus(true) },self.statusCheckInterval);
|
||||
}
|
||||
this.stopCheckingStatus = function() {
|
||||
clearTimeout(self.statusCheckDelayer);
|
||||
clearTimeout(self.retryDelayer);
|
||||
}
|
||||
this.checkStatus = function(keepChecking) {
|
||||
if (!communicateWithWifibox) return;
|
||||
$.ajax({
|
||||
url: self.wifiboxURL + "/update/status",
|
||||
type: "GET",
|
||||
dataType: 'json',
|
||||
//timeout: self.timeoutTime,
|
||||
success: function(response){
|
||||
console.log("UpdatePanel:checkStatus response: ",response);
|
||||
|
||||
// Keep checking ?
|
||||
if(keepChecking) {
|
||||
switch(self.state){
|
||||
case UpdatePanel.DOWNLOADING:
|
||||
case UpdatePanel.INSTALLING:
|
||||
clearTimeout(self.statusCheckDelayer);
|
||||
self.statusCheckDelayer = setTimeout(function() { self.checkStatus(keepChecking) },self.statusCheckInterval);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(response.status != "error") {
|
||||
var data = response.data;
|
||||
self.handleStatusData(data);
|
||||
}
|
||||
}
|
||||
}).fail(function() {
|
||||
//console.log("UpdatePanel:checkStatus: failed");
|
||||
if(keepChecking) {
|
||||
clearTimeout(self.retryDelayer);
|
||||
self.retryDelayer = setTimeout(function() { self.checkStatus(keepChecking) },self.retryDelay); // retry after delay
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.handleStatusData = function(data) {
|
||||
//console.log("UpdatePanel:handleStatusData");
|
||||
self.canUpdate = data.can_update;
|
||||
|
||||
if(self.currentVersion != data.current_version || self.newestVersion != data.newest_version) {
|
||||
self.currentVersion = data.current_version;
|
||||
self.newestVersion = data.newest_version;
|
||||
self.updateInfoDisplay();
|
||||
}
|
||||
|
||||
self.stateText = data.state_text;
|
||||
self.progress = data.progress; // not always available
|
||||
self.imageSize = data.image_size; // not always available
|
||||
|
||||
self.setState(data.state_code);
|
||||
|
||||
switch(this.state){
|
||||
case UpdatePanel.IMAGE_READY:
|
||||
self.installUpdate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.setState = function(newState,refresh) {
|
||||
console.log("UpdatePanel:setState");
|
||||
if(!refresh && this.state == newState) return;
|
||||
console.log("UpdatePanel:setState: ",this.state," > ",newState,"(",this.stateText,") (networkMode: ",self.networkMode,") (newestVersion: ",self.newestVersion,") (refresh: ",refresh,")");
|
||||
this.state = newState;
|
||||
|
||||
// should personal sketches and settings be retained over update?
|
||||
var retain = self.retainCheckbox.prop('checked');
|
||||
console.log(" retain", retain);
|
||||
|
||||
// download button
|
||||
// if there isn't newestVersion data something went wrong,
|
||||
// probably accessing the internet
|
||||
console.log(" self.newestVersion: ",self.newestVersion);
|
||||
if(self.newestVersion != undefined) {
|
||||
console.log(" this.state: ",this.state);
|
||||
switch(this.state){
|
||||
case UpdatePanel.NONE:
|
||||
case UpdatePanel.DOWNLOAD_FAILED:
|
||||
case UpdatePanel.INSTALL_FAILED:
|
||||
console.log(" self.canUpdate: ",self.canUpdate);
|
||||
if(self.canUpdate || !retain) {
|
||||
self.btnUpdate.removeAttr("disabled");
|
||||
} else {
|
||||
self.btnUpdate.attr("disabled", true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
self.btnUpdate.attr("disabled", true);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
self.btnUpdate.attr("disabled", true);
|
||||
}
|
||||
this.updateStatusDisplay();
|
||||
}
|
||||
this.updateStatusDisplay = function() {
|
||||
var text = "";
|
||||
if(self.newestVersion != undefined) {
|
||||
switch(this.state){
|
||||
case UpdatePanel.NONE:
|
||||
if(self.canUpdate) {
|
||||
text = "Update(s) available.";
|
||||
} else {
|
||||
text = "You're up to date.";
|
||||
}
|
||||
break;
|
||||
case UpdatePanel.DOWNLOADING:
|
||||
text = "Downloading update...";
|
||||
break;
|
||||
case UpdatePanel.DOWNLOAD_FAILED:
|
||||
text = "Downloading update failed.";
|
||||
break;
|
||||
case UpdatePanel.IMAGE_READY:
|
||||
text = "Update downloaded.";
|
||||
break;
|
||||
case UpdatePanel.INSTALLING:
|
||||
text = "Installing update... (will take a minute)";
|
||||
break;
|
||||
case UpdatePanel.INSTALLED:
|
||||
text = "Update complete, please reconnect by connecting your device to the access point of your WiFi box and going to <a href='http://draw.doodle3d.com'>draw.doodle3d.com</a>";
|
||||
//text = "Update complete, please <a href='javascript:location.reload(true);'>refresh Page</a>.";
|
||||
break;
|
||||
case UpdatePanel.INSTALL_FAILED:
|
||||
text = "Installing update failed.";
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if(self.networkMode == SettingsWindow.NETWORK_MODE_ACCESS_POINT) {
|
||||
text = "Can't access internet in access point mode.";
|
||||
} else {
|
||||
text = "Can't access internet.";
|
||||
}
|
||||
}
|
||||
this.statusDisplay.html(text);
|
||||
}
|
||||
this.updateInfoDisplay = function() {
|
||||
var html = 'Current version: ' + self.currentVersion +
|
||||
' (<a target="d3d-curr-relnotes" href="ReleaseNotes.html">release notes</a>). ';
|
||||
if(self.canUpdate) {
|
||||
html += 'Latest version: ' + self.newestVersion +
|
||||
' (<a target="d3d-new-relnotes" href="http://doodle3d.com/updates/images/ReleaseNotes.md">release notes</a>).';
|
||||
}
|
||||
self.infoDisplay.html(html);
|
||||
}
|
||||
this.setNetworkMode = function(networkMode) {
|
||||
self.networkMode = networkMode;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user