]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-forms/input-text.component.ts
Add ability for client to create server logs
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-forms / input-text.component.ts
CommitLineData
f8b530e0
RK
1import { Component, forwardRef, Input } from '@angular/core'
2import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
3import { Notifier } from '@app/core'
dc1296a9 4
f8b530e0 5@Component({
a70bf3bd
C
6 selector: 'my-input-text',
7 templateUrl: './input-text.component.html',
8 styleUrls: [ './input-text.component.scss' ],
f8b530e0
RK
9 providers: [
10 {
11 provide: NG_VALUE_ACCESSOR,
a70bf3bd 12 useExisting: forwardRef(() => InputTextComponent),
f8b530e0
RK
13 multi: true
14 }
15 ]
16})
a70bf3bd 17export class InputTextComponent implements ControlValueAccessor {
1916c966 18 @Input() inputId = Math.random().toString(11).slice(2, 8) // id cannot be left empty or undefined
f8b530e0
RK
19 @Input() value = ''
20 @Input() autocomplete = 'off'
21 @Input() placeholder = ''
23cd3129 22 @Input() tabindex = 0
f8b530e0
RK
23 @Input() withToggle = true
24 @Input() withCopy = false
25 @Input() readonly = false
26 @Input() show = false
75084782 27 @Input() formError: string
f8b530e0
RK
28
29 constructor (private notifier: Notifier) { }
30
31 get inputType () {
32 return this.show
33 ? 'text'
34 : 'password'
35 }
36
37 get toggleTitle () {
38 return this.show
39 ? $localize`Hide`
40 : $localize`Show`
41 }
42
43 toggle () {
44 this.show = !this.show
45 }
46
47 activateCopiedMessage () {
48 this.notifier.success($localize`Copied`)
49 }
50
51 propagateChange = (_: any) => { /* empty */ }
52
53 writeValue (value: string) {
54 this.value = value
55 }
56
57 registerOnChange (fn: (_: any) => void) {
58 this.propagateChange = fn
59 }
60
61 registerOnTouched () {
62 // Unused
63 }
64
65 update () {
66 this.propagateChange(this.value)
67 }
68}