/
form-field.hbs
316 lines (314 loc) · 10.4 KB
/
form-field.hbs
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
{{#unless
(or
(eq attr.type "boolean")
(contains
attr.options.editType
(array
"boolean"
"optionalText"
"searchSelect"
"mountAccessor"
"kv"
"file"
"ttl"
"stringArray"
"json"
"regex"
)
)
)
}}
{{#unless (eq attr.type "object")}}
<label for="{{attr.name}}" class="is-label">
{{labelString}}
{{#if attr.options.helpText}}
{{#info-tooltip}}
<span data-test-help-text>
{{attr.options.helpText}}
</span>
{{/info-tooltip}}
{{/if}}
</label>
{{#if attr.options.subText}}
<p class="sub-text">{{attr.options.subText}} {{#if attr.options.docLink}}<a href="{{attr.options.docLink}}" target="_blank" rel="noopener noreferrer">See our documentation</a> for help.{{/if}}</p>
{{/if}}
{{/unless}}
{{/unless}}
{{#if attr.options.possibleValues}}
<div class="control is-expanded">
<div class="select is-fullwidth">
<select name="{{attr.name}}" id="{{attr.name}}" onchange={{action
(action "setAndBroadcast" valuePath)
value="target.value"
}} data-test-input={{attr.name}}>
{{#if attr.options.noDefault}}
<option value="">
Select one
</option>
{{/if}}
{{#each (path-or-array attr.options.possibleValues model) as |val|}}
<option selected={{eq (get model valuePath) (or val.value val)}} value={{or val.value val}}>
{{or val.displayName val}}
</option>
{{/each}}
</select>
</div>
</div>
{{else if (and (eq attr.type "string") (eq attr.options.editType "boolean"))}}
<div class="b-checkbox">
<input type="checkbox" id="{{attr.name}}" class="styled" checked={{eq (get model valuePath) attr.options.trueValue}}
onchange={{action
(action
"setAndBroadcastBool"
valuePath
attr.options.trueValue
attr.options.falseValue
)
value="target.checked"
}} data-test-input={{attr.name}} />
<label for="{{attr.name}}" class="is-label">
{{labelString}}
{{#if attr.options.helpText}}
{{#info-tooltip}}{{attr.options.helpText}}{{/info-tooltip}}
{{/if}}
</label>
</div>
{{else if (eq attr.options.editType "searchSelect")}}
<div class="form-section">
<SearchSelect
@id={{attr.name}}
@models={{attr.options.models}}
@onChange={{action (action "setAndBroadcast" valuePath)}}
@inputValue={{get model valuePath}}
@helpText={{attr.options.helpText}}
@subText={{attr.options.subText}}
@wildcardLabel={{attr.options.wildcardLabel}}
@label={{labelString}}
@subLabel={{attr.options.subLabel}}
@fallbackComponent={{attr.options.fallbackComponent}}
@selectLimit={{attr.options.selectLimit}}
@backend={{model.backend}}
@disallowNewItems={{attr.options.onlyAllowExisting}}
/>
</div>
{{else if (eq attr.options.editType "mountAccessor")}}
{{mount-accessor-select
name=attr.name
label=labelString
warning=attr.options.warning
helpText=attr.options.helpText
value=(get model valuePath)
onChange=(action "setAndBroadcast" valuePath)
}}
{{else if (eq attr.options.editType "kv")}}
{{!-- KV Object Editor --}}
{{kv-object-editor
value=(get model valuePath)
onChange=(action "setAndBroadcast" valuePath)
label=labelString
warning=attr.options.warning
helpText=attr.options.helpText
}}
{{else if (eq attr.options.editType "file")}}
{{!-- File Input --}}
{{text-file
helpText=attr.options.helpText
file=file
onChange=(action "setFile")
label=labelString
}}
{{else if (eq attr.options.editType "ttl")}}
{{!-- TTL Picker --}}
<div class="field">
<TtlPicker2
@onChange={{action (action "setAndBroadcastTtl" valuePath)}}
@label={{labelString}}
@helperTextDisabled={{or attr.options.helperTextDisabled "Vault will use the default lease duration."}}
@helperTextEnabled={{or attr.options.helperTextEnabled "Lease will expire after"}}
@description={{attr.helpText}}
@initialValue={{or (get model valuePath) attr.options.setDefault}}
/>
</div>
{{else if (eq attr.options.editType "regex")}}
{{!-- Regex Validated Input --}}
<RegexValidator
@attr={{attr}}
@labelString={{labelString}}
@value={{or (get model valuePath)
attr.options.defaultValue}}
@onChange={{action
(action "setAndBroadcast" valuePath)
value="target.value"
}}
/>
{{else if (eq attr.options.editType "optionalText")}}
{{!-- Togglable Text Input --}}
<Toggle
@name="show-{{attr.name}}"
@status="success"
@size="small"
@onChange={{action 'toggleShow' attr.name}}
@checked={{showInput}}
data-test-toggle={{attr.name}}
>
<span class="ttl-picker-label is-large">{{labelString}}</span><br/>
<div class="description has-text-grey">
{{#if showInput}}
<span>{{attr.options.subText}} {{#if attr.options.docLink}}<a href="{{attr.options.docLink}}" target="_blank" rel="noopener noreferrer">See our documentation</a> for help.{{/if}}</span>
{{else}}
<span>{{or attr.options.defaultSubText "Vault will use the engine default."}} {{#if attr.options.docLink}}<a href="{{attr.options.docLink}}" target="_blank" rel="noopener noreferrer">See our documentation</a> for help.{{/if}}</span>
{{/if}}
</div>
{{#if showInput}}
<input
data-test-input={{attr.name}}
id={{attr.name}}
autocomplete="off"
spellcheck="false"
value={{or (get model valuePath)
attr.options.defaultValue}}
onChange={{action
(action "setAndBroadcast" valuePath)
value="target.value"
}}
class="input"
maxLength={{attr.options.characterLimit}} />
{{/if}}
</Toggle>
{{else if (eq attr.options.editType "stringArray")}}
{{string-list
data-test-input=attr.name
label=labelString
warning=attr.options.warning
helpText=attr.options.helpText
inputValue=(get model valuePath)
onChange=(action (action "setAndBroadcast" valuePath))
}}
{{else if (eq attr.options.sensitive true)}}
{{!-- Masked Input --}}
<MaskedInput
@value={{or (get model valuePath) attr.options.defaultValue}}
@allowCopy="true"
@onChange={{action (action "setAndBroadcast" valuePath)}}
@name={{attr.name}}
@onKeyUp={{@onKeyUp}}
/>
{{#if (get validationMessages attr.name)}}
<AlertInline
@type="danger"
@message={{get validationMessages attr.name}}
@paddingTop=true
/>
{{/if}}
{{else if (or (eq attr.type "number") (eq attr.type "string"))}}
<div class="control">
{{#if (eq attr.options.editType "textarea")}}
{{!-- Text area --}}
<textarea data-test-input={{attr.name}} id={{attr.name}}
value={{or (get model valuePath) attr.options.defaultValue}} oninput={{action
(action "setAndBroadcast" valuePath)
value="target.value"
}} class="textarea"></textarea>
{{else if (eq attr.options.editType "password")}}
<Input
data-test-input={{attr.name}}
@type="password"
@value={{get model valuePath}}
@name={{attr.name}}
class="input"
{{!-- Prevents browsers from auto-filling --}}
@autocomplete="new-password"
@spellcheck="false" />
{{else if (eq attr.options.editType "json")}}
{{!-- JSON Editor --}}
<JsonEditor
data-test-input={{attr.name}}
@title={{labelString}}
@value={{if
(get model valuePath)
(stringify (jsonify (get model valuePath)))
attr.options.defaultValue
}}
@valueUpdated={{action "codemirrorUpdated" attr.name "string"}}
@options={{hash
theme=(or attr.options.theme 'hashi')
}}
@helpText={{attr.options.helpText}}
>
{{#if attr.options.allowReset}}
<button
type="button"
class="toolbar-link"
disabled={{not (get model valuePath)}}
onClick={{action
(action "setAndBroadcast" valuePath)
null
}}
data-test-json-clear-button
>
Clear
<Icon @glyph="refresh-default" aria-hidden="true" />
</button>
{{/if}}
</JsonEditor>
{{#if attr.options.subText}}
<p class="sub-text">{{attr.options.subText}} {{#if attr.options.docLink}}<a href="{{attr.options.docLink}}" target="_blank" rel="noopener noreferrer">See our documentation</a> for help.{{/if}}</p>
{{/if}}
{{else}}
{{!-- Regular Text Input --}}
<input
data-test-input={{attr.name}}
id={{attr.name}}
readonly={{isReadOnly}}
autocomplete="off"
spellcheck="false"
value={{or (get model valuePath) attr.options.defaultValue}}
onChange={{action
(action "setAndBroadcast" valuePath)
value="target.value"
}}
onkeyup={{action
(action "handleKeyUp" attr.name)
value="target.value"
}}
class="input {{if (get validationMessages attr.name) "has-error-border"}}"
maxLength={{attr.options.characterLimit}} />
{{#if attr.options.validationAttr}}
{{#if
(and
(get model valuePath) (not (get model attr.options.validationAttr))
)
}}
<AlertInline @type="danger" @message={{attr.options.invalidMessage}} />
{{/if}}
{{/if}}
{{#if (get validationMessages attr.name)}}
<AlertInline
@type="danger"
@message={{get validationMessages attr.name}}
@paddingTop=true
/>
{{/if}}
{{/if}}
</div>
{{else if (eq attr.type "boolean")}}
<div class="b-checkbox">
<input disabled={{this.disabled}} type="checkbox" id="{{attr.name}}" class="styled" checked={{get model attr.name}} onchange={{action
(action "setAndBroadcast" valuePath)
value="target.checked"
}} data-test-input={{attr.name}} />
<label for="{{attr.name}}" class="is-label">
{{labelString}}
{{#if (and this.showHelpText attr.options.helpText)}}
{{#info-tooltip}}{{attr.options.helpText}}{{/info-tooltip}}
{{/if}}
</label>
</div>
{{else if (eq attr.type "object")}}
{{json-editor
title=labelString
value=(if (get model valuePath) (stringify (get model valuePath)) emptyData)
valueUpdated=(action "codemirrorUpdated" attr.name false)
helpText=attr.options.helpText
}}
{{/if}}