diff --git a/docs/features/custom_controls.rst b/docs/features/custom_controls.rst index a953617e9..f130596c1 100644 --- a/docs/features/custom_controls.rst +++ b/docs/features/custom_controls.rst @@ -166,6 +166,10 @@ Controls clicked. This allows to override the direct sending of the command or commands to the printer with more sophisticated behaviour. The JavaScript snippet is ``eval``'d and processed in a context where the control it is part of is provided as local variable ``data`` and the ``ControlViewModel`` is available as ``self``. + * - ``additionalClasses`` + - (Optional) Additional classes to apply to the button of a ``command``, ``commands``, ``script`` or ``javascript`` + control, other than the default ``btn``. Can be used to visually style the button, e.g. set to ``btn-danger`` to + turn the button red. * - ``enabled`` - (Optional) A JavaScript snippet returning either ``true`` or ``false`` determining whether the control should be enabled or not. This allow to override the default logic for this (disabled if printer is offline diff --git a/src/octoprint/static/js/app/viewmodels/control.js b/src/octoprint/static/js/app/viewmodels/control.js index 0f38329de..072205414 100644 --- a/src/octoprint/static/js/app/viewmodels/control.js +++ b/src/octoprint/static/js/app/viewmodels/control.js @@ -226,6 +226,10 @@ $(function() { } } + if (control.hasOwnProperty("command") && !control.hasOwnProperty("additionalClasses")) { + control.additionalClasses = ""; + } + control.processed = true; return control; }; diff --git a/src/octoprint/templates/tabs/control.jinja2 b/src/octoprint/templates/tabs/control.jinja2 index a3c8cc633..14b672508 100644 --- a/src/octoprint/templates/tabs/control.jinja2 +++ b/src/octoprint/templates/tabs/control.jinja2 @@ -173,6 +173,6 @@