open-vault/ui/app/templates/partials/form-field-from-model.hbs

88 lines
2.5 KiB
Handlebars
Raw Normal View History

2018-04-03 14:16:57 +00:00
<div class="field">
2019-02-14 18:52:34 +00:00
{{#unless
(or
(contains
attr.options.editType
(array
"boolean"
"searchSelect"
"mountAccessor"
"kv"
"file"
"ttl"
"stringArray"
"json"
)
)
(eq attr.type "boolean")
)
}}
2018-04-03 14:16:57 +00:00
<label for="{{attr.name}}" class="is-label">
{{capitalize (or attr.options.label (humanize (dasherize attr.name)))}}
{{#if attr.options.helpText}}
2019-02-14 18:52:34 +00:00
{{#info-tooltip}}{{attr.options.helpText}}{{/info-tooltip}}
2018-04-03 14:16:57 +00:00
{{/if}}
</label>
{{/unless}}
{{#if attr.options.possibleValues}}
2019-02-14 18:52:34 +00:00
<div class="control is-expanded">
2018-04-03 14:16:57 +00:00
<div class="select is-fullwidth">
<select
name="{{attr.name}}"
id="{{attr.name}}"
onchange={{action (mut (get model attr.name)) value="target.value"}}
data-test-input={{attr.name}}
2019-02-14 18:52:34 +00:00
>
2018-04-03 14:16:57 +00:00
{{#each attr.options.possibleValues as |val|}}
<option selected={{eq (get model attr.name) val}} value={{val}}>
{{val}}
</option>
{{/each}}
</select>
</div>
</div>
2019-02-14 18:52:34 +00:00
{{else if (eq attr.options.editType "ttl")}}
{{ttl-picker
initialValue=(or (get model attr.name) attr.options.defaultValue)
labelText=(if
attr.options.label attr.options.label (humanize (dasherize attr.name))
)
setDefaultValue=false
onChange=(action (mut (get model attr.name)))
}}
{{else if (or (eq attr.type "number") (eq attr.type "string"))}}
2018-04-03 14:16:57 +00:00
<div class="control">
2019-02-14 18:52:34 +00:00
{{input
id=attr.name
value=(get model (or attr.options.fieldValue attr.name))
class="input"
data-test-input=attr.name
}}
2018-04-03 14:16:57 +00:00
</div>
2019-02-14 18:52:34 +00:00
{{else if (eq attr.type "boolean")}}
2018-04-03 14:16:57 +00:00
<div class="b-checkbox">
2019-02-14 18:52:34 +00:00
<input
type="checkbox"
id="{{attr.name}}"
class="styled"
checked={{get model attr.name}}
onchange={{action (mut (get model attr.name)) value="target.checked"}}
data-test-input={{attr.name}}
/>
<label for="{{attr.name}}" class="is-label">
{{capitalize (or attr.options.label (humanize (dasherize attr.name)))}}
{{#if attr.options.helpText}}
{{#info-tooltip}}{{attr.options.helpText}}{{/info-tooltip}}
{{/if}}
</label>
</div>
{{else if (eq attr.type "object")}}
{{json-editor
value=(if
(get model attr.name) (stringify (get model attr.name)) emptyData
)
valueUpdated=(action "codemirrorUpdated" attr.name)
}}
{{/if}}
</div>