]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/forms/peertube-checkbox.component.ts
Fix broken playlist api
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / forms / peertube-checkbox.component.ts
CommitLineData
8dfceec4 1import { ChangeDetectorRef, Component, forwardRef, Input, OnChanges, SimpleChanges } from '@angular/core'
0f7fedc3
C
2import { 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})
16export class PeertubeCheckboxComponent implements ControlValueAccessor {
17 @Input() checked = false
18 @Input() inputName: string
19 @Input() labelText: string
b4a929ac 20 @Input() labelHtml: string
0f7fedc3 21 @Input() helpHtml: string
8e8eb261 22 @Input() helpPlacement = 'top'
14e2014a 23 @Input() disabled = false
0f7fedc3 24
8dfceec4
C
25 // FIXME: https://github.com/angular/angular/issues/10816#issuecomment-307567836
26 @Input() onPushWorkaround = false
27
28 constructor (private cdr: ChangeDetectorRef) { }
29
0f7fedc3
C
30 propagateChange = (_: any) => { /* empty */ }
31
32 writeValue (checked: boolean) {
33 this.checked = checked
8dfceec4
C
34
35 if (this.onPushWorkaround) {
36 this.cdr.markForCheck()
37 }
0f7fedc3
C
38 }
39
40 registerOnChange (fn: (_: any) => void) {
41 this.propagateChange = fn
42 }
43
44 registerOnTouched () {
45 // Unused
46 }
47
48 onModelChange () {
49 this.propagateChange(this.checked)
50 }
51
52 setDisabledState (isDisabled: boolean) {
14e2014a 53 this.disabled = isDisabled
0f7fedc3
C
54 }
55}