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
<script type="text/javascript">
    RED.nodes.registerType('ui_text',{
        category: RED._("node-red-dashboard/ui_base:ui_base.label.category"),
        color: 'rgb(119, 198, 204)',
        defaults: {
            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},
            name: {value: ''},
            label: {value: 'text'},
            format: {value: '{{msg.payload}}'},
            layout: {value:'row-spread'},
            className: {value: ''}
        },
        inputs:1,
        outputs:0,
        align: "right",
        icon: "ui_text.png",
        paletteLabel: 'text',
        label: function() { return this.name || (~this.label.indexOf("{{") ? null : this.label) || 'text'; },
        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"
            });
 
            $(".nr-db-text-layout-"+(this.layout||'row-spread')).addClass('selected');
 
            [ ".nr-db-text-layout-row-left",".nr-db-text-layout-row-center",".nr-db-text-layout-row-right",
              ".nr-db-text-layout-row-spread",".nr-db-text-layout-col-center"].forEach(function(id) {
                    $(id).click(function(e) {
                        $(".nr-db-text-layout").removeClass('selected');
                        $(this).addClass('selected');
                        $('#node-input-layout').val(id.substring(".nr-db-text-layout-".length));
                        e.preventDefault();
                    })
                })
        }
    });
</script>
 
<script type="text/html" data-template-name="ui_text">
    <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-format"><i class="fa fa-i-cursor"></i> Value format</label>
        <input type="text" id="node-input-format" placeholder="{{msg.payload}}">
    </div>
    <div class="form-row">
        <label style="vertical-align: top"><i class="fa fa-th-large"></i> Layout</label>
        <div style="display:inline-block">
        <input type="hidden" id="node-input-layout"><input type="hidden" id="node-input-layoutAlign">
        <div>
            <a href="#" class="nr-db-text-layout nr-db-text-layout-row nr-db-text-layout-row-left">
                <span class="nr-db-text-layout-label">label</span>
                <span class="nr-db-text-layout-value">value</span>
                <div class="nr-db-text-layout-checkbox"></div>
            </a>
            <a href="#" class="nr-db-text-layout nr-db-text-layout-row nr-db-text-layout-row-center">
                <span class="nr-db-text-layout-label">label</span>
                <span class="nr-db-text-layout-value">value</span>
                <div class="nr-db-text-layout-checkbox"></div>
            </a>
            <a href="#" class="nr-db-text-layout nr-db-text-layout-row nr-db-text-layout-row-right">
                <span class="nr-db-text-layout-label">label</span>
                <span class="nr-db-text-layout-value">value</span>
                <div class="nr-db-text-layout-checkbox"></div>
            </a>
        </div>
        <div>
            <a href="#" class="nr-db-text-layout nr-db-text-layout-row nr-db-text-layout-row-spread">
                <span class="nr-db-text-layout-label">label</span>
                <span class="nr-db-text-layout-value">value</span>
                <div class="nr-db-text-layout-checkbox"></div>
            </a>
            <a href="#" class="nr-db-text-layout nr-db-text-layout-col nr-db-text-layout-col-center">
                <span class="nr-db-text-layout-label">label</span>
                <span class="nr-db-text-layout-value">value</span>
                <div class="nr-db-text-layout-checkbox"></div>
            </a>
        </div>
        </div>
    </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>
<style>
    .nr-db-text-layout {
        position:relative;
        display: inline-block;
        width: 90px;
        height: 60px;
        border-radius:3px;
        border:1px solid var(--red-ui-form-input-border-color, #bbb);
        cursor:pointer;
        color: #666;
        margin-right: 10px;
        margin-bottom: 10px;
    }
    .nr-db-text-layout.selected, .nr-db-text-layout:hover {
        border-color: var(--red-ui-form-input-border-selected-color, #333);
        color: var(--red-ui-secondary-text-color-selected, #333);
    }
    .nr-db-text-layout span {
        position: absolute;
    }
    .nr-db-text-layout-value {
        font-weight: bold;
    }
    .nr-db-text-layout-row span { top: 20px; }
    .nr-db-text-layout-row-left .nr-db-text-layout-label { left: 2px; }
    .nr-db-text-layout-row-left .nr-db-text-layout-value { left: 34px; }
    .nr-db-text-layout-row-spread .nr-db-text-layout-label { left: 2px; }
    .nr-db-text-layout-row-spread .nr-db-text-layout-value { right: 2px; }
    .nr-db-text-layout-row-center .nr-db-text-layout-label { left: 11px; }
    .nr-db-text-layout-row-center .nr-db-text-layout-value { right: 11px; }
    .nr-db-text-layout-row-right .nr-db-text-layout-label { right: 40px; }
    .nr-db-text-layout-row-right .nr-db-text-layout-value { right: 2px; }
 
    .nr-db-text-layout-col span { width: 90px;  text-align: center; left: 0px;}
    .nr-db-text-layout-col-center .nr-db-text-layout-label { top: 12px; }
    .nr-db-text-layout-col-center .nr-db-text-layout-value { top: 26px; }
    .nr-db-text-layout-checkbox {
        display: none;
        width: 10px;
        height: 10px;
        border-radius: 10px;
        border: 1px solid var(--red-ui-primary-border-color, #bbb);
        position: absolute;
        right: -5px;
        top: -5px;
        background: var(--red-ui-secondary-background, #fff);
    }
    .nr-db-text-layout.selected .nr-db-text-layout-checkbox {
        display:inline-block;
        box-shadow: inset 0px 0px 0px 2px #fff;
        background: #333;
        border-color: #333;
    }
 
</style>