liudong
2023-05-29 340f156319b863525e50e900c58e59b86ecb3d5e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<script type="text/javascript">
    RED.nodes.registerType('ui_switch',{
        category: RED._("node-red-dashboard/ui_base:ui_base.label.category"),
        color: 'rgb(176, 223, 227)',
        defaults: {
            name: {value: ''},
            label: {value: 'switch'},
            tooltip: {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},
            passthru: {value: true},
            decouple: {value: "false"},
            topic: {value: 'topic', validate: (RED.validators.hasOwnProperty('typedInput')?RED.validators.typedInput('topicType'):function(v) { return true})},
            topicType: {value: 'msg'},
            style: {value: ''},
            onvalue: {value: true, required:true, validate: (RED.validators.hasOwnProperty('typedInput')?RED.validators.typedInput('onvalueType'):function(v) { return true})},
            onvalueType: {value: 'bool'},
            onicon: {value: '' },
            oncolor: {value: ''},
            offvalue: {value: false, required:true, validate: (RED.validators.hasOwnProperty('typedInput')?RED.validators.typedInput('offvalueType'):function(v) { return true})},
            offvalueType: {value: 'bool'},
            officon: {value: ''},
            offcolor: {value: ''},
            animate: {value: false},
            className: {value: ''}
        },
        inputs:1,
        outputs:1,
        icon: "ui_switch.png",
        paletteLabel: 'switch',
        label: function() { return this.name || (~this.label.indexOf("{{") ? null : this.label) || 'switch'; },
        labelStyle: function() { return this.name?"node_label_italic":""; },
        oneditprepare: function() {
            $("#node-input-size").elementSizer({
                width: "#node-input-width",
                height: "#node-input-height",
                group: "#node-input-group"
            });
            $('#node-input-custom-icons').on("change", function() {
                if ($('#node-input-custom-icons').val() === "default") {
                    $(".form-row-custom-icons").hide();
                }
                else {
                    $(".form-row-custom-icons").show();
                }
            });
 
            if (this.onicon !== "" || this.oncolor !== "" || this.officon !=="" || this.offcolor !== "") {
                $('#node-input-custom-icons').val('custom');
            }
            else {
                $(".form-row-custom-icons").hide();
                $('#node-input-custom-icons').change();
            }
 
            $('#node-input-onvalue').typedInput({
                default: 'str',
                typeField: $("#node-input-onvalueType"),
                types: ['str','num','bool','json','bin','date','flow','global']
            });
 
            $('#node-input-offvalue').typedInput({
                default: 'str',
                typeField: $("#node-input-offvalueType"),
                types: ['str','num','bool','json','bin','date','flow','global']
            });
 
            $('#node-input-topic').typedInput({
                default: 'str',
                typeField: $("#node-input-topicType"),
                types: ['str','msg','flow','global']
            });
 
            $('#node-input-passthru').on("change", function() {
                if (this.checked) {
                    $('.form-row-decouple').hide();
                    $('#node-input-decouple').val("false");
                }
                else {
                    $('.form-row-decouple').show();
                }
            });
        },
        oneditsave: function() {
            if ($('#node-input-custom-icons').val() === 'default') {
                $('#node-input-onicon').val('');
                $('#node-input-officon').val('');
                $('#node-input-oncolor').val('');
                $('#node-input-offcolor').val('');
            }
        }
    });
</script>
 
<script type="text/html" data-template-name="ui_switch">
    <div class="form-row">
        <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-label"><i class="fa fa-i-cursor"></i> Label</label>
        <input type="text" id="node-input-label">
    </div>
    <div class="form-row">
        <label for="node-input-tooltip"><i class="fa fa-info-circle"></i> Tooltip</label>
        <input type="text" id="node-input-tooltip" placeholder="optional tooltip">
    </div>
    <div class="form-row">
        <label for="node-input-custom-icons"><i class="fa fa-picture-o"></i> Icon</label>
        <select id="node-input-custom-icons" style="width:35%">
            <option value="default">Default</option>
            <option value="custom">Custom</option>
        </select>
        <span style="width:auto; padding-left:20px" class="form-row-custom-icons" for="node-input-animate"> Animate
        <input type="checkbox" checked id="node-input-animate" style="display:inline-block; width:auto; vertical-align:baseline;"></span>
    </div>
    <div class="form-row form-row-custom-icons">
        <label for="node-input-onicon" style="text-align:right;"><i class="fa fa-toggle-on"></i> On Icon</label>
        <input type="text" id="node-input-onicon" style="width:120px">
        <label for="node-input-oncolor" style="width:50px; text-align:right;">Colour</label>
        <input type="text" id="node-input-oncolor" style="width:120px">
    </div>
    <div class="form-row form-row-custom-icons">
        <label for="node-input-officon" style="text-align:right;"><i class="fa fa-toggle-off"></i> Off Icon</label>
        <input type="text" id="node-input-officon" style="width:120px">
        <label for="node-input-offcolor" style="width:50px; text-align:right;">Colour</label>
        <input type="text" id="node-input-offcolor" style="width:120px">
    </div>
    <div class="form-row">
        <label style="width:auto" for="node-input-passthru"><i class="fa fa-arrow-right"></i> Pass through <code>msg</code> if payload matches valid state: </label>
        <input type="checkbox" checked id="node-input-passthru" style="display:inline-block; width:auto; vertical-align:top;">
    </div>
    <div class="form-row form-row-decouple">
        <label for="node-input-decouple"><i class="fa fa-toggle-on"></i> Indicator</label>
        <select id="node-input-decouple" style="display: inline-block; vertical-align: middle; width:70%;">
            <option value="false">Switch icon shows state of the output</option>
            <option value="true">Switch icon shows state of the input</option>
        </select>
    </div>
    <div class="form-row">
        <label style="width:auto" for="node-input-onvalue"><i class="fa fa-envelope-o"></i> When clicked, send:</label>
    </div>
    <div class="form-row">
        <label for="node-input-onvalue" style="padding-left:25px; margin-right:-25px">On Payload</label>
        <input type="text" id="node-input-onvalue" style="width:70%">
        <input type="hidden" id="node-input-onvalueType">
    </div>
    <div class="form-row">
        <label for="node-input-offvalue" style="padding-left:25px; margin-right:-25px">Off Payload</label>
        <input type="text" id="node-input-offvalue" style="width:70%">
        <input type="hidden" id="node-input-offvalueType">
    </div>
    <div class="form-row">
        <label for="node-input-topic" style="padding-left:25px; margin-right:-25px">Topic</label>
        <input type="text" id="node-input-topic">
        <input type="hidden" id="node-input-topicType">
    </div>
    <div class="form-row">
        <label for="node-input-className"><i class="fa fa-code"></i>  Class</label>
        <input type="text" id="node-input-className" placeholder="Optional CSS class name(s) for widget"/>
    </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">
    </div>
</script>