Fix method names
[oweals/peertube.git] / client / src / app / shared / forms / peertube-checkbox.component.ts
1 import { ChangeDetectorRef, Component, forwardRef, Input, OnChanges, SimpleChanges } from '@angular/core'
2 import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
3
4 @Component({
5   selector: 'my-peertube-checkbox',
6   styleUrls: [ './peertube-checkbox.component.scss' ],
7   templateUrl: './peertube-checkbox.component.html',
8   providers: [
9     {
10       provide: NG_VALUE_ACCESSOR,
11       useExisting: forwardRef(() => PeertubeCheckboxComponent),
12       multi: true
13     }
14   ]
15 })
16 export class PeertubeCheckboxComponent implements ControlValueAccessor {
17   @Input() checked = false
18   @Input() inputName: string
19   @Input() labelText: string
20   @Input() labelHtml: string
21   @Input() helpHtml: string
22   @Input() disabled = false
23
24   // FIXME: https://github.com/angular/angular/issues/10816#issuecomment-307567836
25   @Input() onPushWorkaround = false
26
27   constructor (private cdr: ChangeDetectorRef) { }
28
29   propagateChange = (_: any) => { /* empty */ }
30
31   writeValue (checked: boolean) {
32     this.checked = checked
33
34     if (this.onPushWorkaround) {
35       this.cdr.markForCheck()
36     }
37   }
38
39   registerOnChange (fn: (_: any) => void) {
40     this.propagateChange = fn
41   }
42
43   registerOnTouched () {
44     // Unused
45   }
46
47   onModelChange () {
48     this.propagateChange(this.checked)
49   }
50
51   setDisabledState (isDisabled: boolean) {
52     this.disabled = isDisabled
53   }
54 }