From 2edba7a4c923c1858ee672bf65c0b7b6e3405c0d Mon Sep 17 00:00:00 2001 From: Rick Companje Date: Thu, 5 Dec 2013 17:32:29 +0100 Subject: [PATCH] SettingsWindow printerType dropdown is now populated by API call --- js_src/SettingsWindow.js | 191 +++++++++++++------------- js_src/gcodeGenerating.js | 110 ++------------- js_src/libs/jquery-coolfieldset.js | 3 +- js_src/main.js | 5 +- www/img/buttons/btnOk.png | Bin 5198 -> 12653 bytes www/img/buttons/btnOk_settings.png | Bin 3568 -> 0 bytes www/img/buttons/btnReset_settings.png | Bin 7564 -> 0 bytes www/index.html | 2 +- www/settings.html | 21 ++- 9 files changed, 129 insertions(+), 203 deletions(-) delete mode 100644 www/img/buttons/btnOk_settings.png delete mode 100644 www/img/buttons/btnReset_settings.png diff --git a/js_src/SettingsWindow.js b/js_src/SettingsWindow.js index 02f420d..f38c8b4 100644 --- a/js_src/SettingsWindow.js +++ b/js_src/SettingsWindow.js @@ -1,30 +1,5 @@ //these settings are defined in the firmware (conf_defaults.lua) and will be initialized in loadSettings() -var settings = { -"network.ap.ssid": "d3d-ap-%%MAC_ADDR_TAIL%%", -"network.ap.address": "192.168.10.1", -"network.ap.netmask": "255.255.255.0", -"printer.temperature": 220, -"printer.maxObjectHeight": 150, -"printer.layerHeight": 0.2, -"printer.wallThickness": 0.7, -"printer.screenToMillimeterScale": 0.3, -"printer.speed": 50, -"printer.travelSpeed": 200, -"printer.filamentThickness": 2.85, -"printer.enableTraveling": true, -"printer.useSubLayers": true, -"printer.firstLayerSlow": true, -"printer.autoWarmUp": true, -"printer.simplify.iterations": 10, -"printer.simplify.minNumPoints": 15, -"printer.simplify.minDistance": 3, -"printer.retraction.enabled": true, -"printer.retraction.speed": 50, -"printer.retraction.minDistance": 1, -"printer.retraction.amount": 5, -"printer.autoWarmUpCommand": "M104 S220 (hardcoded temperature)" -} - +var settings = { } //wrapper to prevent scoping issues in showSettings() function openSettingsWindow() { @@ -45,52 +20,52 @@ function SettingsWindow() { this.retrySaveSettingsDelay; // retry setTimout instance this.retryResetSettingsDelay // retry setTimout instance this.retryRetrieveNetworkStatusDelay;// retry setTimout instance - + this.apFieldSet; this.clientFieldSet; this.networks; this.currentNetwork; // the ssid of the network the box is on - this.selectedNetwork; // the ssid of the selected network in the client mode settings - this.currentLocalIP = ""; - this.clientModeState = SettingsWindow.NOT_CONNECTED; - this.currentAP; - this.apModeState = SettingsWindow.NO_AP; + this.selectedNetwork; // the ssid of the selected network in the client mode settings + this.currentLocalIP = ""; + this.clientModeState = SettingsWindow.NOT_CONNECTED; + this.currentAP; + this.apModeState = SettingsWindow.NO_AP; - // after switching wifi network or creating a access point we delay the status retrieval - // because the webserver needs time to switch - this.retrieveNetworkStatusDelay; // setTimout delay - this.retrieveNetworkStatusDelayTime = 1000; + // after switching wifi network or creating a access point we delay the status retrieval + // because the webserver needs time to switch + this.retrieveNetworkStatusDelay; // setTimout delay + this.retrieveNetworkStatusDelayTime = 1000; // Events SettingsWindow.SETTINGS_LOADED = "settingsLoaded"; - // network client mode states - SettingsWindow.NOT_CONNECTED = "not connected"; // also used as first item in networks list - SettingsWindow.CONNECTED = "connected"; - SettingsWindow.CONNECTING = "connecting"; - SettingsWindow.CONNECTING_FAILED = "connecting failed" + // network client mode states + SettingsWindow.NOT_CONNECTED = "not connected"; // also used as first item in networks list + SettingsWindow.CONNECTED = "connected"; + SettingsWindow.CONNECTING = "connecting"; + SettingsWindow.CONNECTING_FAILED = "connecting failed" - // network access point mode states - SettingsWindow.NO_AP = "no ap"; - SettingsWindow.AP = "ap"; - SettingsWindow.CREATING_AP = "creating ap"; + // network access point mode states + SettingsWindow.NO_AP = "no ap"; + SettingsWindow.AP = "ap"; + SettingsWindow.CREATING_AP = "creating ap"; - SettingsWindow.API_CONNECTING_FAILED = -1 - SettingsWindow.API_NOT_CONNECTED = 0 - SettingsWindow.API_CONNECTING = 1 - SettingsWindow.API_CONNECTED = 2 - SettingsWindow.API_CREATING = 3 - SettingsWindow.API_CREATED = 4 + SettingsWindow.API_CONNECTING_FAILED = -1 + SettingsWindow.API_NOT_CONNECTED = 0 + SettingsWindow.API_CONNECTING = 1 + SettingsWindow.API_CONNECTED = 2 + SettingsWindow.API_CREATING = 3 + SettingsWindow.API_CREATED = 4 - // network mode - SettingsWindow.NETWORK_MODE_NEITHER = "neither"; - SettingsWindow.NETWORK_MODE_CLIENT = "clientMode"; - SettingsWindow.NETWORK_MODE_ACCESS_POINT = "accessPointMode"; + // network mode + SettingsWindow.NETWORK_MODE_NEITHER = "neither"; + SettingsWindow.NETWORK_MODE_CLIENT = "clientMode"; + SettingsWindow.NETWORK_MODE_ACCESS_POINT = "accessPointMode"; - this.networkMode = SettingsWindow.NETWORK_MODE_NEITHER; + this.networkMode = SettingsWindow.NETWORK_MODE_NEITHER; - this.updatePanel = new UpdatePanel(); - this.printerPanel = new PrinterPanel(); + this.updatePanel = new UpdatePanel(); + this.printerPanel = new PrinterPanel(); var self = this; @@ -101,45 +76,61 @@ function SettingsWindow() { this.window = $("#settings"); this.btnOK = this.window.find(".btnOK"); enableButton(this.btnOK,this.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"); + 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) }); - self.loadSettings(); - - - var btnAP = self.form.find("label[for='ap']"); - var btnClient = self.form.find("label[for='client']"); - var btnRefresh = self.form.find("#refreshNetworks"); - var btnConnect = self.form.find("#connectToNetwork"); - var btnCreate = self.form.find("#createAP"); - var networkSelector = self.form.find("#network"); - self.apFieldSet = self.form.find("#apSettings"); - self.clientFieldSet = self.form.find("#clientSettings"); - self.btnRestoreSettings = self.form.find("#restoreSettings"); - - btnAP.on('touchstart mousedown',self.showAPSettings); - btnClient.on('touchstart mousedown',self.showClientSettings); - btnRefresh.on('touchstart mousedown',self.refreshNetworks); - btnConnect.on('touchstart mousedown',self.connectToNetwork); - btnCreate.on('touchstart mousedown',self.createAP); - networkSelector.change(self.networkSelectorChanged); - 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; - - }); - } + $.ajax({ + url: self.wifiboxURL + "/printer/listall", + dataType: 'json', + timeout: self.timeoutTime, + success: function(response) { + console.log("Settings:printer/listall response: ",response.data.printers); + + $.each(response.data.printers, function(key, value) { + // console.log(key,value); + $('#printerType').append($('