-
rhenck authored
Separating code changes is rather hard right now, so there is a lot of stuff that is part of this commit that should not. Details below. - All elements have static fields that holds their title and icon. This way dynamic lists can be built (for example for delete dialog) which show title and icon for all elements. ALso icons and names can be changed in one place. - Template-Tab has been added. This should have templates to help creating groups of ui elements. This is work in progress and there are actually no templates yet. So this will change or even be removed in the future. This is mostly UI, the code is "TODO". - Refactoring and improvement for delete and reference dialogs - Delete logic refactored for elements, sections and pages. There are no longer different dialogs when references are found, but instead one dialog that can do both.
rhenck authoredSeparating code changes is rather hard right now, so there is a lot of stuff that is part of this commit that should not. Details below. - All elements have static fields that holds their title and icon. This way dynamic lists can be built (for example for delete dialog) which show title and icon for all elements. ALso icons and names can be changed in one place. - Template-Tab has been added. This should have templates to help creating groups of ui elements. This is work in progress and there are actually no templates yet. So this will change or even be removed in the future. This is mostly UI, the code is "TODO". - Refactoring and improvement for delete and reference dialogs - Delete logic refactored for elements, sections and pages. There are no longer different dialogs when references are found, but instead one dialog that can do both.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
checkbox.ts 2.52 KiB
import { Type } from '@angular/core';
import {
InputElement, InputElementProperties, UIElementType
} from 'common/models/elements/element';
import { ElementComponent } from 'common/directives/element-component.directive';
import { CheckboxComponent } from 'common/components/input-elements/checkbox.component';
import { VariableInfo, VariableValue } from '@iqb/responses';
import {
BasicStyles, PropertyGroupGenerators, PropertyGroupValidators
} from 'common/models/elements/property-group-interfaces';
import { environment } from 'common/environment';
import { InstantiationEror } from 'common/util/errors';
export class CheckboxElement extends InputElement implements CheckboxProperties {
type: UIElementType = 'checkbox';
value: boolean = false;
crossOutChecked: boolean = false;
styling: BasicStyles;
static title: string = 'Kontrollkästchen';
static icon: string = 'check_box';
constructor(element?: CheckboxProperties) {
super(element);
if (element && isValid(element)) {
this.crossOutChecked = element.crossOutChecked;
this.styling = { ...element.styling };
} else {
if (environment.strictInstantiation) {
throw new InstantiationEror('Error at Checkbox instantiation', element);
}
if (element?.crossOutChecked !== undefined) this.crossOutChecked = element.crossOutChecked;
this.dimensions = PropertyGroupGenerators.generateDimensionProps({
width: 215,
...element?.dimensions
});
this.styling = PropertyGroupGenerators.generateBasicStyleProps(element?.styling);
}
}
getDuplicate(): CheckboxElement {
return new CheckboxElement(this);
}
getVariableInfos(): VariableInfo[] {
return [{
id: this.id,
type: 'boolean',
format: '',
multiple: false,
nullable: false,
values: this.getVariableInfoValues(),
valuePositionLabels: [],
page: '',
valuesComplete: true
}];
}
private getVariableInfoValues(): VariableValue[] {
return [
{ value: 'true', label: `Angekreuzt: ${this.label}` },
{ value: 'false', label: `Nicht Angekreuzt: ${this.label}` }
];
}
getElementComponent(): Type<ElementComponent> {
return CheckboxComponent;
}
}
export interface CheckboxProperties extends InputElementProperties {
crossOutChecked: boolean;
styling: BasicStyles;
}
function isValid(blueprint?: CheckboxProperties): boolean {
if (!blueprint) return false;
return blueprint.crossOutChecked !== undefined &&
PropertyGroupValidators.isValidBasicStyles(blueprint.styling);
}