mirror of
https://github.com/Doodle3D/doodle3d-client.git
synced 2024-11-21 17:07:55 +01:00
Remove inheritance logic, use FormPanel instead
This commit is contained in:
parent
1394a28c18
commit
05e49a54ff
@ -18,19 +18,21 @@ function FormPanel() {
|
||||
// ui elements
|
||||
var _element;
|
||||
|
||||
var _self;
|
||||
var _self = this;
|
||||
|
||||
FormPanel.prototype.init = function(wifiboxURL,wifiboxCGIBinURL,panelElement) {
|
||||
this.init = function(wifiboxURL,wifiboxCGIBinURL,panelElement) {
|
||||
|
||||
// make _self the scope of which init was called?
|
||||
// needed to have the subclass instance access the same counter
|
||||
_self = this;
|
||||
//console.log("FormPanel:init");
|
||||
//_self = this;
|
||||
//console.log(" _element: ",_element);
|
||||
_element = panelElement;
|
||||
//console.log(" >_element: ",_element);
|
||||
_configAPI.init(wifiboxURL,wifiboxCGIBinURL);
|
||||
};
|
||||
|
||||
//this.readForm = function(form) {
|
||||
FormPanel.prototype.readForm = function(form) {
|
||||
this.readForm = function(form) {
|
||||
//console.log("FormPanel:readForm");
|
||||
if(!form) form = _element; // if no form specified, read whole panel form
|
||||
//console.log("FormPanel");
|
||||
@ -69,11 +71,13 @@ function FormPanel() {
|
||||
return settings;
|
||||
};
|
||||
|
||||
FormPanel.prototype.fill = function(settings,form) {
|
||||
this.fillForm = function(settings,form) {
|
||||
//console.log("FormPanel:fillForm");
|
||||
if(!form) form = _element; // if no form specified, fill whole panel form
|
||||
//console.log(" form: ",form);
|
||||
|
||||
clearValidationErrors();
|
||||
|
||||
//fill form with loaded settings
|
||||
var selects = form.find("select");
|
||||
selects.each( function(index,element) {
|
||||
@ -102,7 +106,7 @@ function FormPanel() {
|
||||
});
|
||||
};
|
||||
|
||||
FormPanel.prototype.saveSettings = function(newSettings,complete) {
|
||||
this.saveSettings = function(newSettings,complete) {
|
||||
//console.log(" newSettings: ",newSettings);
|
||||
_configAPI.save(newSettings,function(data) {
|
||||
var validation = data.validation;
|
||||
|
@ -6,9 +6,6 @@
|
||||
* 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() {
|
||||
|
||||
var NOT_CONNECTED = "not connected"; // used as first item in networks list
|
||||
@ -22,6 +19,7 @@ function NetworkPanel() {
|
||||
var _networkMode = NetworkPanel.NETWORK_MODE.NEITHER;
|
||||
var _networkModeChangedHandler;
|
||||
|
||||
var _form = new FormPanel();
|
||||
var _api = new NetworkAPI();
|
||||
var _networks = {};
|
||||
var _currentNetwork; // the ssid of the network the box is on
|
||||
@ -56,8 +54,8 @@ function NetworkPanel() {
|
||||
|
||||
this.init = function(wifiboxURL,wifiboxCGIBinURL,panelElement) {
|
||||
//console.log("NetworkPanel:init");
|
||||
// super call:
|
||||
_self.constructor.prototype.init.call(_self,wifiboxURL,wifiboxCGIBinURL,panelElement);
|
||||
|
||||
_form.init(wifiboxURL,wifiboxCGIBinURL,panelElement)
|
||||
|
||||
_api.init(wifiboxURL,wifiboxCGIBinURL);
|
||||
|
||||
@ -302,7 +300,7 @@ function NetworkPanel() {
|
||||
//console.log("NetworkPanel:connectToNetwork");
|
||||
if(_selectedNetwork == undefined) return;
|
||||
// save network related settings and on complete, connect to network
|
||||
_self.saveSettings(_self.readForm(),function(validated) {
|
||||
_form.saveSettings(_form.readForm(),function(validated) {
|
||||
if(!validated) return;
|
||||
updateClientModeUI(NetworkAPI.STATUS.CONNECTING,"");
|
||||
_api.associate(_selectedNetwork,_passwordField.val(),true);
|
||||
@ -317,7 +315,7 @@ function NetworkPanel() {
|
||||
this.createAP = function() {
|
||||
//console.log("createAP");
|
||||
// save network related settings and on complete, create access point
|
||||
_self.saveSettings(_self.readForm(),function(success) {
|
||||
_form.saveSettings(_form.readForm(),function(success) {
|
||||
if(!success) return;
|
||||
updateAPModeUI(NetworkAPI.STATUS.CREATING,"");
|
||||
_api.openAP();
|
||||
|
@ -6,12 +6,10 @@
|
||||
* 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/
|
||||
PrinterPanel.prototype = new FormPanel();
|
||||
function PrinterPanel() {
|
||||
|
||||
this.printerType;
|
||||
var _form = new FormPanel();
|
||||
|
||||
// ui elements
|
||||
var _element;
|
||||
@ -19,12 +17,10 @@ function PrinterPanel() {
|
||||
var _printerSettings;
|
||||
|
||||
var _self = this;
|
||||
|
||||
|
||||
this.init = function(wifiboxURL,wifiboxCGIBinURL,panelElement) {
|
||||
|
||||
// super call:
|
||||
_self.constructor.prototype.init.call(_self,wifiboxURL,wifiboxCGIBinURL,panelElement);
|
||||
|
||||
_form.init(wifiboxURL,wifiboxCGIBinURL,panelElement)
|
||||
_element = panelElement;
|
||||
|
||||
_printerSelector = _element.find("#printerType");
|
||||
@ -32,7 +28,7 @@ function PrinterPanel() {
|
||||
|
||||
// we use readForm to get all the settings we need to
|
||||
// reload after changing printer type
|
||||
_printerSettings = _self.readForm();
|
||||
_printerSettings = _form.readForm();
|
||||
|
||||
var gcodePanel = _element.find("#gcodePanel");
|
||||
gcodePanel.coolfieldset({collapsed:true});
|
||||
@ -42,10 +38,10 @@ function PrinterPanel() {
|
||||
var settings = {};
|
||||
settings[_printerSelector.attr("name")] = _self.printerType;
|
||||
|
||||
_self.saveSettings(settings,function(validated) {
|
||||
_form.saveSettings(settings,function(validated) {
|
||||
if(!validated) return;
|
||||
_self.loadSettings(_printerSettings,function(settings) {
|
||||
_self.fill(settings);
|
||||
_form.loadSettings(_printerSettings,function(settings) {
|
||||
_form.fillForm(settings);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user