File

feature-libs/product-configurator/rulebased/components/attribute/types/single-selection-image/configurator-attribute-single-selection-image.component.ts

Extends

ConfiguratorAttributeBaseComponent

Implements

OnInit

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector cx-configurator-attribute-single-selection-image
templateUrl ./configurator-attribute-single-selection-image.component.html

Index

Properties
Methods
Inputs
Outputs

Inputs

attribute
Type : Configurator.Attribute
ownerKey
Type : string

Outputs

selectionChange
Type : EventEmitter

Methods

extractValuePriceFormulaParameters
extractValuePriceFormulaParameters(value?: Configurator.Value)
Parameters :
Name Type Optional
value Configurator.Value Yes
ngOnInit
ngOnInit()
Returns : void
onClick
onClick(value: string)

Submits a value.

Parameters :
Name Type Optional Description
value string No
  • Selected value
Returns : void
createAriaLabelledBy
createAriaLabelledBy(prefix: string, attributeId: string, valueId?: string, hasQuantity?: boolean)

Creates unique key for attribute 'aria-labelledby'

Parameters :
Name Type Optional
prefix string No
attributeId string No
valueId string Yes
hasQuantity boolean Yes
Returns : string
createAttributeIdForConfigurator
createAttributeIdForConfigurator(currentAttribute: Configurator.Attribute)

Creates unique key for config attribute to be sent to configurator

Parameters :
Name Type Optional
currentAttribute Configurator.Attribute No
Returns : string
createAttributeUiKey
createAttributeUiKey(prefix: string, attributeId: string)

Creates unique key for config attribute on the UI

Parameters :
Name Type Optional Description
prefix string No

for key depending on usage (e.g. uiType, label)

attributeId string No
Returns : string
createAttributeValueIdForConfigurator
createAttributeValueIdForConfigurator(currentAttribute: Configurator.Attribute, value: string)

Creates unique key for config value to be sent to configurator

Parameters :
Name Type Optional
currentAttribute Configurator.Attribute No
value string No
Returns : string
createFocusId
createFocusId(attributeId: string, valueCode: string)

Creates a unique key for focus handling for the given attribute and value

Parameters :
Name Type Optional
attributeId string No
valueCode string No
Returns : string

focus key

createValueUiKey
createValueUiKey(prefix: string, attributeId: string, valueId: string)

Creates unique key for config value on the UI

Parameters :
Name Type Optional Description
prefix string No

for key depending on usage (e.g. uiType, label)

attributeId string No
valueId string No
Returns : string
Protected getAttributeCode
getAttributeCode(attribute: Configurator.Attribute)

Get code from attribute. The code is not a mandatory attribute (since not available for VC flavour), still it is mandatory in the context of CPQ. Calling this method therefore only makes sense when CPQ is active. In case the method is called in the wrong context, an exception will be thrown

Parameters :
Name Type Optional
attribute Configurator.Attribute No
Returns : number

Attribute code

Protected getUiType
getUiType(attribute: Configurator.Attribute)
Parameters :
Name Type Optional
attribute Configurator.Attribute No
Returns : string

Properties

attribute
Type : Configurator.Attribute
Decorators :
@Input()
attributeRadioButtonForm
Default value : new FormControl('')
ownerKey
Type : string
Decorators :
@Input()
selectionChange
Default value : new EventEmitter<ConfigFormUpdateEvent>()
Decorators :
@Output()
Private Static PREFIX
Type : string
Default value : 'cx-configurator'
Private Static PREFIX_DDLB_OPTION_PRICE_VALUE
Type : string
Default value : 'option--price'
Private Static PREFIX_LABEL
Type : string
Default value : 'label'
Private Static PREFIX_OPTION_PRICE_VALUE
Type : string
Default value : 'price--optionsPriceValue'
Private Static SEPERATOR
Type : string
Default value : '--'
import {
  ChangeDetectionStrategy,
  Component,
  EventEmitter,
  Input,
  OnInit,
  Output,
} from '@angular/core';
import { FormControl } from '@angular/forms';
import { Configurator } from '../../../../core/model/configurator.model';
import { ConfigFormUpdateEvent } from '../../../form/configurator-form.event';
import { ConfiguratorPriceComponentOptions } from '../../../price/configurator-price.component';
import { ConfiguratorAttributeBaseComponent } from '../base/configurator-attribute-base.component';

@Component({
  selector: 'cx-configurator-attribute-single-selection-image',
  templateUrl: './configurator-attribute-single-selection-image.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ConfiguratorAttributeSingleSelectionImageComponent
  extends ConfiguratorAttributeBaseComponent
  implements OnInit
{
  attributeRadioButtonForm = new FormControl('');

  @Input() attribute: Configurator.Attribute;
  @Input() ownerKey: string;

  @Output() selectionChange = new EventEmitter<ConfigFormUpdateEvent>();

  ngOnInit(): void {
    this.attributeRadioButtonForm.setValue(this.attribute.selectedSingleValue);
  }

  /**
   * Submits a value.
   *
   * @param {string} value - Selected value
   */
  onClick(value: string): void {
    const event: ConfigFormUpdateEvent = {
      ownerKey: this.ownerKey,
      changedAttribute: {
        ...this.attribute,
        selectedSingleValue: value,
      },
    };
    this.selectionChange.emit(event);
  }

  extractValuePriceFormulaParameters(
    value?: Configurator.Value
  ): ConfiguratorPriceComponentOptions | undefined {
    if (value) {
      return {
        price: value.valuePrice,
        isLightedUp: value.selected,
      };
    }
  }
}
<div id="{{ createAttributeIdForConfigurator(attribute) }}" class="cx-row">
  <div
    *ngFor="let value of attribute.values"
    id="{{ createAttributeValueIdForConfigurator(attribute, value.valueCode) }}"
    class="cx-configurator-select"
  >
    <input
      id="{{
        createAttributeValueIdForConfigurator(attribute, value.valueCode) +
          '-input'
      }}"
      type="radio"
      class="form-input"
      [value]="value.valueCode"
      formcontrolname="attributeRadioButtonForm"
      [formControl]="attributeRadioButtonForm"
      [value]="value.valueCode"
      name="{{ createAttributeIdForConfigurator(attribute) }}"
      attr.name="{{ createAttributeIdForConfigurator(attribute) }}"
      [attr.required]="attribute.required"
      [attr.aria-labelledby]="
        createAriaLabelledBy('label', attribute.name, value.valueCode)
      "
      [attr.aria-checked]="
        attributeRadioButtonForm.value === value.valueCode ? true : false
      "
      [attr.checked]="
        attributeRadioButtonForm.value === value.valueCode ? 'checked' : null
      "
      (click)="onClick(value.valueCode)"
      [cxFocus]="{ key: attribute.name + '-' + value.name }"
    />
    <div class="cx-label-container">
      <label
        id="{{ createValueUiKey('label', attribute.name, value.valueCode) }}"
        for="{{
          createAttributeValueIdForConfigurator(attribute, value.valueCode) +
            '-input'
        }}"
        class="form-check-label form-radio-label"
      >
        <img
          *ngIf="value.images[0]"
          class="cx-img"
          src="{{ value.images[0].url }}"
          alt="{{ value.images[0].altText }}"
        />
        <div *ngIf="!value.images[0]" class="cx-img-dummy"></div>
        {{ value.valueDisplay }}
        <cx-configurator-price
          [formula]="extractValuePriceFormulaParameters(value)"
        ></cx-configurator-price>
      </label>
    </div>
  </div>
</div>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""