From 6765b25803f95eeb460e51618ae4f2ed82d7051c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 21 May 2019 10:37:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20action=20prompt:=20show=20icon?= =?UTF-8?q?=20for=20dismissed=20prompts=20in=20navbar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static/js/action_command_prompt.js | 42 +++++++++++++++---- .../action_command_prompt_navbar.jinja2 | 3 ++ 2 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 src/octoprint/plugins/action_command_prompt/templates/action_command_prompt_navbar.jinja2 diff --git a/src/octoprint/plugins/action_command_prompt/static/js/action_command_prompt.js b/src/octoprint/plugins/action_command_prompt/static/js/action_command_prompt.js index c55ab7909..cb7181cda 100644 --- a/src/octoprint/plugins/action_command_prompt/static/js/action_command_prompt.js +++ b/src/octoprint/plugins/action_command_prompt/static/js/action_command_prompt.js @@ -4,7 +4,17 @@ $(function() { self.loginState = parameters[0]; - self._modal = undefined; + self.modal = ko.observable(undefined); + + self.text = ko.observable(); + self.buttons = ko.observableArray([]); + + self.active = ko.pureComputed(function() { + return self.text() !== undefined; + }); + self.visible = ko.pureComputed(function() { + return self.modal() !== undefined; + }); self.requestData = function() { if (!self.loginState.isUser()) return; @@ -15,11 +25,19 @@ $(function() { self.fromResponse = function(data) { if (data.hasOwnProperty("text") && data.hasOwnProperty("choices")) { - self._showPrompt(data.text, data.choices); + self.text(data.text); + self.buttons(data.choices); + self.showPrompt(); + } else { + self.text(undefined); + self.buttons([]); } }; - self._showPrompt = function(text, buttons) { + self.showPrompt = function() { + var text = self.text(); + var buttons = self.buttons(); + var opts = { title: gettext("Message from your printer"), message: text, @@ -31,11 +49,11 @@ $(function() { } }, onclose: function() { - self._modal = undefined; + self.modal(undefined); } }; - self._modal = showSelectionDialog(opts) + self.modal(showSelectionDialog(opts)); }; self._select = function(index) { @@ -43,8 +61,9 @@ $(function() { }; self._closePrompt = function() { - if (self._modal) { - self._modal.modal("hide"); + var modal = self.modal(); + if (modal) { + modal.modal("hide"); } }; @@ -60,10 +79,14 @@ $(function() { switch (data.action) { case "show": { - self._showPrompt(data.text, data.choices); + self.text(data.text); + self.buttons(data.choices); + self.showPrompt(); break; } case "close": { + self.text(undefined); + self.buttons([]); self._closePrompt(); break; } @@ -74,6 +97,7 @@ $(function() { OCTOPRINT_VIEWMODELS.push({ construct: ActionCommandPromptViewModel, - dependencies: ["loginStateViewModel"] + dependencies: ["loginStateViewModel"], + elements: ["#navbar_plugin_action_command_prompt"] }); }); diff --git a/src/octoprint/plugins/action_command_prompt/templates/action_command_prompt_navbar.jinja2 b/src/octoprint/plugins/action_command_prompt/templates/action_command_prompt_navbar.jinja2 new file mode 100644 index 000000000..584c486b2 --- /dev/null +++ b/src/octoprint/plugins/action_command_prompt/templates/action_command_prompt_navbar.jinja2 @@ -0,0 +1,3 @@ +