added button styling functionality, removed "output" in the menu
This commit is contained in:
@ -8,7 +8,6 @@ from octoprint.settings import settings
|
|||||||
|
|
||||||
import octoprint.plugin
|
import octoprint.plugin
|
||||||
|
|
||||||
|
|
||||||
class CustomControlPlugin(octoprint.plugin.SettingsPlugin,
|
class CustomControlPlugin(octoprint.plugin.SettingsPlugin,
|
||||||
octoprint.plugin.TemplatePlugin,
|
octoprint.plugin.TemplatePlugin,
|
||||||
octoprint.plugin.AssetPlugin):
|
octoprint.plugin.AssetPlugin):
|
||||||
|
@ -225,12 +225,13 @@
|
|||||||
else
|
else
|
||||||
control.collapsed = ko.observable(false);
|
control.collapsed = ko.observable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (control.hasOwnProperty("input")) {
|
if (control.hasOwnProperty("input")) {
|
||||||
control.input = ko.observableArray(self._processInput(control.input));
|
control.input = ko.observableArray(self._processInput(control.input));
|
||||||
}
|
}
|
||||||
|
|
||||||
control.name = ko.observable(control.name || "");
|
control.name = ko.observable(control.name || "");
|
||||||
|
control.style = ko.observable(control.style || "");
|
||||||
|
|
||||||
control.width = ko.observable(control.hasOwnProperty("width") ? control.width : "2");
|
control.width = ko.observable(control.hasOwnProperty("width") ? control.width : "2");
|
||||||
control.offset = ko.observable(control.hasOwnProperty("offset") ? control.offset : "");
|
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) {
|
self.deleteElement = function (invokedOn, contextParent, selectedMenu) {
|
||||||
var element = self.searchElement(self.controlsFromServer, contextParent.attr('id'));
|
var element = self.searchElement(self.controlsFromServer, contextParent.attr('id'));
|
||||||
if (element == undefined) {
|
if (element == undefined) {
|
||||||
@ -417,7 +430,7 @@
|
|||||||
|
|
||||||
switch (self.customControlDialogViewModel.type()) {
|
switch (self.customControlDialogViewModel.type()) {
|
||||||
case "container": {
|
case "container": {
|
||||||
element.name(ret.name);
|
element.name(ret.name);
|
||||||
element.layout(ret.layout);
|
element.layout(ret.layout);
|
||||||
element.collapsed(ret.collapsed);
|
element.collapsed(ret.collapsed);
|
||||||
break;
|
break;
|
||||||
@ -521,6 +534,30 @@
|
|||||||
self.deleteElement(invokedOn, contextParent, selectedMenu);
|
self.deleteElement(invokedOn, contextParent, selectedMenu);
|
||||||
break;
|
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: {
|
default: {
|
||||||
if (selectedMenu.attr('cmd').startsWith("create")) {
|
if (selectedMenu.attr('cmd').startsWith("create")) {
|
||||||
switch (selectedMenu.attr('cmd')) {
|
switch (selectedMenu.attr('cmd')) {
|
||||||
@ -553,9 +590,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.editStyle = function (type) {
|
|
||||||
}
|
|
||||||
|
|
||||||
self.recursiveDeleteProperties = function (list) {
|
self.recursiveDeleteProperties = function (list) {
|
||||||
_.each(list, function (element, index, ll) {
|
_.each(list, function (element, index, ll) {
|
||||||
if (!element.parent || (element.parent.hasOwnProperty("layout") && element.parent.layout() != "horizontal_grid")) {
|
if (!element.parent || (element.parent.hasOwnProperty("layout") && element.parent.layout() != "horizontal_grid")) {
|
||||||
@ -618,4 +652,4 @@
|
|||||||
["loginStateViewModel", "settingsViewModel", "controlViewModel", "customControlDialogViewModel"],
|
["loginStateViewModel", "settingsViewModel", "controlViewModel", "customControlDialogViewModel"],
|
||||||
"#settings_plugin_customControl"
|
"#settings_plugin_customControl"
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
var inputs = self.element().input()
|
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 (inputs[i].hasOwnProperty("slider")) {
|
||||||
if (typeof inputs[i].slider == "object")
|
if (typeof inputs[i].slider == "object")
|
||||||
@ -59,6 +59,7 @@
|
|||||||
self.reset = function (data) {
|
self.reset = function (data) {
|
||||||
var element = {
|
var element = {
|
||||||
name: undefined,
|
name: undefined,
|
||||||
|
style: "",
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
commands: "",
|
commands: "",
|
||||||
confirm: "",
|
confirm: "",
|
||||||
@ -105,6 +106,7 @@
|
|||||||
}
|
}
|
||||||
case "command": {
|
case "command": {
|
||||||
el.name = obj.name;
|
el.name = obj.name;
|
||||||
|
el.style = "btn";
|
||||||
if (obj.commands.indexOf('\n') == -1)
|
if (obj.commands.indexOf('\n') == -1)
|
||||||
el.command = obj.commands;
|
el.command = obj.commands;
|
||||||
else
|
else
|
||||||
@ -165,6 +167,7 @@
|
|||||||
case "script":
|
case "script":
|
||||||
{
|
{
|
||||||
el.name = obj.name;
|
el.name = obj.name;
|
||||||
|
el.style = "btn";
|
||||||
el.script = obj.script;
|
el.script = obj.script;
|
||||||
|
|
||||||
if (self.useConfirm()) {
|
if (self.useConfirm()) {
|
||||||
@ -254,4 +257,4 @@
|
|||||||
[],
|
[],
|
||||||
"#customControlDialog"
|
"#customControlDialog"
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
@ -3,14 +3,14 @@
|
|||||||
<div style="min-height:15px; margin: 16px 16px; border:1px solid #00e500" id="base" data-bind="contextMenu: { menuSelector: '#controlContextMenu', menuSelected: $root.controlContextMenu }">
|
<div style="min-height:15px; margin: 16px 16px; border:1px solid #00e500" id="base" data-bind="contextMenu: { menuSelector: '#controlContextMenu', menuSelected: $root.controlContextMenu }">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- "width: 588px" to be the same as teh real Control tab-->
|
<!-- "width: 588px" to be the same as teh real Control tab-->
|
||||||
<div class="innerSortable" style="width: 588px; clear: both; display: none;" id="customControls" data-bind="visible: loginState.isUser, template: { name: $root.displayMode, foreach: controls }"></div>
|
<div class="innerSortable" style="width: 588px; clear: both; display: none;" id="customControls" data-bind="visible: loginState.isUser, template: { name: $root.displayMode, foreach: controls }"></div>
|
||||||
|
|
||||||
<ul id="controlContextMenu" class="dropdown-menu" role="menu" style="display:block;position:fixed !important;margin-bottom:5px;">
|
<ul id="controlContextMenu" class="dropdown-menu" role="menu" style="display:block;position:fixed !important;margin-bottom:5px;">
|
||||||
<li>
|
<li>
|
||||||
<a href="#" cmd="createContainer">{{ _('Create Container') }}</a>
|
<a href="#" cmd="createContainer">{{ _('Create Container') }}</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul id="commandContextMenu" class="dropdown-menu" role="menu" style="display:block;position:fixed !important;margin-bottom:5px;">
|
<ul id="commandContextMenu" class="dropdown-menu" role="menu" style="display:block;position:fixed !important;margin-bottom:5px;">
|
||||||
<li><a href="#" cmd="editElement">{{ _('Edit') }}</a></li>
|
<li><a href="#" cmd="editElement">{{ _('Edit') }}</a></li>
|
||||||
<li><a href="#" cmd="deleteElement">{{ _('Delete') }}</a></li>
|
<li><a href="#" cmd="deleteElement">{{ _('Delete') }}</a></li>
|
||||||
@ -19,13 +19,23 @@
|
|||||||
<a href="#">Style</a>
|
<a href="#">Style</a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li>
|
<li>
|
||||||
<a href="#" cmd="editStyle">Normal</a>
|
<a href="#" cmd="editStyleNormal">Normal</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="btn-primary">
|
<li class="btn-primary">
|
||||||
<a href="#" cmd="editStyle">Primary</a>
|
<a href="#" cmd="editStylePrimary">Primary</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="btn-danger">
|
<li class="btn-danger">
|
||||||
<a href="#" cmd="editStyle">Danger</a>
|
<a href="#" cmd="editStyleDanger">Danger</a>
|
||||||
|
</li>
|
||||||
|
<li class="btn-warning">
|
||||||
|
<a href="#" cmd="editStyleWarning">Warning</a>
|
||||||
|
</li>
|
||||||
|
<li class="btn-success">
|
||||||
|
<a href="#" cmd="editStyleSuccess">Success</a>
|
||||||
|
</li>
|
||||||
|
<li class="btn-info">
|
||||||
|
<a href="#" cmd="editStyleInfo">Info</a>
|
||||||
|
<li>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
@ -34,10 +44,10 @@
|
|||||||
<li class="dropdown-submenu">
|
<li class="dropdown-submenu">
|
||||||
<a href="#">Create Command</a>
|
<a href="#">Create Command</a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><a href="#" cmd="createContainer">{{ _('Container') }}</a></li>
|
<li><a href="#" cmd="createContainer">{{ _('Container') }}</a></li>
|
||||||
<li><a href="#" cmd="createCommand">{{ _('Command') }}</a></li>
|
<li><a href="#" cmd="createCommand">{{ _('Command') }}</a></li>
|
||||||
<li><a href="#" cmd="createScript">{{ _('Script Command') }}</a></li>
|
<li><a href="#" cmd="createScript">{{ _('Script Command') }}</a></li>
|
||||||
<li><a href="#" cmd="createOutput">{{ _('Output') }}</a></li>
|
<!--<li><a href="#" cmd="createOutput">{{ _('Output') }}</a></li>-->
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li class="divider"></li>
|
<li class="divider"></li>
|
||||||
@ -76,8 +86,10 @@
|
|||||||
</script>
|
</script>
|
||||||
<script type="text/html" id="settingsCustomControls_controlTemplate">
|
<script type="text/html" id="settingsCustomControls_controlTemplate">
|
||||||
<form class="form-inline custom_control" style="min-height:15px; border:1px dotted #000000" data-bind="contextMenu: { menuSelector: '#commandContextMenu', menuSelected: $root.controlContextMenu }, css: { 'sortable': $parent.layout() != 'horizontal_grid' }, attr: { 'id': id }">
|
<form class="form-inline custom_control" style="min-height:15px; border:1px dotted #000000" data-bind="contextMenu: { menuSelector: '#commandContextMenu', menuSelected: $root.controlContextMenu }, css: { 'sortable': $parent.layout() != 'horizontal_grid' }, attr: { 'id': id }">
|
||||||
|
<div data-bind="text: console.log($data)"></div>
|
||||||
<!-- ko template: { name: 'settingsCustomControls_controlTemplate_input', data: $data, if: $data.hasOwnProperty('input') } --><!-- /ko -->
|
<!-- ko template: { name: 'settingsCustomControls_controlTemplate_input', data: $data, if: $data.hasOwnProperty('input') } --><!-- /ko -->
|
||||||
<!-- ko template: { name: 'settingsCustomControls_controlTemplate_command', data: $data, if: $data.hasOwnProperty('command') || $data.hasOwnProperty('commands') || $data.hasOwnProperty('script') || $data.hasOwnProperty('javascript') } --><!-- /ko -->
|
<!-- ko template: { name: 'settingsCustomControls_controlTemplate_command', data: $data, if: !$data.hasOwnProperty('style') && ($data.hasOwnProperty('command') || $data.hasOwnProperty('commands') || $data.hasOwnProperty('script') || $data.hasOwnProperty('javascript')) } --><!-- /ko -->
|
||||||
|
<!-- ko template: { name: 'settingsCustomControls_controlTemplate_command_styled', data: $data, if: $data.hasOwnProperty('style') && ($data.hasOwnProperty('command') || $data.hasOwnProperty('commands') || $data.hasOwnProperty('script') || $data.hasOwnProperty('javascript')) } --><!-- /ko -->
|
||||||
<!-- ko template: { name: 'settingsCustomControls_controlTemplate_output', data: $data, if: $data.hasOwnProperty('value') } --><!-- /ko -->
|
<!-- ko template: { name: 'settingsCustomControls_controlTemplate_output', data: $data, if: $data.hasOwnProperty('value') } --><!-- /ko -->
|
||||||
</form>
|
</form>
|
||||||
</script>
|
</script>
|
||||||
@ -98,4 +110,7 @@
|
|||||||
<script type="text/html" id="settingsCustomControls_controlTemplate_command">
|
<script type="text/html" id="settingsCustomControls_controlTemplate_command">
|
||||||
<button class="btn" data-bind="text: name" onclick="event.preventDefault()"></button>
|
<button class="btn" data-bind="text: name" onclick="event.preventDefault()"></button>
|
||||||
</script>
|
</script>
|
||||||
<!-- End of templates for custom controls -->
|
<script type="text/html" id="settingsCustomControls_controlTemplate_command_styled">
|
||||||
|
<button data-bind="text: name, attr: { 'class': style }" onclick="event.preventDefault()"></button>
|
||||||
|
</script>
|
||||||
|
<!-- End of templates for custom controls -->
|
||||||
|
Reference in New Issue
Block a user