From fb6ff04013716b460252d63c95e95e75915ccc6c Mon Sep 17 00:00:00 2001 From: ntoff Date: Wed, 7 Mar 2018 22:04:09 +1000 Subject: [PATCH] Add a confirmation to disconnect while printing Fullfills a feature request: https://github.com/foosel/OctoPrint/issues/2287 Add a confirmation dialog if a user attempts to disconnect while a print is in progress --- .../static/js/app/viewmodels/connection.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/connection.js b/src/octoprint/static/js/app/viewmodels/connection.js index bfdf03bfb..2c8bf90b7 100644 --- a/src/octoprint/static/js/app/viewmodels/connection.js +++ b/src/octoprint/static/js/app/viewmodels/connection.js @@ -125,8 +125,24 @@ $(function() { self.settings.printerProfiles.requestData(); }); } else { - self.requestData(); - OctoPrint.connection.disconnect(); + if (!self.isPrinting() && !self.isPaused()) { + self.requestData(); + OctoPrint.connection.disconnect(); + } else { + showConfirmationDialog({ + title: gettext("Are you sure?"), + message: gettext("

You are about to disconnect from the printer while a print is in progress.

\ +

Disconnecting while a print is in progress will prevent OctoPrint from completing the print. If you're printing from an SD card attached directly to the printer, any attempt to restart OctoPrint or reconnect to the printer could interrupt the print.

"), + question: gettext("Are you sure you want to disconnect from the printer?"), + cancel: gettext("Stay Connected"), + proceed: gettext("Disconnect"), + onproceed: function() { + self.requestData(); + OctoPrint.connection.disconnect(); + } + }) + } + } };