|
|
@ -5,7 +5,7 @@ |
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, forwardRef, Input, OnInit } from '@angular/core'; |
|
|
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, forwardRef, Input, OnChanges } from '@angular/core'; |
|
|
import { FormControl, NG_VALUE_ACCESSOR } from '@angular/forms'; |
|
|
import { FormControl, NG_VALUE_ACCESSOR } from '@angular/forms'; |
|
|
|
|
|
|
|
|
import { |
|
|
import { |
|
|
@ -48,7 +48,7 @@ const NO_EMIT = { emitEvent: false }; |
|
|
providers: [SQX_REFERENCES_DROPDOWN_CONTROL_VALUE_ACCESSOR], |
|
|
providers: [SQX_REFERENCES_DROPDOWN_CONTROL_VALUE_ACCESSOR], |
|
|
changeDetection: ChangeDetectionStrategy.OnPush |
|
|
changeDetection: ChangeDetectionStrategy.OnPush |
|
|
}) |
|
|
}) |
|
|
export class ReferencesDropdownComponent extends StatefulControlComponent<State, ReadonlyArray<string> | string> implements OnInit { |
|
|
export class ReferencesDropdownComponent extends StatefulControlComponent<State, ReadonlyArray<string> | string> implements OnChanges { |
|
|
private languageField: LanguageDto; |
|
|
private languageField: LanguageDto; |
|
|
private selectedId: string | undefined; |
|
|
private selectedId: string | undefined; |
|
|
private itemCount: number; |
|
|
private itemCount: number; |
|
|
@ -59,6 +59,10 @@ export class ReferencesDropdownComponent extends StatefulControlComponent<State, |
|
|
@Input() |
|
|
@Input() |
|
|
public mode: 'Array' | 'Single'; |
|
|
public mode: 'Array' | 'Single'; |
|
|
|
|
|
|
|
|
|
|
|
public get isValid() { |
|
|
|
|
|
return !!this.schemaId && !!this.languageField; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Input() |
|
|
@Input() |
|
|
public set language(value: LanguageDto) { |
|
|
public set language(value: LanguageDto) { |
|
|
this.languageField = value; |
|
|
this.languageField = value; |
|
|
@ -102,8 +106,8 @@ export class ReferencesDropdownComponent extends StatefulControlComponent<State, |
|
|
})); |
|
|
})); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngOnInit() { |
|
|
public ngOnChanges() { |
|
|
if (!this.schemaId || this.language) { |
|
|
if (!this.isValid) { |
|
|
this.selectionControl.disable(); |
|
|
this.selectionControl.disable(); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
@ -121,6 +125,16 @@ export class ReferencesDropdownComponent extends StatefulControlComponent<State, |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public setDisabledState(isDisabled: boolean) { |
|
|
|
|
|
if (isDisabled) { |
|
|
|
|
|
this.selectionControl.disable(); |
|
|
|
|
|
} else if (this.isValid) { |
|
|
|
|
|
this.selectionControl.enable(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
super.setDisabledState(isDisabled); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public writeValue(obj: any) { |
|
|
public writeValue(obj: any) { |
|
|
if (Types.isString(obj)) { |
|
|
if (Types.isString(obj)) { |
|
|
this.selectedId = obj; |
|
|
this.selectedId = obj; |
|
|
|