From f783726c47e111b0c392a3703f2a5bcd6afbb6ea Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Mon, 28 Oct 2013 01:26:58 +0100 Subject: [PATCH] A little less code duplication --- js_src/SettingsWindow.js | 18 +++++++++++++----- js_src/gcodeGenerating.js | 19 +++++++------------ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/js_src/SettingsWindow.js b/js_src/SettingsWindow.js index 3542ab1..de546fb 100644 --- a/js_src/SettingsWindow.js +++ b/js_src/SettingsWindow.js @@ -310,16 +310,24 @@ function SettingsWindow() { this.printerSelectorChanged = function(e) { var selectedOption = self.printerSelector.find("option:selected"); - switch(selectedOption.val()) { + if(self.isMarlinPrinter(selectedOption.val())) { + self.x3gSettings.hide(); + self.gcodeSettings.show(); + } else { + self.gcodeSettings.hide(); + self.x3gSettings.show(); + } + } + + this.isMarlinPrinter = function(printer) { + switch(printer) { case "makerbot_generic": case "makerbot_replicator2": case "makerbot_thingomatic": - self.gcodeSettings.hide(); - self.x3gSettings.show(); + return false; break; default: - self.x3gSettings.hide(); - self.gcodeSettings.show(); + return true; break; } } diff --git a/js_src/gcodeGenerating.js b/js_src/gcodeGenerating.js index d2da941..95eebe9 100644 --- a/js_src/gcodeGenerating.js +++ b/js_src/gcodeGenerating.js @@ -65,19 +65,14 @@ function generate_gcode() { var startCode = ""; var endCode = ""; - switch(printerType) { - case "makerbot_generic": - case "makerbot_replicator2": - case "makerbot_thingomatic": - startCode = settings["printer.startcode.x3g"]; - endCode = settings["printer.endcode.x3g"]; - break; - default: - startCode = settings["printer.startcode.marlin"]; - endCode = settings["printer.endcode.marlin"]; - break; + if(settingsWindow.isMarlinPrinter(printerType)) { + startCode = settings["printer.startcode.marlin"]; + endCode = settings["printer.endcode.marlin"]; + } else { + startCode = settings["printer.startcode.x3g"]; + endCode = settings["printer.endcode.x3g"]; } - + startCode = subsituteVariables(startCode,temperature,bedTemperature,preheatTemperature,preheatBedTemperature); startCode = startCode.split("\n");