@spartacus/order
Version:
Order feature library for Spartacus
753 lines (736 loc) • 207 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@spartacus/core'), require('@angular/router'), require('@angular/common'), require('@angular/forms'), require('rxjs/operators'), require('@spartacus/order/root'), require('@spartacus/storefront'), require('@ng-bootstrap/ng-bootstrap'), require('@ng-select/ng-select'), require('rxjs')) :
typeof define === 'function' && define.amd ? define('@spartacus/order/components', ['exports', '@angular/core', '@spartacus/core', '@angular/router', '@angular/common', '@angular/forms', 'rxjs/operators', '@spartacus/order/root', '@spartacus/storefront', '@ng-bootstrap/ng-bootstrap', '@ng-select/ng-select', 'rxjs'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.spartacus = global.spartacus || {}, global.spartacus.order = global.spartacus.order || {}, global.spartacus.order.components = {}), global.ng.core, global.core, global.ng.router, global.ng.common, global.ng.forms, global.rxjs.operators, global.spartacus.order.root, global.storefront, global.i1$1, global.ngSelect, global.rxjs));
}(this, (function (exports, i0, i1, i3, i4, i5, operators, i2, i3$1, i1$1, ngSelect, rxjs) { 'use strict';
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
var i3__namespace = /*#__PURE__*/_interopNamespace(i3);
var i4__namespace = /*#__PURE__*/_interopNamespace(i4);
var i5__namespace = /*#__PURE__*/_interopNamespace(i5);
var i2__namespace = /*#__PURE__*/_interopNamespace(i2);
var i3__namespace$1 = /*#__PURE__*/_interopNamespace(i3$1);
var i1__namespace$1 = /*#__PURE__*/_interopNamespace(i1$1);
var AmendOrderActionsComponent = /** @class */ (function () {
function AmendOrderActionsComponent(routingService) {
this.routingService = routingService;
this.styles = 'row';
}
AmendOrderActionsComponent.prototype.continue = function (event) {
if (this.amendOrderForm.valid) {
this.routingService.go({
cxRoute: this.forwardRoute,
params: { code: this.orderCode },
});
}
else {
this.amendOrderForm.markAllAsTouched();
event.stopPropagation();
}
};
return AmendOrderActionsComponent;
}());
AmendOrderActionsComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: AmendOrderActionsComponent, deps: [{ token: i1__namespace.RoutingService }], target: i0__namespace.ɵɵFactoryTarget.Component });
AmendOrderActionsComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.5", type: AmendOrderActionsComponent, selector: "cx-amend-order-actions", inputs: { orderCode: "orderCode", amendOrderForm: "amendOrderForm", backRoute: "backRoute", forwardRoute: "forwardRoute" }, host: { properties: { "class": "this.styles" } }, ngImport: i0__namespace, template: "<div class=\"col-xs-12 col-md-4 col-lg-3\">\n <a\n [routerLink]=\"\n {\n cxRoute: backRoute,\n params: { code: orderCode }\n } | cxUrl\n \"\n class=\"btn btn-block btn-action\"\n >\n {{ 'common.back' | cxTranslate }}\n </a>\n</div>\n<div class=\"col-xs-12 col-md-4 col-lg-3\">\n <button\n *ngIf=\"forwardRoute\"\n class=\"btn btn-block btn-primary\"\n (click)=\"continue($event)\"\n >\n {{ 'common.continue' | cxTranslate }}\n </button>\n\n <button *ngIf=\"!forwardRoute\" class=\"btn btn-block btn-primary\" type=\"submit\">\n {{ 'orderDetails.cancellationAndReturn.submit' | cxTranslate }}\n </button>\n</div>\n", directives: [{ type: i3__namespace.RouterLinkWithHref, selector: "a[routerLink],area[routerLink]", inputs: ["routerLink", "target", "queryParams", "fragment", "queryParamsHandling", "preserveFragment", "skipLocationChange", "replaceUrl", "state", "relativeTo"] }, { type: i4__namespace.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], pipes: { "cxUrl": i1__namespace.UrlPipe, "cxTranslate": i1__namespace.TranslatePipe }, changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: AmendOrderActionsComponent, decorators: [{
type: i0.Component,
args: [{
selector: 'cx-amend-order-actions',
templateUrl: './amend-order-actions.component.html',
changeDetection: i0.ChangeDetectionStrategy.OnPush,
}]
}], ctorParameters: function () { return [{ type: i1__namespace.RoutingService }]; }, propDecorators: { orderCode: [{
type: i0.Input
}], amendOrderForm: [{
type: i0.Input
}], backRoute: [{
type: i0.Input
}], forwardRoute: [{
type: i0.Input
}], styles: [{
type: i0.HostBinding,
args: ['class']
}] } });
var AmendOrderActionsModule = /** @class */ (function () {
function AmendOrderActionsModule() {
}
return AmendOrderActionsModule;
}());
AmendOrderActionsModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: AmendOrderActionsModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
AmendOrderActionsModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: AmendOrderActionsModule, declarations: [AmendOrderActionsComponent], imports: [i4.CommonModule, i3.RouterModule, i1.UrlModule, i1.I18nModule], exports: [AmendOrderActionsComponent] });
AmendOrderActionsModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: AmendOrderActionsModule, imports: [[i4.CommonModule, i3.RouterModule, i1.UrlModule, i1.I18nModule]] });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: AmendOrderActionsModule, decorators: [{
type: i0.NgModule,
args: [{
imports: [i4.CommonModule, i3.RouterModule, i1.UrlModule, i1.I18nModule],
declarations: [AmendOrderActionsComponent],
exports: [AmendOrderActionsComponent],
}]
}] });
exports.AmendOrderType = void 0;
(function (AmendOrderType) {
AmendOrderType[AmendOrderType["CANCEL"] = 0] = "CANCEL";
AmendOrderType[AmendOrderType["RETURN"] = 1] = "RETURN";
})(exports.AmendOrderType || (exports.AmendOrderType = {}));
var OrderDetailsService = /** @class */ (function () {
function OrderDetailsService(userOrderService, routingService) {
var _this = this;
this.userOrderService = userOrderService;
this.routingService = routingService;
this.orderCode$ = this.routingService.getRouterState().pipe(operators.map(function (routingData) { return routingData.state.params.orderCode; }), operators.distinctUntilChanged());
this.orderLoad$ = this.orderCode$.pipe(operators.tap(function (orderCode) {
if (orderCode) {
_this.userOrderService.loadOrderDetails(orderCode);
}
else {
_this.userOrderService.clearOrderDetails();
}
}), operators.shareReplay({ bufferSize: 1, refCount: true }));
}
OrderDetailsService.prototype.getOrderDetails = function () {
var _this = this;
return this.orderLoad$.pipe(operators.switchMap(function () { return _this.userOrderService.getOrderDetails(); }));
};
return OrderDetailsService;
}());
OrderDetailsService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderDetailsService, deps: [{ token: i2__namespace.OrderFacade }, { token: i1__namespace.RoutingService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
OrderDetailsService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderDetailsService, providedIn: 'root' });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderDetailsService, decorators: [{
type: i0.Injectable,
args: [{
providedIn: 'root',
}]
}], ctorParameters: function () { return [{ type: i2__namespace.OrderFacade }, { type: i1__namespace.RoutingService }]; } });
function ValidateQuantityToCancel(control) {
if (!control.value) {
return null;
}
var quantity = Object.values(control.value).reduce(function (acc, val) { return acc + val; }, 0);
return quantity > 0 ? null : { cxNoSelectedItemToCancel: true };
}
var OrderAmendService = /** @class */ (function () {
function OrderAmendService(orderDetailsService) {
this.orderDetailsService = orderDetailsService;
}
/**
* Returns entries with an amended quantity.
*/
OrderAmendService.prototype.getAmendedEntries = function () {
var _this = this;
return this.getForm().pipe(operators.switchMap(function (form) {
return _this.getEntries().pipe(operators.map(function (entries) { return entries.filter(function (entry) { return _this.getFormControl(form, entry).value > 0; }); }));
}));
};
OrderAmendService.prototype.getOrder = function () {
return this.orderDetailsService.getOrderDetails();
};
/**
* returns the form with form data at runtime
*/
OrderAmendService.prototype.getForm = function () {
var _this = this;
return this.getOrder().pipe(operators.tap(function (order) {
var _a;
if (!_this.form || ((_a = _this.form.get('orderCode')) === null || _a === void 0 ? void 0 : _a.value) !== order.code) {
_this.buildForm(order);
}
}), operators.map(function () { return _this.form; }));
};
OrderAmendService.prototype.buildForm = function (order) {
var _this = this;
this.form = new i5.FormGroup({});
this.form.addControl('orderCode', new i5.FormControl(order.code));
var entryGroup = new i5.FormGroup({}, { validators: [ValidateQuantityToCancel] });
this.form.addControl('entries', entryGroup);
(order.entries || []).forEach(function (entry) {
var _a, _b;
var key = (_b = (_a = entry === null || entry === void 0 ? void 0 : entry.entryNumber) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '';
entryGroup.addControl(key, new i5.FormControl(0, {
validators: [
i5.Validators.min(0),
i5.Validators.max(_this.getMaxAmendQuantity(entry)),
],
}));
});
};
OrderAmendService.prototype.getFormControl = function (form, entry) {
var _a, _b, _c;
return ((_a = form.get('entries')) === null || _a === void 0 ? void 0 : _a.get((_c = (_b = entry.entryNumber) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : ''));
};
/**
* As discussed, this calculation is moved to SPA side.
* The calculation and validation should be in backend facade layer.
*/
OrderAmendService.prototype.getAmendedPrice = function (entry) {
var _a, _b, _c;
var amendedQuantity = this.getFormControl(this.form, entry).value;
var amendedPrice = Object.assign({}, entry.basePrice);
amendedPrice.value =
Math.round(((_b = (_a = entry.basePrice) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0) * amendedQuantity * 100) / 100;
amendedPrice.formattedValue = i4.formatCurrency(amendedPrice.value,
// TODO: user current language
'en', i4.getCurrencySymbol((_c = amendedPrice.currencyIso) !== null && _c !== void 0 ? _c : '', 'narrow'), amendedPrice.currencyIso);
return amendedPrice;
};
OrderAmendService.prototype.getMaxAmendQuantity = function (entry) {
return ((this.isCancellation()
? entry.cancellableQuantity
: entry.returnableQuantity) ||
entry.quantity ||
0);
};
OrderAmendService.prototype.isCancellation = function () {
return this.amendType === exports.AmendOrderType.CANCEL;
};
return OrderAmendService;
}());
OrderAmendService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderAmendService, deps: [{ token: OrderDetailsService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
OrderAmendService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderAmendService });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderAmendService, decorators: [{
type: i0.Injectable
}], ctorParameters: function () { return [{ type: OrderDetailsService }]; } });
var CancelOrReturnItemsComponent = /** @class */ (function () {
function CancelOrReturnItemsComponent(orderAmendService) {
this.orderAmendService = orderAmendService;
this.isConfirmation = false;
this.form$ = this.orderAmendService.getForm();
}
CancelOrReturnItemsComponent.prototype.getControl = function (form, entry) {
var _a, _b, _c;
var control = ((_a = form.get('entries')) === null || _a === void 0 ? void 0 : _a.get((_c = (_b = entry.entryNumber) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : ''));
return control;
};
CancelOrReturnItemsComponent.prototype.setAll = function (form) {
var _this = this;
this.entries.forEach(function (entry) { return _this.getControl(form, entry).setValue(_this.getMaxAmendQuantity(entry)); });
};
CancelOrReturnItemsComponent.prototype.getItemPrice = function (entry) {
return this.orderAmendService.getAmendedPrice(entry);
};
CancelOrReturnItemsComponent.prototype.getMaxAmendQuantity = function (entry) {
return this.orderAmendService.getMaxAmendQuantity(entry);
};
CancelOrReturnItemsComponent.prototype.isCancellation = function () {
return this.orderAmendService.isCancellation();
};
return CancelOrReturnItemsComponent;
}());
CancelOrReturnItemsComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: CancelOrReturnItemsComponent, deps: [{ token: OrderAmendService }], target: i0__namespace.ɵɵFactoryTarget.Component });
CancelOrReturnItemsComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.5", type: CancelOrReturnItemsComponent, selector: "cx-amend-order-items", inputs: { entries: "entries", isConfirmation: "isConfirmation" }, ngImport: i0__namespace, template: "<div *ngIf=\"form$ | async as form\">\n <button\n *ngIf=\"!isConfirmation\"\n class=\"btn btn-link cx-action-link\"\n (click)=\"setAll(form)\"\n >\n {{ 'orderDetails.cancellationAndReturn.setAll' | cxTranslate }}\n </button>\n\n <div class=\"d-none d-md-block cx-item-list-header\">\n <div class=\"row\">\n <div class=\"text-left col-6\">\n {{ 'orderDetails.cancellationAndReturn.item' | cxTranslate }}\n </div>\n <div class=\"text-center col-2\">\n {{ 'orderDetails.cancellationAndReturn.itemPrice' | cxTranslate }}\n </div>\n <div *ngIf=\"!isConfirmation\" class=\"text-center col-2\">\n {{ 'orderDetails.cancellationAndReturn.quantity' | cxTranslate }}\n </div>\n <div class=\"cx-item-list-qty col-2 text-right\">\n {{\n (isCancellation()\n ? 'orderDetails.cancellationAndReturn.cancelQty'\n : 'orderDetails.cancellationAndReturn.returnQty'\n ) | cxTranslate\n }}\n </div>\n <div *ngIf=\"isConfirmation\" class=\"cx-item-list-total col-2\">\n {{ 'orderDetails.cancellationAndReturn.totalPrice' | cxTranslate }}\n </div>\n </div>\n </div>\n\n <div class=\"cx-item-list-row\" *ngFor=\"let item of entries; let i = index\">\n <div class=\"row cx-item-list-items\">\n <!-- Item Image -->\n <cx-media\n class=\"col-2\"\n [container]=\"item.product.images?.PRIMARY\"\n format=\"thumbnail\"\n ></cx-media>\n\n <!-- Item Information -->\n <div class=\"cx-info col-10\">\n <div class=\"cx-info-container row\">\n <!-- Item Description -->\n <div class=\"col-md-4 col-xl-5 cx-list-item-desc\">\n <div *ngIf=\"item.product.name\" class=\"cx-name\">\n {{ item.product.name }}\n </div>\n <div *ngIf=\"item.product.code\" class=\"cx-code\">\n {{ 'cartItems.id' | cxTranslate }} {{ item.product.code }}\n </div>\n <!-- Variants -->\n <ng-container *ngIf=\"item.product.baseOptions?.length\">\n <div\n *ngFor=\"\n let variant of item.product.baseOptions[0]?.selected\n ?.variantOptionQualifiers\n \"\n class=\"cx-property\"\n >\n <div class=\"cx-label\" *ngIf=\"variant.name\">\n {{ variant.name }}:\n </div>\n <div class=\"cx-value\" *ngIf=\"variant.value\">\n {{ variant.value }}\n </div>\n </div>\n </ng-container>\n </div>\n <!-- Price -->\n <div\n *ngIf=\"item.basePrice\"\n class=\"cx-price col-md-3 col-lg-3 col-xl-2\"\n >\n <div class=\"cx-label d-block d-md-none d-lg-none d-xl-none\">\n {{ 'orderDetails.cancellationAndReturn.itemPrice' | cxTranslate }}\n </div>\n <div *ngIf=\"item.basePrice\" class=\"cx-value\">\n {{ item.basePrice?.formattedValue }}\n </div>\n </div>\n <!-- item Quantity -->\n <div *ngIf=\"!isConfirmation\" class=\"cx-request-qty col-md-3\">\n <div\n class=\"cx-label d-block d-md-none d-lg-none d-xl-none\"\n placement=\"left\"\n title=\"{{ 'cartItems.quantityTitle' | cxTranslate }}\"\n >\n {{ 'orderDetails.cancellationAndReturn.quantity' | cxTranslate }}\n </div>\n <div class=\"cx-value\">\n {{ getMaxAmendQuantity(item) }}\n </div>\n </div>\n <!-- Amended Quantity -->\n <div class=\"cx-quantity col-xs-12 col-md-2 col-sm-12\">\n <div class=\"cx-label d-block d-md-none d-lg-none d-xl-none\">\n {{\n (isCancellation()\n ? 'orderDetails.cancellationAndReturn.cancelQty'\n : 'orderDetails.cancellationAndReturn.returnQty'\n ) | cxTranslate\n }}\n </div>\n\n <div\n *ngIf=\"isConfirmation\"\n class=\"w-100 text-center cx-order-quantity-value\"\n >\n {{ getControl(form, item).value }}\n </div>\n <cx-item-counter\n *ngIf=\"!isConfirmation\"\n [min]=\"0\"\n [max]=\"getMaxAmendQuantity(item)\"\n [control]=\"getControl(form, item)\"\n >\n </cx-item-counter>\n </div>\n <!-- Total Price -->\n <div *ngIf=\"isConfirmation\" class=\"cx-total col-3\">\n <div class=\"cx-label d-block d-md-none\">\n {{\n 'orderDetails.cancellationAndReturn.totalPrice' | cxTranslate\n }}\n </div>\n <div class=\"cx-value\">\n {{ getItemPrice(item)?.formattedValue }}\n </div>\n </div>\n </div>\n </div>\n </div>\n </div>\n</div>\n", components: [{ type: i3__namespace$1.MediaComponent, selector: "cx-media", inputs: ["container", "format", "alt", "role", "loading"], outputs: ["loaded"] }, { type: i3__namespace$1.ItemCounterComponent, selector: "cx-item-counter", inputs: ["control", "min", "max", "step", "allowZero", "readonly"] }], directives: [{ type: i4__namespace.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i4__namespace.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], pipes: { "async": i4__namespace.AsyncPipe, "cxTranslate": i1__namespace.TranslatePipe }, changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: CancelOrReturnItemsComponent, decorators: [{
type: i0.Component,
args: [{
selector: 'cx-amend-order-items',
templateUrl: './amend-order-items.component.html',
changeDetection: i0.ChangeDetectionStrategy.OnPush,
}]
}], ctorParameters: function () { return [{ type: OrderAmendService }]; }, propDecorators: { entries: [{
type: i0.Input
}], isConfirmation: [{
type: i0.Input
}] } });
var AmendOrderItemsModule = /** @class */ (function () {
function AmendOrderItemsModule() {
}
return AmendOrderItemsModule;
}());
AmendOrderItemsModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: AmendOrderItemsModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
AmendOrderItemsModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: AmendOrderItemsModule, declarations: [CancelOrReturnItemsComponent], imports: [i4.CommonModule,
i5.ReactiveFormsModule,
i1.I18nModule,
i3$1.MediaModule,
i3$1.ItemCounterModule,
i1.FeaturesConfigModule,
i3$1.FormErrorsModule], exports: [CancelOrReturnItemsComponent] });
AmendOrderItemsModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: AmendOrderItemsModule, imports: [[
i4.CommonModule,
i5.ReactiveFormsModule,
i1.I18nModule,
i3$1.MediaModule,
i3$1.ItemCounterModule,
i1.FeaturesConfigModule,
i3$1.FormErrorsModule,
]] });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: AmendOrderItemsModule, decorators: [{
type: i0.NgModule,
args: [{
imports: [
i4.CommonModule,
i5.ReactiveFormsModule,
i1.I18nModule,
i3$1.MediaModule,
i3$1.ItemCounterModule,
i1.FeaturesConfigModule,
i3$1.FormErrorsModule,
],
declarations: [CancelOrReturnItemsComponent],
exports: [CancelOrReturnItemsComponent],
}]
}] });
var CancelOrderConfirmationComponent = /** @class */ (function () {
function CancelOrderConfirmationComponent(orderAmendService) {
var _this = this;
this.orderAmendService = orderAmendService;
this.form$ = this.orderAmendService
.getForm()
.pipe(operators.tap(function (form) { return (_this.orderCode = form.value.orderCode); }));
this.entries$ = this.orderAmendService.getAmendedEntries();
}
CancelOrderConfirmationComponent.prototype.submit = function (form) {
if (form.valid) {
this.orderAmendService.save();
}
else {
form.markAllAsTouched();
}
};
return CancelOrderConfirmationComponent;
}());
CancelOrderConfirmationComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: CancelOrderConfirmationComponent, deps: [{ token: OrderAmendService }], target: i0__namespace.ɵɵFactoryTarget.Component });
CancelOrderConfirmationComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.5", type: CancelOrderConfirmationComponent, selector: "cx-cancel-order-confirmation", ngImport: i0__namespace, template: "<form\n *ngIf=\"form$ | async as form\"\n [formGroup]=\"form\"\n (ngSubmit)=\"submit(form)\"\n>\n <ng-container *ngTemplateOutlet=\"actions\"></ng-container>\n\n <cx-amend-order-items\n *ngIf=\"entries$ | async as entries\"\n [entries]=\"entries\"\n [isConfirmation]=\"true\"\n >\n </cx-amend-order-items>\n\n <ng-container *ngTemplateOutlet=\"actions\"></ng-container>\n\n <ng-template #actions>\n <cx-amend-order-actions\n *ngIf=\"orderCode\"\n [orderCode]=\"orderCode\"\n [amendOrderForm]=\"form\"\n backRoute=\"orderCancel\"\n ></cx-amend-order-actions>\n </ng-template>\n</form>\n", components: [{ type: CancelOrReturnItemsComponent, selector: "cx-amend-order-items", inputs: ["entries", "isConfirmation"] }, { type: AmendOrderActionsComponent, selector: "cx-amend-order-actions", inputs: ["orderCode", "amendOrderForm", "backRoute", "forwardRoute"] }], directives: [{ type: i4__namespace.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i5__namespace.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { type: i5__namespace.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { type: i5__namespace.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { type: i4__namespace.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }], pipes: { "async": i4__namespace.AsyncPipe }, changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: CancelOrderConfirmationComponent, decorators: [{
type: i0.Component,
args: [{
selector: 'cx-cancel-order-confirmation',
templateUrl: './cancel-order-confirmation.component.html',
changeDetection: i0.ChangeDetectionStrategy.OnPush,
}]
}], ctorParameters: function () { return [{ type: OrderAmendService }]; } });
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
/** @deprecated */
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/** @deprecated */
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2)
for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar)
ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || from);
}
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n])
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try {
step(g[n](v));
}
catch (e) {
settle(q[0][3], e);
} }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
}
else {
cooked.raw = raw;
}
return cooked;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, state, kind, f) {
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
}
function __classPrivateFieldSet(receiver, state, value, kind, f) {
if (kind === "m")
throw new TypeError("Private method is not writable");
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
}
var OrderCancellationService = /** @class */ (function (_super) {
__extends(OrderCancellationService, _super);
function OrderCancellationService(orderDetailsService, userOrderService, routing, globalMessageService) {
var _this = _super.call(this, orderDetailsService) || this;
_this.orderDetailsService = orderDetailsService;
_this.userOrderService = userOrderService;
_this.routing = routing;
_this.globalMessageService = globalMessageService;
_this.amendType = exports.AmendOrderType.CANCEL;
return _this;
}
/**
* Return cancellable order entries.
*/
OrderCancellationService.prototype.getEntries = function () {
return this.getOrder().pipe(operators.filter(function (order) { return !!(order === null || order === void 0 ? void 0 : order.entries); }), operators.map(function (order) {
var _a, _b;
return (_b = (_a = order.entries) === null || _a === void 0 ? void 0 : _a.filter(function (entry) { return entry.entryNumber !== -1 &&
entry.cancellableQuantity &&
entry.cancellableQuantity > 0; })) !== null && _b !== void 0 ? _b : [];
}));
};
OrderCancellationService.prototype.save = function () {
var _this = this;
var orderCode = this.form.value.orderCode;
var entries = this.form.value.entries;
var inputs = Object.keys(entries)
.filter(function (entryNumber) { return entries[entryNumber] > 0; })
.map(function (entryNumber) { return ({
orderEntryNumber: Number(entryNumber),
quantity: entries[entryNumber],
}); });
this.form.reset();
this.userOrderService.cancelOrder(orderCode, {
cancellationRequestEntryInputs: inputs,
});
this.userOrderService
.getCancelOrderSuccess()
.pipe(operators.first(Boolean))
.subscribe(function () { return _this.afterSave(orderCode); });
};
OrderCancellationService.prototype.afterSave = function (orderCode) {
this.userOrderService.resetCancelOrderProcessState();
this.globalMessageService.add({
key: 'orderDetails.cancellationAndReturn.cancelSuccess',
params: { orderCode: orderCode },
}, i1.GlobalMessageType.MSG_TYPE_CONFIRMATION);
this.routing.go({
cxRoute: 'orders',
});
};
return OrderCancellationService;
}(OrderAmendService));
OrderCancellationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderCancellationService, deps: [{ token: OrderDetailsService }, { token: i2__namespace.OrderFacade }, { token: i1__namespace.RoutingService }, { token: i1__namespace.GlobalMessageService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
OrderCancellationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderCancellationService, providedIn: 'root' });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderCancellationService, decorators: [{
type: i0.Injectable,
args: [{
providedIn: 'root',
}]
}], ctorParameters: function () { return [{ type: OrderDetailsService }, { type: i2__namespace.OrderFacade }, { type: i1__namespace.RoutingService }, { type: i1__namespace.GlobalMessageService }]; } });
var OrderCancellationGuard = /** @class */ (function () {
function OrderCancellationGuard(orderAmendService, semanticPathService, router) {
this.orderAmendService = orderAmendService;
this.semanticPathService = semanticPathService;
this.router = router;
}
OrderCancellationGuard.prototype.canActivate = function () {
var _this = this;
return this.orderAmendService.getForm().pipe(operators.map(function (form) {
if (!form.valid) {
// the order code is not available in the route
// as long as we're inside a guard, hence we redirect
// to the common orders page.
return _this.router.parseUrl(_this.semanticPathService.get('orders'));
}
else {
return true;
}
}));
};
return OrderCancellationGuard;
}());
OrderCancellationGuard.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderCancellationGuard, deps: [{ token: OrderCancellationService }, { token: i1__namespace.SemanticPathService }, { token: i3__namespace.Router }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
OrderCancellationGuard.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderCancellationGuard, providedIn: 'root' });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: OrderCancellationGuard, decorators: [{
type: i0.Injectable,
args: [{
providedIn: 'root',
}]
}], ctorParameters: function () { return [{ type: OrderCancellationService }, { type: i1__namespace.SemanticPathService }, { type: i3__namespace.Router }]; } });
var CancelOrderConfirmationModule = /** @class */ (function () {
function CancelOrderConfirmationModule() {
}
return CancelOrderConfirmationModule;
}());
CancelOrderConfirmationModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: CancelOrderConfirmationModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
CancelOrderConfirmationModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: CancelOrderConfirmationModule, declarations: [CancelOrderConfirmationComponent], imports: [i4.CommonModule,
i5.ReactiveFormsModule,
AmendOrderItemsModule,
AmendOrderActionsModule], exports: [CancelOrderConfirmationComponent] });
CancelOrderConfirmationModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: CancelOrderConfirmationModule, providers: [
i1.provideDefaultConfig({
cmsComponents: {