From f12c3903c09b3f75875123c17ca41c623c9a0f14 Mon Sep 17 00:00:00 2001 From: ntoff Date: Thu, 23 Mar 2017 08:54:26 +1000 Subject: [PATCH] function to check if user and printer is operational clean up the jinja a bit too --- octoprint_estop/static/js/estop.js | 14 ++++++++++---- octoprint_estop/templates/estop_sidebar.jinja2 | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/octoprint_estop/static/js/estop.js b/octoprint_estop/static/js/estop.js index 8ee5edb..5ee27c0 100644 --- a/octoprint_estop/static/js/estop.js +++ b/octoprint_estop/static/js/estop.js @@ -7,10 +7,16 @@ $(function() { var self = this; //see if we're logged in and the printer is operational (for en/disable of button) self.loginState = parameters[0]; - self.terminal = parameters[1]; - + self.printerState = parameters[1]; + + self.enableEstop = ko.pureComputed(function() { + return self.printerState.isOperational() && self.loginState.isUser(); + }); + self.sendEstopCommand = function () { - OctoPrint.control.sendGcode("M112"); //should this ever be a variable? M112 universal? + if (self.enableEstop()) { + OctoPrint.control.sendGcode("M112"); + }; }; } @@ -18,7 +24,7 @@ $(function() { construct: EstopViewModel, dependencies: [ "loginStateViewModel", - "terminalViewModel", + "printerStateViewModel", ], elements: ["#sidebar_plugin_estop"] }); diff --git a/octoprint_estop/templates/estop_sidebar.jinja2 b/octoprint_estop/templates/estop_sidebar.jinja2 index cc384c9..8f6e5a9 100644 --- a/octoprint_estop/templates/estop_sidebar.jinja2 +++ b/octoprint_estop/templates/estop_sidebar.jinja2 @@ -1,4 +1,4 @@
- +