diff --git a/src/octoprint/static/js/app/client/control.js b/src/octoprint/static/js/app/client/control.js index d1a0eae7..a9b7187a 100644 --- a/src/octoprint/static/js/app/client/control.js +++ b/src/octoprint/static/js/app/client/control.js @@ -22,8 +22,21 @@ }, opts); }; + var sendGcodeScriptWithParameters = function(script, context, parameters, opts) { + script = script || ""; + context = context || {}; + parameters = parameters || {}; + + return OctoPrint.postJson(commandUrl, { + script: script, + context: context, + parameters: parameters + }, opts); + }; + OctoPrint.control = { sendGcodeWithParameters: sendGcodeWithParameters, + sendGcodeScriptWithParameters: sendGcodeScriptWithParameters, getCustomControls: function (opts) { return OctoPrint.get(customUrl, opts); @@ -34,13 +47,7 @@ }, sendGcodeScript: function (script, context, opts) { - script = script || ""; - context = context || {}; - - return OctoPrint.postJson(commandUrl, { - script: script, - context: context - }, opts); + return sendGcodeScriptWithParameters(script, context, undefined, opts); } } }); diff --git a/src/octoprint/static/js/app/viewmodels/control.js b/src/octoprint/static/js/app/viewmodels/control.js index 70865873..d6c944c9 100644 --- a/src/octoprint/static/js/app/viewmodels/control.js +++ b/src/octoprint/static/js/app/viewmodels/control.js @@ -287,30 +287,26 @@ $(function() { }; self.sendCustomCommand = function (command) { - if (!command) - return; + if (!command) return; + + var parameters = {}; + if (command.hasOwnProperty("input")) { + _.each(command.input, function (input) { + if (!input.hasOwnProperty("parameter") || !input.hasOwnProperty("value")) { + return; + } + + parameters[input.parameter] = input.value(); + }); + } if (command.hasOwnProperty("command") || command.hasOwnProperty("commands")) { var commands = command.commands || [command.command]; - - if (command.hasOwnProperty("input")) { - var parameters = {}; - _.each(command.input, function(input) { - if (!input.hasOwnProperty("parameter") || !input.hasOwnProperty("value")) { - return; - } - - parameters[input.parameter] = input.value(); - }); - OctoPrint.control.sendGcodeWithParameters(commands, parameters); - } else { - OctoPrint.control.sendGcode(commands); - } + OctoPrint.control.sendGcodeWithParameters(commands, parameters); } else if (command.hasOwnProperty("script")) { var script = command.script; var context = command.context || {}; - - OctoPrint.control.sendGcodeScript(script, context); + OctoPrint.control.sendGcodeScriptWithParameters(script, context, parameters); } };