11< script type ="text/javascript ">
2- RED . nodes . registerType ( "node-red-contrib-httpauthmultiple" , {
3- category : "config" ,
4- defaults : {
5- name : { value : "" } ,
6- authType : { value : "Basic" , required : true } ,
7- realm : { value : "" , required : true } ,
8- hashed : { value : false , required : true } ,
9- auths : { value : { } }
10- } ,
11- color : "#E7E7AE" ,
12- icon : "white-globe.png" ,
13- label : function ( ) { return ( this . name || "http auth multiple" ) ; } ,
14- oneditprepare : function ( ) {
15- function resizeRule ( rule ) {
16- var newWidth = rule . width ( ) ;
17- rule . find ( '.red-ui-typedInput' ) . typedInput ( "width" , ( newWidth - 15 ) / 2 ) ;
2+ /* global RED:false, $:false */
3+ RED . nodes . registerType ( 'http-basic-auth-multiple' , {
4+ category : 'config' ,
5+ defaults : {
6+ name : { value : '' } ,
7+ realm : { value : '' , required : true } ,
8+ auths : { value : { } } ,
9+ } ,
10+ color : '#E7E7AE' ,
11+ icon : 'white-globe.png' ,
12+ label : function ( ) { return ( this . name || 'http auth multiple' ) ; } ,
13+ oneditprepare : function ( ) {
14+ function resizeRule ( rule ) {
15+ const newWidth = rule . width ( ) ;
16+ rule . find ( '.red-ui-typedInput' ) . typedInput ( 'width' , ( newWidth - 15 ) / 2 ) ;
17+ }
18+ const authList = $ ( '#node-input-auths-container' ) . css ( 'min-height' , '150px' ) . css ( 'min-width' , '450px' )
19+ . editableList ( {
20+ addItem : function ( container , i , auth ) {
21+ const row = $ ( '<div/>' ) . appendTo ( container ) ;
1822
19- }
20- var authList = $ ( "#node-input-auths-container" ) . css ( 'min-height' , '150px' ) . css ( 'min-width' , '450px' )
21- . editableList ( {
22- addItem : function ( container , i , auth ) {
23- var row = $ ( '<div/>' ) . appendTo ( container ) ;
23+ const propertyUser = $ ( '<input/>' ,
24+ { class : 'node-input-auth-user' , type : 'text' , style : 'width: 30%;' , placeholder : 'user' } ) . appendTo ( row ) ;
2425
25- var propertyUser = $ ( '<input/>' , { class : "node-input-auth-user" , type : "text" , style : "width: 30%;" , placeholder : "user" } )
26- . appendTo ( row ) ;
26+ const propertyRealm = $ ( '<input/>' ,
27+ { class : 'node-input-auth-realm' , type : 'text' , style : 'margin-left: 3%; width: 30%;' , placeholder : 'realm' } ) . appendTo ( row ) ;
2728
28- var propertyRealm = $ ( '<input/>' , { class : "node-input-auth-realm" , type : "text" , style : "margin-left: 3%; width: 30%;" , placeholder : "realm" } )
29- . appendTo ( row ) ;
29+ const propertyPassword = $ ( '<input/>' ,
30+ { class : 'node-input-auth-password' , type : 'text' , style : 'margin-left: 3%; width: 30%;' , placeholder : 'password' } ) . appendTo ( row ) ;
3031
31- var propertyPassword = $ ( '<input/>' , { class : "node-input-auth-password" , type : "text" , style : "margin-left: 3%; width: 30%;" , placeholder : "password" } )
32- . appendTo ( row ) ;
32+ propertyUser . val ( auth . user ) ;
33+ propertyRealm . val ( auth . realm ) ;
34+ propertyPassword . val ( auth . password ) ;
3335
34- propertyUser . val ( auth . user ) ;
35- propertyRealm . val ( auth . realm ) ;
36- propertyPassword . val ( auth . password ) ;
36+ resizeRule ( container ) ;
37+ } ,
38+ resizeItem : resizeRule ,
39+ removable : true ,
40+ } ) ;
3741
38- resizeRule ( container ) ;
39- } ,
40- resizeItem : resizeRule ,
41- removable : true
42- } ) ;
42+ if ( this . auths ) {
43+ for ( const key in this . auths ) {
44+ if ( ( this . auths [ key ] ) . length ) {
45+ this . auths [ key ] . forEach ( function ( value , index ) {
46+ authList . editableList ( 'addItem' , { realm : key , user : value . user , password : value . password } ) ;
47+ } ) ;
48+ }
49+ }
50+ }
51+ } ,
52+ oneditsave : function ( ) {
53+ const auths = $ ( '#node-input-auths-container' ) . editableList ( 'items' ) ;
54+ const node = this ;
55+ node . auths = { } ;
56+ auths . each ( function ( i ) {
57+ const auth = $ ( this ) ;
58+ const user = auth . find ( '.node-input-auth-user' ) . val ( ) ;
59+ const realm = auth . find ( '.node-input-auth-realm' ) . val ( ) ;
60+ const password = auth . find ( '.node-input-auth-password' ) . val ( ) ;
4361
44- if ( this . auths ) {
45- for ( var key in this . auths ) {
46- if ( ( this . auths [ key ] ) . length ) {
47- this . auths [ key ] . forEach ( function ( value , index ) {
48- authList . editableList ( 'addItem' , { realm : key , user : value . user , password : value . password } ) ;
49- } )
50- }
51- }
52- }
53- } ,
54- oneditsave : function ( ) {
55- var auths = $ ( "#node-input-auths-container" ) . editableList ( 'items' ) ;
56- var node = this ;
57- node . auths = { } ;
58- auths . each ( function ( i ) {
59- var auth = $ ( this ) ;
60- var user = auth . find ( ".node-input-auth-user" ) . val ( ) ;
61- var realm = auth . find ( ".node-input-auth-realm" ) . val ( ) ;
62- var password = auth . find ( ".node-input-auth-password" ) . val ( ) ;
62+ if ( ! node . auths [ realm ] ) {
63+ node . auths [ realm ] = [ ] ;
64+ }
6365
64- if ( ! node . auths [ realm ] ) {
65- node . auths [ realm ] = [ ] ;
66- }
67-
68- if ( realm && user && password ) {
69- node . auths [ realm ] . push ( {
70- "user" : user ,
71- "password" : password
72- } ) ;
73- }
74- } ) ;
75-
76- } ,
77- paletteLabel : "http auth"
78- } ) ;
66+ if ( realm && user && password ) {
67+ node . auths [ realm ] . push ( {
68+ user,
69+ password,
70+ } ) ;
71+ }
72+ } ) ;
73+ } ,
74+ paletteLabel : 'http auth' ,
75+ } ) ;
7976</ script >
80- < script type ="text/x-red " data-template-name ="node-red-contrib-httpauthmultiple ">
77+ < script type ="text/x-red " data-template-name ="http-basic-auth-multiple ">
78+ < div class = "form-row" >
79+ < label for = "node-config-input-name" > < i class = "fa fa-tag" > </ i > Name</ label >
80+ < input type = "texth" id = "node-config-input-name" >
81+ </ div >
82+ < div class = "form-row" >
83+ < label for = "node-input-authType" > < i class = "fa fa-list" > </ i > Auth Type</ label >
84+ < select id = "node-input-authType" >
85+ < option value = "Basic" > Basic</ option >
86+ < option value = "Digest" > Digest</ option >
87+ </ select >
88+ </ div >
8189 < div class = "form-row" >
82- < label for = "node-config-input-name" > < i class = "fa fa-tag" > </ i > Name</ label >
83- < input type = "texth" id = "node-config-input-name" >
84- </ div >
85- < div class = "form-row" >
86- < label for = "node-input-authType" > < i class = "fa fa-list" > </ i > Auth Type</ label >
87- < select id = "node-input-authType" >
88- < option value = "Basic" > Basic</ option >
89- < option value = "Digest" > Digest</ option >
90- </ select >
91- </ div >
92- < div class = "form-row" >
93- < label for = "node-config-input-realm" > < i class = "fa fa-globe" > </ i > Realm</ label >
94- < input type = "text" id = "node-config-input-realm" >
95- </ div >
96- < div class = "form-row" >
97- < label for = "node-config-input-hashed" > < i class = "fa fa-asterisk" > </ i > Hashed</ label >
98- < input type = "checkbox" id = "node-config-input-hashed" >
99- </ div >
100- < div class = "form-row" >
101- < label > < i class = "fa fa-list" > </ i > Auths</ span >
102- </ label >
103- </ div >
104- < div class = "form-row node-input-auths-container-row" >
105- < ol id = "node-input-auths-container" > </ ol >
106- </ div >
107- </ script >
90+ < label for = "node-config-input-realm" > < i class = "fa fa-globe" > </ i > Realm</ label >
91+ < input type = "text" id = "node-config-input-realm" >
92+ </ div >
93+ < div class = "form-row" >
94+ < label for = "node-config-input-hashed" > < i class = "fa fa-asterisk" > </ i > Hashed</ label >
95+ < input type = "checkbox" id = "node-config-input-hashed" >
96+ </ div >
97+ < div class = "form-row" >
98+ < label > < i class = "fa fa-list" > </ i > Auths</ span >
99+ </ label >
100+ </ div >
101+ < div class = "form-row node-input-auths-container-row" >
102+ < ol id = "node-input-auths-container" > </ ol >
103+ </ div >
104+ </ script >
0 commit comments