feature-libs/product-configurator/rulebased/components/attribute/types/checkbox-list/configurator-attribute-checkbox-list.component.ts
ConfiguratorAttributeMultiSelectionBaseComponent
| changeDetection | ChangeDetectionStrategy.OnPush |
| selector | cx-configurator-attribute-checkbox-list |
| templateUrl | ./configurator-attribute-checkbox-list.component.html |
Properties |
Methods |
Inputs |
Outputs |
Accessors |
constructor(configUtilsService: ConfiguratorStorefrontUtilsService, quantityService: ConfiguratorAttributeQuantityService)
|
|||||||||
|
Parameters :
|
| group | |
Type : string
|
|
| attribute | |
Type : Configurator.Attribute
|
|
|
Inherited from
ConfiguratorAttributeMultiSelectionBaseComponent
|
|
| ownerKey | |
Type : string
|
|
|
Inherited from
ConfiguratorAttributeMultiSelectionBaseComponent
|
|
| selectionChange | |
Type : EventEmitter
|
|
|
Inherited from
ConfiguratorAttributeMultiSelectionBaseComponent
|
|
| ngOnInit |
ngOnInit()
|
|
Returns :
void
|
| onChangeQuantity | ||||||
onChangeQuantity(eventObject: any)
|
||||||
|
Parameters :
Returns :
void
|
| onChangeValueQuantity |
onChangeValueQuantity(eventObject: any, valueCode: string, formIndex: number)
|
|
Returns :
void
|
| onSelect |
onSelect()
|
|
Returns :
void
|
| extractPriceFormulaParameters |
extractPriceFormulaParameters()
|
|
Inherited from
ConfiguratorAttributeMultiSelectionBaseComponent
|
|
Extract corresponding price formula parameters. For the multi-selection attribute types only total price of the attribute should be displayed at the attribute level.
Returns :
ConfiguratorPriceComponentOptions
|
| extractQuantityParameters | ||||||||||||
extractQuantityParameters(initialQuantity?: number, allowZero?: boolean)
|
||||||||||||
|
Inherited from
ConfiguratorAttributeMultiSelectionBaseComponent
|
||||||||||||
|
Extract corresponding quantity parameters
Parameters :
|
| extractValuePriceFormulaParameters | ||||||||
extractValuePriceFormulaParameters(value: Configurator.Value)
|
||||||||
|
Inherited from
ConfiguratorAttributeMultiSelectionBaseComponent
|
||||||||
|
Extract corresponding value price formula parameters. For the multi-selection attribute types the complete price formula should be displayed at the value level.
Parameters :
|
| Protected onHandleAttributeQuantity | ||||||
onHandleAttributeQuantity(quantity: number)
|
||||||
|
Inherited from
ConfiguratorAttributeMultiSelectionBaseComponent
|
||||||
|
Parameters :
Returns :
void
|
| attributeCheckBoxForms |
Default value : new Array<FormControl>()
|
| group |
Type : string
|
Decorators :
@Input()
|
| attribute |
Type : Configurator.Attribute
|
Decorators :
@Input()
|
|
Inherited from
ConfiguratorAttributeMultiSelectionBaseComponent
|
| loading$ |
Default value : new BehaviorSubject<boolean>(false)
|
|
Inherited from
ConfiguratorAttributeMultiSelectionBaseComponent
|
| ownerKey |
Type : string
|
Decorators :
@Input()
|
|
Inherited from
ConfiguratorAttributeMultiSelectionBaseComponent
|
| selectionChange |
Default value : new EventEmitter<ConfigFormUpdateEvent>()
|
Decorators :
@Output()
|
|
Inherited from
ConfiguratorAttributeMultiSelectionBaseComponent
|
| 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>