Skip to content
Snippets Groups Projects
radio-button-group-complex.ts 1.84 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Type } from '@angular/core';
    
    import {
    
      BasicStyles, InputElement, OptionElement,
    
      PositionedUIElement, PositionProperties, TextImageLabel,
    
    rhenck's avatar
    rhenck committed
      AnswerScheme, AnswerSchemeValue, UIElement
    
    } from 'common/models/elements/element';
    import { ElementComponent } from 'common/directives/element-component.directive';
    import { RadioGroupImagesComponent } from 'common/components/input-elements/radio-group-images.component';
    
    
    export class RadioButtonGroupComplexElement extends InputElement implements PositionedUIElement, OptionElement {
      options: TextImageLabel[] = [];
    
      itemsPerRow: number | null;
    
      position: PositionProperties;
      styling: BasicStyles;
    
    
    rhenck's avatar
    rhenck committed
      constructor(element: Partial<RadioButtonGroupComplexElement>) {
        super({ height: 100, ...element });
    
        if (element.options) this.options = [...element.options];
    
        this.itemsPerRow = element.itemsPerRow !== undefined ? element.itemsPerRow : null;
    
    rhenck's avatar
    rhenck committed
        this.position = UIElement.initPositionProps({ marginBottom: 40, ...element.position });
    
        this.styling = {
    
    rhenck's avatar
    rhenck committed
          ...UIElement.initStylingProps({ backgroundColor: 'transparent', ...element.styling })
    
      hasAnswerScheme(): boolean {
    
        return Boolean(this.getAnswerScheme);
    
      getAnswerScheme(): AnswerScheme {
    
        return {
          id: this.id,
          type: 'integer',
          format: '',
          multiple: false,
    
          nullable: !this.value && this.value !== 0,
    
          values: this.getAnswerSchemeValues(),
    
      private getAnswerSchemeValues(): AnswerSchemeValue[] {
    
        return this.options
          .map((option, index) => ({ value: (index + 1).toString(), label: option.text }));
    
      getElementComponent(): Type<ElementComponent> {
    
        return RadioGroupImagesComponent;
      }
    
    rhenck's avatar
    rhenck committed
      getNewOptionLabel(optionText: string): TextImageLabel {
    
    rhenck's avatar
    rhenck committed
        return UIElement.createOptionLabel(optionText, true) as TextImageLabel;