File

feature-libs/product-configurator/rulebased/components/attribute/types/checkbox-list/configurator-attribute-checkbox-list.component.ts

Extends

ConfiguratorAttributeMultiSelectionBaseComponent

Implements

OnInit

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector cx-configurator-attribute-checkbox-list
templateUrl ./configurator-attribute-checkbox-list.component.html

Index

Properties
Methods
Inputs
Outputs
Accessors

Constructor

constructor(configUtilsService: ConfiguratorStorefrontUtilsService, quantityService: ConfiguratorAttributeQuantityService)
Parameters :
Name Type Optional
configUtilsService ConfiguratorStorefrontUtilsService No
quantityService ConfiguratorAttributeQuantityService No

Inputs

group
Type : string
attribute
Type : Configurator.Attribute
ownerKey
Type : string

Outputs

selectionChange
Type : EventEmitter

Methods

ngOnInit
ngOnInit()
Returns : void
onChangeQuantity
onChangeQuantity(eventObject: any)
Parameters :
Name Type Optional
eventObject any No
Returns : void
onChangeValueQuantity
onChangeValueQuantity(eventObject: any, valueCode: string, formIndex: number)
Parameters :
Name Type Optional
eventObject any No
valueCode string No
formIndex number No
Returns : void
onSelect
onSelect()
Returns : void
extractPriceFormulaParameters
extractPriceFormulaParameters()

Extract corresponding price formula parameters. For the multi-selection attribute types only total price of the attribute should be displayed at the attribute level.

  • New price formula
extractQuantityParameters
extractQuantityParameters(initialQuantity?: number, allowZero?: boolean)

Extract corresponding quantity parameters

Parameters :
Name Type Optional Description
initialQuantity number Yes
  • Initial quantity
allowZero boolean Yes
  • Allow zero
  • New quantity options
extractValuePriceFormulaParameters
extractValuePriceFormulaParameters(value: Configurator.Value)

Extract corresponding value price formula parameters. For the multi-selection attribute types the complete price formula should be displayed at the value level.

Parameters :
Name Type Optional Description
value Configurator.Value No
  • Configurator value
  • New price formula
Protected onHandleAttributeQuantity
onHandleAttributeQuantity(quantity: number)
Parameters :
Name Type Optional
quantity number No
Returns : void

Properties

attributeCheckBoxForms
Default value : new Array<FormControl>()
group
Type : string
Decorators :
@Input()
attribute
Type : Configurator.Attribute
Decorators :
@Input()
loading$
Default value : new BehaviorSubject<boolean>(false)
ownerKey
Type : string
Decorators :
@Input()
selectionChange
Default value : new EventEmitter<ConfigFormUpdateEvent>()
Decorators :
@Output()

Accessors

allowZeroValueQuantity
getallowZeroValueQuantity()
import {
  ChangeDetectionStrategy,
  Component,
  Input,
  isDevMode,
  OnInit,
} from '@angular/core';
import { FormControl } from '@angular/forms';
import { Configurator } from '../../../../core/model/configurator.model';
import { ConfigFormUpdateEvent } from '../../../form/configurator-form.event';
import { ConfiguratorStorefrontUtilsService } from '../../../service/configurator-storefront-utils.service';
import { ConfiguratorAttributeQuantityService } from '../../quantity/configurator-attribute-quantity.service';
import { ConfiguratorAttributeMultiSelectionBaseComponent } from '../base/configurator-attribute-multi-selection-base.component';

@Component({
  selector: 'cx-configurator-attribute-checkbox-list',
  templateUrl: './configurator-attribute-checkbox-list.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ConfiguratorAttributeCheckBoxListComponent
  extends ConfiguratorAttributeMultiSelectionBaseComponent
  implements OnInit
{
  attributeCheckBoxForms = new Array<FormControl>();

  @Input() group: string;

  constructor(
    protected configUtilsService: ConfiguratorStorefrontUtilsService,
    protected quantityService: ConfiguratorAttributeQuantityService
  ) {
    super(quantityService);
  }

  ngOnInit(): void {
    const disabled = !this.allowZeroValueQuantity;

    if (this.attribute.values) {
      for (const value of this.attribute.values) {
        let attributeCheckBoxForm;

        if (value.selected) {
          attributeCheckBoxForm = new FormControl({
            value: true,
            disabled: disabled,
          });
        } else {
          attributeCheckBoxForm = new FormControl(false);
        }
        this.attributeCheckBoxForms.push(attributeCheckBoxForm);
      }
    }
  }

  get allowZeroValueQuantity(): boolean {
    return this.quantityService.allowZeroValueQuantity(this.attribute) ?? false;
  }

  onSelect(): void {
    const selectedValues =
      this.configUtilsService.assembleValuesForMultiSelectAttributes(
        this.attributeCheckBoxForms,
        this.attribute
      );

    const event: ConfigFormUpdateEvent = {
      changedAttribute: {
        ...this.attribute,
        values: selectedValues,
      },
      ownerKey: this.ownerKey,
      updateType: Configurator.UpdateType.ATTRIBUTE,
    };

    this.selectionChange.emit(event);
  }

  onChangeValueQuantity(
    eventObject: any,
    valueCode: string,
    formIndex: number
  ): void {
    if (eventObject === 0) {
      this.attributeCheckBoxForms[formIndex].setValue(false);
      this.onSelect();
      return;
    }

    const value: Configurator.Value | undefined = this.configUtilsService
      .assembleValuesForMultiSelectAttributes(
        this.attributeCheckBoxForms,
        this.attribute
      )
      .find((item) => item.valueCode === valueCode);

    if (!value) {
      if (isDevMode()) {
        console.warn('no value for event:', eventObject);
      }

      return;
    }

    value.quantity = eventObject;

    const event: ConfigFormUpdateEvent = {
      changedAttribute: {
        ...this.attribute,
        values: [value],
      },
      ownerKey: this.ownerKey,
      updateType: Configurator.UpdateType.VALUE_QUANTITY,
    };

    this.selectionChange.emit(event);
  }

  onChangeQuantity(eventObject: any): void {
    if (!eventObject) {
      this.attributeCheckBoxForms.forEach((_, index) =>
        this.attributeCheckBoxForms[index].setValue(false)
      );
      this.onSelect();
    } else {
      this.onHandleAttributeQuantity(eventObject);
    }
  }
}
<fieldset>
  <legend style="display: none">{{ attribute.label }}</legend>
  <div id="{{ createAttributeIdForConfigurator(attribute) }}">
    <div
      *ngIf="withQuantityOnAttributeLevel"
      class="cx-attribute-level-quantity-price"
    >
      <cx-configurator-attribute-quantity
        (changeQuantity)="onChangeQuantity($event)"
        [quantityOptions]="
          extractQuantityParameters(attribute.quantity, !attribute.required)
        "
      ></cx-configurator-attribute-quantity>
      <cx-configurator-price
        [formula]="extractPriceFormulaParameters()"
      ></cx-configurator-price>
    </div>
    <ng-container *ngFor="let value of attribute.values; let i = index">
      <div class="form-check">
        <div class="cx-value-label-pair">
          <input
            id="{{
              createAttributeValueIdForConfigurator(attribute, value.valueCode)
            }}"
            type="checkbox"
            class="form-check-input"
            [cxFocus]="{ key: attribute.name + '-' + value.name }"
            [value]="value.valueCode"
            (change)="onSelect()"
            [formControl]="attributeCheckBoxForms[i]"
            name="{{ createAttributeIdForConfigurator(attribute) }}"
          />
          <label
            id="{{
              createValueUiKey('label', attribute.name, value.valueCode)
            }}"
            for="{{
              createAttributeValueIdForConfigurator(attribute, value.valueCode)
            }}"
            class="cx-configurator-attribute-value-label form-check-label"
            >{{ value.valueDisplay }}</label
          >
        </div>
        <div class="cx-value-price">
          <cx-configurator-price
            [formula]="extractValuePriceFormulaParameters(value)"
          ></cx-configurator-price>
        </div>
      </div>
      <cx-configurator-attribute-quantity
        *ngIf="value.selected && withQuantity && !withQuantityOnAttributeLevel"
        (changeQuantity)="onChangeValueQuantity($event, value.valueCode, i)"
        [quantityOptions]="
          extractQuantityParameters(value.quantity, allowZeroValueQuantity)
        "
      ></cx-configurator-attribute-quantity>
    </ng-container>
  </div>
</fieldset>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""