Add button group ui node

This commit is contained in:
2023-08-25 07:56:24 +02:00
commit 43347936b3
3 changed files with 156 additions and 0 deletions
+82
View File
@@ -0,0 +1,82 @@
<script type="text/javascript">
RED.nodes.registerType('ui_button_group', {
category: 'dashboard',
color: 'rgb(63, 173, 181)',
defaults: {
name: { value: '' },
group: { type: 'ui_group', required: true },
order: { value: 0 },
width: {
value: 0, validate: function (v) {
var width = v || 0;
var currentGroup = $('#node-input-group').val() || this.group;
var groupNode = RED.nodes.node(currentGroup);
var valid = !groupNode || +width <= +groupNode.width;
$("#node-input-size").toggleClass("input-error", !valid);
return valid;
}
},
height: { value: 0 },
buttonwidth: {
value: 0, validate: function (v) {
var btnWidth = Number(v || 0);
var valid = btnWidth <= Number(this.width) && btnWidth > 0;
console.log(`valid: ${valid}; btnWidth: ${btnWidth}; this.width: ${this.width}; v: ${v}`);
$("#node-input-buttonwidth").toggleClass("input-error", !valid);
return valid;
}
},
buttonheight: {
value: 0, validate: function (v) {
var btnHeight = Number(v || 0);
var valid = btnHeight <= Number(this.height) && btnHeight > 0;
$("#node-input-buttonheight").toggleClass("input-error", !valid);
return valid;
},
},
},
inputs: 1,
outputs: 1,
icon: 'font-awesome/fa-th-large',
paletteLabel: 'button group',
label: function () {
return this.name || 'Buttons';
},
oneditprepare: function () {
$("#node-input-size").elementSizer({
width: "#node-input-width",
height: "#node-input-height",
group: "#node-input-group"
});
}
});
</script>
<script type="text/html" data-template-name="ui_button_group">
<div class='form-row' id='template-row-group'>
<label for='node-input-group'><i class='fa fa-table'></i> Group</label>
<input type='text' id='node-input-group'>
</div>
<div class="form-row">
<label><i class="fa fa-object-group"></i> Size</label>
<input type="hidden" id="node-input-width">
<input type="hidden" id="node-input-height">
<button class="editor-button" id="node-input-size"></button>
</div>
<div class="form-row">
<label for="node-input-buttonwidth"><i class="fa fa-tag"></i> Button Width</label>
<input type="number" id="node-input-buttonwidth" placeholder="1">
</div>
<div class="form-row">
<label for="node-input-buttonheight"><i class="fa fa-tag"></i> Button Height</label>
<input type="number" id="node-input-buttonheight" placeholder="1">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/html" data-help-name="ui_button_group">
<p>A simple button group node</p>
</script>