From 09ff8e995341beb8946ca704768511892a23eefe Mon Sep 17 00:00:00 2001 From: electr0sheep Date: Wed, 21 Feb 2018 23:12:43 -0700 Subject: [PATCH] added button styling functionality, removed "output" in the menu --- octoprint_customControl/__init__.py | 1 - .../static/js/customControl.js | 46 ++++++++++++++++--- .../static/js/customControlDialog.js | 7 ++- .../customControl_hookedsettings.jinja2 | 33 +++++++++---- 4 files changed, 69 insertions(+), 18 deletions(-) diff --git a/octoprint_customControl/__init__.py b/octoprint_customControl/__init__.py index 4a134fc..9090bc7 100644 --- a/octoprint_customControl/__init__.py +++ b/octoprint_customControl/__init__.py @@ -8,7 +8,6 @@ from octoprint.settings import settings import octoprint.plugin - class CustomControlPlugin(octoprint.plugin.SettingsPlugin, octoprint.plugin.TemplatePlugin, octoprint.plugin.AssetPlugin): diff --git a/octoprint_customControl/static/js/customControl.js b/octoprint_customControl/static/js/customControl.js index 37960a3..aaa57b1 100644 --- a/octoprint_customControl/static/js/customControl.js +++ b/octoprint_customControl/static/js/customControl.js @@ -225,12 +225,13 @@ else control.collapsed = ko.observable(false); } - + if (control.hasOwnProperty("input")) { control.input = ko.observableArray(self._processInput(control.input)); } control.name = ko.observable(control.name || ""); + control.style = ko.observable(control.style || ""); control.width = ko.observable(control.hasOwnProperty("width") ? control.width : "2"); control.offset = ko.observable(control.hasOwnProperty("offset") ? control.offset : ""); @@ -310,6 +311,18 @@ }); } } + self.editElementStyle = function (invokedOn, contextParent, selectedMenu, style) { + var element = self.searchElement(self.controlsFromServer, contextParent.attr('id')); + if (element == undefined) { + self._showPopup({ + title: gettext("Something went wrong while creating the new Element"), + type: "error" + }); + return; + } + + element.style("btn " + style); + } self.deleteElement = function (invokedOn, contextParent, selectedMenu) { var element = self.searchElement(self.controlsFromServer, contextParent.attr('id')); if (element == undefined) { @@ -417,7 +430,7 @@ switch (self.customControlDialogViewModel.type()) { case "container": { - element.name(ret.name); + element.name(ret.name); element.layout(ret.layout); element.collapsed(ret.collapsed); break; @@ -521,6 +534,30 @@ self.deleteElement(invokedOn, contextParent, selectedMenu); break; } + case "editStyleNormal": { + self.editElementStyle(invokedOn, contextParent, selectedMenu, ""); + break; + } + case "editStylePrimary": { + self.editElementStyle(invokedOn, contextParent, selectedMenu, "btn-primary"); + break; + } + case "editStyleDanger": { + self.editElementStyle(invokedOn, contextParent, selectedMenu, "btn-danger"); + break; + } + case "editStyleWarning": { + self.editElementStyle(invokedOn, contextParent, selectedMenu, "btn-warning"); + break; + } + case "editStyleSuccess": { + self.editElementStyle(invokedOn, contextParent, selectedMenu, "btn-success"); + break; + } + case "editStyleInfo": { + self.editElementStyle(invokedOn, contextParent, selectedMenu, "btn-info"); + break; + } default: { if (selectedMenu.attr('cmd').startsWith("create")) { switch (selectedMenu.attr('cmd')) { @@ -553,9 +590,6 @@ } } - self.editStyle = function (type) { - } - self.recursiveDeleteProperties = function (list) { _.each(list, function (element, index, ll) { if (!element.parent || (element.parent.hasOwnProperty("layout") && element.parent.layout() != "horizontal_grid")) { @@ -618,4 +652,4 @@ ["loginStateViewModel", "settingsViewModel", "controlViewModel", "customControlDialogViewModel"], "#settings_plugin_customControl" ]); -}); \ No newline at end of file +}); diff --git a/octoprint_customControl/static/js/customControlDialog.js b/octoprint_customControl/static/js/customControlDialog.js index 6ff9c1f..d5ecd1d 100644 --- a/octoprint_customControl/static/js/customControlDialog.js +++ b/octoprint_customControl/static/js/customControlDialog.js @@ -30,7 +30,7 @@ return false; var inputs = self.element().input() - for(var i = 0; i < inputs.length; i++) + for(var i = 0; i < inputs.length; i++) { if (inputs[i].hasOwnProperty("slider")) { if (typeof inputs[i].slider == "object") @@ -59,6 +59,7 @@ self.reset = function (data) { var element = { name: undefined, + style: "", collapsed: false, commands: "", confirm: "", @@ -105,6 +106,7 @@ } case "command": { el.name = obj.name; + el.style = "btn"; if (obj.commands.indexOf('\n') == -1) el.command = obj.commands; else @@ -165,6 +167,7 @@ case "script": { el.name = obj.name; + el.style = "btn"; el.script = obj.script; if (self.useConfirm()) { @@ -254,4 +257,4 @@ [], "#customControlDialog" ]); -}); \ No newline at end of file +}); diff --git a/octoprint_customControl/templates/customControl_hookedsettings.jinja2 b/octoprint_customControl/templates/customControl_hookedsettings.jinja2 index 16c9533..2f7727e 100644 --- a/octoprint_customControl/templates/customControl_hookedsettings.jinja2 +++ b/octoprint_customControl/templates/customControl_hookedsettings.jinja2 @@ -3,14 +3,14 @@
- + +