Fix: Also provide custom control parameters to custom GCODE scripts

Closes #1085
This commit is contained in:
Gina Häußge 2015-10-19 13:45:40 +02:00
parent 4cfc74c344
commit 66fbd1fc6a
2 changed files with 28 additions and 25 deletions

View file

@ -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);
}
}
});

View file

@ -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);
}
};