Newer
Older
InputElement, InputElementProperties, OptionElement, UIElement, UIElementType
} from 'common/models/elements/element';
import { ElementComponent } from 'common/directives/element-component.directive';
import { RadioGroupImagesComponent } from 'common/components/input-elements/radio-group-images.component';
import { VariableInfo, VariableValue } from '@iqb/responses';
import { TextImageLabel } from 'common/models/elements/label-interfaces';
import {
BasicStyles, PositionProperties, PropertyGroupGenerators, PropertyGroupValidators
} from 'common/models/elements/property-group-interfaces';
import { environment } from 'common/environment';
import { InstantiationEror } from 'common/util/errors';
export class RadioButtonGroupComplexElement extends InputElement
implements OptionElement, RadioButtonGroupComplexProperties {
type: UIElementType = 'radio-group-images';
options: TextImageLabel[] = [];
itemsPerRow: number | null = null;
position: PositionProperties;
styling: BasicStyles;
static title: string = 'Optionsfelder (mit Bild)';
static icon: string = 'radio_button_checked';
constructor(element?: RadioButtonGroupComplexProperties) {
this.position = { ...element.position };
this.styling = { ...element.styling };
} else {
if (environment.strictInstantiation) {
throw new InstantiationEror('Error at RadioButtonGroupComplex instantiation', element);
}
if (element?.label !== undefined) this.label = element.label;
if (element?.options) this.options = [...element.options];
if (element?.itemsPerRow) this.itemsPerRow = element.itemsPerRow;
this.dimensions = PropertyGroupGenerators.generateDimensionProps({
height: 100,
...element?.dimensions
});
this.position = PropertyGroupGenerators.generatePositionProps({
...element?.position
});
this.styling = PropertyGroupGenerators.generateBasicStyleProps(element?.styling);
}
getDuplicate(): RadioButtonGroupComplexElement {
return new RadioButtonGroupComplexElement(this);
}
getVariableInfos(): VariableInfo[] {
return [{
id: this.id,
type: 'integer',
format: '',
multiple: false,
values: this.getVariableInfoValues(),
valuePositionLabels: [],
page: '',
private getVariableInfoValues(): VariableValue[] {
.map((option, index) => ({
value: (index + 1).toString(),
label: InputElement.stripHTML(option.text)
}));
getElementComponent(): Type<ElementComponent> {
getNewOptionLabel(optionText: string): TextImageLabel {
return UIElement.createOptionLabel(optionText, true) as TextImageLabel;
export interface RadioButtonGroupComplexProperties extends InputElementProperties {
options: TextImageLabel[];
itemsPerRow: number | null;
position: PositionProperties;
styling: BasicStyles;
}
function isValid(blueprint?: RadioButtonGroupComplexProperties): boolean {
if (!blueprint) return false;
return blueprint.label !== undefined &&
blueprint.options !== undefined &&