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