UNPKG

@spartacus/cart

Version:

`@spartacus/cart` is a package that you can include in your application, which allows you to use various cart features.

811 lines (802 loc) 79.5 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms'), require('@spartacus/core'), require('rxjs'), require('rxjs/operators'), require('@spartacus/storefront'), require('@angular/common'), require('@angular/router'), require('@spartacus/cart/quick-order/root'), require('@spartacus/cart/quick-order/core')) : typeof define === 'function' && define.amd ? define('@spartacus/cart/quick-order/components', ['exports', '@angular/core', '@angular/forms', '@spartacus/core', 'rxjs', 'rxjs/operators', '@spartacus/storefront', '@angular/common', '@angular/router', '@spartacus/cart/quick-order/root', '@spartacus/cart/quick-order/core'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.spartacus = global.spartacus || {}, global.spartacus.cart = global.spartacus.cart || {}, global.spartacus.cart['quick-order'] = global.spartacus.cart['quick-order'] || {}, global.spartacus.cart['quick-order'].components = {}), global.ng.core, global.ng.forms, global.core, global.rxjs, global.rxjs.operators, global.storefront, global.ng.common, global.ng.router, global.spartacus.cart['quick-order'].root, global.spartacus.cart['quick-order'].core)); }(this, (function (exports, i0, i2, i1, rxjs, operators, i2$1, i7, i3, i2$2, i4) { '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 i2__namespace = /*#__PURE__*/_interopNamespace(i2); var i1__namespace = /*#__PURE__*/_interopNamespace(i1); var i2__namespace$1 = /*#__PURE__*/_interopNamespace(i2$1); var i7__namespace = /*#__PURE__*/_interopNamespace(i7); var i3__namespace = /*#__PURE__*/_interopNamespace(i3); var i2__namespace$2 = /*#__PURE__*/_interopNamespace(i2$2); var i4__namespace = /*#__PURE__*/_interopNamespace(i4); var CartQuickOrderFormComponent = /** @class */ (function () { function CartQuickOrderFormComponent(activeCartService, eventService, formBuilder, globalMessageService) { this.activeCartService = activeCartService; this.eventService = eventService; this.formBuilder = formBuilder; this.globalMessageService = globalMessageService; this.cartIsLoading$ = this.activeCartService .isStable() .pipe(operators.map(function (loaded) { return !loaded; })); this.cart$ = this.activeCartService.getActive(); this.min = 1; this.subscription = new rxjs.Subscription(); this.cartEventsSubscription = new rxjs.Subscription(); this.minQuantityValue = 1; } CartQuickOrderFormComponent.prototype.ngOnInit = function () { this.buildForm(); this.watchQuantityChange(); }; CartQuickOrderFormComponent.prototype.ngOnDestroy = function () { var _a, _b; (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe(); (_b = this.cartEventsSubscription) === null || _b === void 0 ? void 0 : _b.unsubscribe(); }; CartQuickOrderFormComponent.prototype.applyQuickOrder = function () { var _a, _b; if (this.quickOrderForm.invalid) { this.quickOrderForm.markAllAsTouched(); return; } var productCode = (_a = this.quickOrderForm.get('productCode')) === null || _a === void 0 ? void 0 : _a.value; var quantity = (_b = this.quickOrderForm.get('quantity')) === null || _b === void 0 ? void 0 : _b.value; this.watchAddEntrySuccessEvent(); this.watchAddEntryFailEvent(); if (productCode && quantity) { this.activeCartService.addEntry(productCode, quantity); } }; CartQuickOrderFormComponent.prototype.buildForm = function () { this.quickOrderForm = this.formBuilder.group({ productCode: ['', [i2.Validators.required]], quantity: [ this.minQuantityValue, { updateOn: 'blur', validators: [i2.Validators.required] }, ], }); }; CartQuickOrderFormComponent.prototype.watchQuantityChange = function () { var _this = this; var _a; this.subscription.add((_a = this.quickOrderForm .get('quantity')) === null || _a === void 0 ? void 0 : _a.valueChanges.subscribe(function (value) { var _a; return (_a = _this.quickOrderForm .get('quantity')) === null || _a === void 0 ? void 0 : _a.setValue(_this.getValidCount(value), { emitEvent: false }); })); }; CartQuickOrderFormComponent.prototype.watchAddEntrySuccessEvent = function () { var _this = this; this.cartEventsSubscription.add(this.eventService .get(i1.CartAddEntrySuccessEvent) .pipe(operators.first()) .subscribe(function (data) { var _a, _b; var key = 'quickOrderCartForm.stockLevelReached'; var productTranslation; var messageType = i1.GlobalMessageType.MSG_TYPE_WARNING; if (data.quantityAdded) { key = data.quantityAdded > 1 ? 'quickOrderCartForm.entriesWereAdded' : 'quickOrderCartForm.entryWasAdded'; productTranslation = data.quantityAdded > 1 ? 'quickOrderCartForm.products' : 'quickOrderCartForm.product'; messageType = i1.GlobalMessageType.MSG_TYPE_CONFIRMATION; } _this.globalMessageService.add({ key: key, params: { product: ((_b = (_a = data === null || data === void 0 ? void 0 : data.entry) === null || _a === void 0 ? void 0 : _a.product) === null || _b === void 0 ? void 0 : _b.name) || productTranslation, quantity: data.quantityAdded, }, }, messageType); _this.resetForm(); })); }; CartQuickOrderFormComponent.prototype.watchAddEntryFailEvent = function () { var _this = this; this.cartEventsSubscription.add(this.eventService .get(i1.CartAddEntryFailEvent) .pipe(operators.first()) .subscribe(function () { _this.globalMessageService.add({ key: 'quickOrderCartForm.noResults', }, i1.GlobalMessageType.MSG_TYPE_ERROR); })); }; CartQuickOrderFormComponent.prototype.getValidCount = function (value) { if (value < this.min || !value) { value = this.min; } return value; }; CartQuickOrderFormComponent.prototype.resetForm = function () { this.quickOrderForm.reset(); }; return CartQuickOrderFormComponent; }()); CartQuickOrderFormComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: CartQuickOrderFormComponent, deps: [{ token: i1__namespace.ActiveCartService }, { token: i1__namespace.EventService }, { token: i2__namespace.FormBuilder }, { token: i1__namespace.GlobalMessageService }], target: i0__namespace.ɵɵFactoryTarget.Component }); CartQuickOrderFormComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.5", type: CartQuickOrderFormComponent, selector: "cx-cart-quick-order-form", ngImport: i0__namespace, template: "<ng-container *ngIf=\"cart$ | async as cart\">\n <div class=\"cx-cart-quick-order-form-title\">\n {{ 'quickOrderCartForm.title' | cxTranslate }}\n </div>\n <div class=\"form-group\">\n <form (ngSubmit)=\"applyQuickOrder()\" [formGroup]=\"quickOrderForm\">\n <div class=\"cx-cart-quick-order-form-container\">\n <span class=\"cx-cart-quick-order-form-productID\">\n <label class=\"cx-cart-quick-order-form-label\">\n {{ 'quickOrderCartForm.productCodeLabel' | cxTranslate }}\n </label>\n <input\n aria-required=\"true\"\n class=\"form-control input-product-code\"\n formControlName=\"productCode\"\n placeholder=\"{{\n 'quickOrderCartForm.productCodePlaceholder' | cxTranslate\n }}\"\n type=\"text\"\n />\n </span>\n\n <span class=\"cx-cart-quick-order-form-qty\">\n <label class=\"cx-cart-quick-order-form-label\">\n {{ 'quickOrderCartForm.quantityLabel' | cxTranslate }}\n </label>\n <input\n aria-required=\"true\"\n class=\"form-control input-quantity\"\n formControlName=\"quantity\"\n type=\"number\"\n />\n </span>\n <button\n [class.disabled]=\"cartIsLoading$ | async\"\n [disabled]=\"cartIsLoading$ | async\"\n class=\"btn btn-block btn-action apply-quick-order-button\"\n type=\"submit\"\n >\n {{ 'quickOrderCartForm.addToCart' | cxTranslate }}\n </button>\n <cx-form-errors\n aria-live=\"assertive\"\n aria-atomic=\"true\"\n [control]=\"quickOrderForm.get('productCode')\"\n ></cx-form-errors>\n <cx-form-errors\n aria-live=\"assertive\"\n aria-atomic=\"true\"\n [control]=\"quickOrderForm.get('quantity')\"\n ></cx-form-errors>\n </div>\n </form></div\n></ng-container>\n", components: [{ type: i2__namespace$1.FormErrorsComponent, selector: "cx-form-errors", inputs: ["prefix", "translationParams", "control"] }], directives: [{ type: i7__namespace.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2__namespace.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { type: i2__namespace.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { type: i2__namespace.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { type: i2__namespace.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { type: i2__namespace.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i2__namespace.FormControlName, selector: "[formControlName]", inputs: ["disabled", "formControlName", "ngModel"], outputs: ["ngModelChange"] }, { type: i2__namespace.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }], pipes: { "async": i7__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: CartQuickOrderFormComponent, decorators: [{ type: i0.Component, args: [{ selector: 'cx-cart-quick-order-form', templateUrl: './cart-quick-order-form.component.html', changeDetection: i0.ChangeDetectionStrategy.OnPush, }] }], ctorParameters: function () { return [{ type: i1__namespace.ActiveCartService }, { type: i1__namespace.EventService }, { type: i2__namespace.FormBuilder }, { type: i1__namespace.GlobalMessageService }]; } }); var CartQuickOrderFormModule = /** @class */ (function () { function CartQuickOrderFormModule() { } return CartQuickOrderFormModule; }()); CartQuickOrderFormModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: CartQuickOrderFormModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule }); CartQuickOrderFormModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: CartQuickOrderFormModule, declarations: [CartQuickOrderFormComponent], imports: [i7.CommonModule, i2.ReactiveFormsModule, i1.I18nModule, i2$1.FormErrorsModule], exports: [CartQuickOrderFormComponent] }); CartQuickOrderFormModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: CartQuickOrderFormModule, providers: [ i1.provideDefaultConfig({ cmsComponents: { CartQuickOrderFormComponent: { component: CartQuickOrderFormComponent, }, }, }), ], imports: [[i7.CommonModule, i2.ReactiveFormsModule, i1.I18nModule, i2$1.FormErrorsModule]] }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: CartQuickOrderFormModule, decorators: [{ type: i0.NgModule, args: [{ imports: [i7.CommonModule, i2.ReactiveFormsModule, i1.I18nModule, i2$1.FormErrorsModule], providers: [ i1.provideDefaultConfig({ cmsComponents: { CartQuickOrderFormComponent: { component: CartQuickOrderFormComponent, }, }, }), ], declarations: [CartQuickOrderFormComponent], exports: [CartQuickOrderFormComponent], }] }] }); /*! ***************************************************************************** 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 QuickOrderFormComponent = /** @class */ (function () { function QuickOrderFormComponent(globalMessageService, // TODO(#14058): Remove it as it is not in use anymore quickOrderService, config, // TODO(#14058): Make it required cd, // TODO(#14058): Make it required winRef // TODO(#14058): Make it required ) { this.globalMessageService = globalMessageService; this.quickOrderService = quickOrderService; this.config = config; this.cd = cd; this.winRef = winRef; this.iconTypes = i2$1.ICON_TYPE; this.isSearching = false; this.noResults = false; this.results = []; this.subscription = new rxjs.Subscription(); this.searchSubscription = new rxjs.Subscription(); } QuickOrderFormComponent.prototype.ngOnInit = function () { this.buildForm(); this.subscription.add(this.watchProductAdd()); this.subscription.add(this.watchQueryChange()); }; QuickOrderFormComponent.prototype.onBlur = function (event) { var _this = this; // Use timeout to detect changes setTimeout(function () { if (!_this.isSuggestionFocused()) { _this.blurSuggestionBox(event); } }); }; QuickOrderFormComponent.prototype.clear = function (event) { var _a, _b; event === null || event === void 0 ? void 0 : event.preventDefault(); if (this.isResultsBoxOpen()) { this.toggleBodyClass('quick-order-searchbox-is-active', false); } var product = (_a = this.form.get('product')) === null || _a === void 0 ? void 0 : _a.value; if (!!product) { this.form.reset(); } // We have to call 'close' method every time to make sure results list is empty and call detectChanges to change icon type in form this.close(); (_b = this.cd) === null || _b === void 0 ? void 0 : _b.detectChanges(); }; QuickOrderFormComponent.prototype.add = function (product, event) { event === null || event === void 0 ? void 0 : event.preventDefault(); // TODO change to nonpurchasable flag once we will support multidimensional products in search and when the purchasable flag will be available in search product response // Check if product is purchasable / non multidimensional if (product.multidimensional) { this.quickOrderService.setNonPurchasableProductError(product); this.clear(); return; } else { this.quickOrderService.clearNonPurchasableProductError(); } this.quickOrderService.addProduct(product); }; QuickOrderFormComponent.prototype.addProduct = function (event) { var _this = this; this.quickOrderService .canAdd() .pipe(operators.take(1)) .subscribe(function (canAdd) { if (canAdd) { // Add product if there is only one in the result list if (_this.results.length === 1) { _this.add(_this.results[0], event); // Add product if there is focus on it } else if (_this.getFocusedIndex() !== -1) { var product = _this.results[_this.getFocusedIndex()]; _this.add(product, event); } } }); }; QuickOrderFormComponent.prototype.focusNextChild = function (event) { event.preventDefault(); // Negate normal keyscroll if (!this.results.length) { return; } var _e = __read([ this.getResultElements(), this.getFocusedIndex(), ], 2), results = _e[0], focusedIndex = _e[1]; // Focus on first index moving to last if (results.length) { if (focusedIndex >= results.length - 1) { results[0].focus(); } else { results[focusedIndex + 1].focus(); } } }; QuickOrderFormComponent.prototype.focusPreviousChild = function (event) { event.preventDefault(); // Negate normal keyscroll if (!this.results.length) { return; } var _e = __read([ this.getResultElements(), this.getFocusedIndex(), ], 2), results = _e[0], focusedIndex = _e[1]; // Focus on last index moving to first if (results.length) { if (focusedIndex < 1) { results[results.length - 1].focus(); } else { results[focusedIndex - 1].focus(); } } }; QuickOrderFormComponent.prototype.isResultsBoxOpen = function () { return this.winRef ? !!this.winRef.document.querySelector('.quick-order-searchbox-is-active') : false; }; QuickOrderFormComponent.prototype.canAddProduct = function () { return this.quickOrderService.canAdd(); }; QuickOrderFormComponent.prototype.open = function () { this.toggleBodyClass('quick-order-searchbox-is-active', true); }; // Return result list as HTMLElement array QuickOrderFormComponent.prototype.getResultElements = function () { if (this.winRef) { return Array.from(this.winRef.document.querySelectorAll('.quick-order-results-products > li button')); } else { return []; } }; QuickOrderFormComponent.prototype.blurSuggestionBox = function (event) { this.toggleBodyClass('quick-order-searchbox-is-active', false); if (event && event.target) { event.target.blur(); } }; // Return focused element as HTMLElement QuickOrderFormComponent.prototype.getFocusedElement = function () { if (this.winRef) { return this.winRef.document.activeElement; } }; QuickOrderFormComponent.prototype.getFocusedIndex = function () { return this.getResultElements().indexOf(this.getFocusedElement()); }; QuickOrderFormComponent.prototype.isSuggestionFocused = function () { return this.getResultElements().includes(this.getFocusedElement()); }; QuickOrderFormComponent.prototype.toggleBodyClass = function (className, add) { // TODO(#14058): Remove condition if (this.winRef) { if (add === undefined) { this.winRef.document.body.classList.toggle(className); } else { add ? this.winRef.document.body.classList.add(className) : this.winRef.document.body.classList.remove(className); } } }; QuickOrderFormComponent.prototype.buildForm = function () { var form = new i2.FormGroup({}); form.setControl('product', new i2.FormControl(null)); this.form = form; }; QuickOrderFormComponent.prototype.isEmpty = function (string) { return (string === null || string === void 0 ? void 0 : string.trim()) === '' || string == null; }; QuickOrderFormComponent.prototype.watchQueryChange = function () { var _this = this; return this.form.valueChanges .pipe(operators.distinctUntilChanged(), operators.debounceTime(300), operators.filter(function (value) { var _a, _b, _c, _d; if ((_b = (_a = _this.config) === null || _a === void 0 ? void 0 : _a.quickOrder) === null || _b === void 0 ? void 0 : _b.searchForm) { //Check if input to quick order is an empty after deleting input manually if (_this.isEmpty(value.product)) { //Clear recommendation results on empty string _this.clear(); return false; } return (!!value.product && value.product.length >= ((_d = (_c = _this.config.quickOrder) === null || _c === void 0 ? void 0 : _c.searchForm) === null || _d === void 0 ? void 0 : _d.minCharactersBeforeRequest)); } return value; })) .subscribe(function (value) { _this.searchProducts(value.product); }); }; QuickOrderFormComponent.prototype.searchProducts = function (query) { var _this = this; this.searchSubscription.add(this.canAddProduct() .pipe(operators.filter(Boolean), operators.switchMap(function () { var _a, _b, _c; return _this.quickOrderService .searchProducts(query, (_c = (_b = (_a = _this.config) === null || _a === void 0 ? void 0 : _a.quickOrder) === null || _b === void 0 ? void 0 : _b.searchForm) === null || _c === void 0 ? void 0 : _c.maxProducts) .pipe(operators.take(1)); })) .subscribe(function (products) { var _a; _this.results = products; if (_this.results.length) { _this.noResults = false; _this.open(); } else { _this.noResults = true; } (_a = _this.cd) === null || _a === void 0 ? void 0 : _a.detectChanges(); })); }; QuickOrderFormComponent.prototype.clearResults = function () { this.results = []; }; QuickOrderFormComponent.prototype.close = function () { this.resetSearchSubscription(); this.clearResults(); this.noResults = false; }; QuickOrderFormComponent.prototype.resetSearchSubscription = function () { this.searchSubscription.unsubscribe(); this.searchSubscription = new rxjs.Subscription(); }; QuickOrderFormComponent.prototype.watchProductAdd = function () { var _this = this; return this.quickOrderService .getProductAdded() .subscribe(function () { return _this.clear(); }); }; QuickOrderFormComponent.prototype.ngOnDestroy = function () { this.subscription.unsubscribe(); }; return QuickOrderFormComponent; }()); QuickOrderFormComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: QuickOrderFormComponent, deps: [{ token: i1__namespace.GlobalMessageService }, { token: i2__namespace$2.QuickOrderFacade }, { token: i1__namespace.Config }, { token: i0__namespace.ChangeDetectorRef }, { token: i1__namespace.WindowRef }], target: i0__namespace.ɵɵFactoryTarget.Component }); QuickOrderFormComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.5", type: QuickOrderFormComponent, selector: "cx-quick-order-form", ngImport: i0__namespace, template: "<form [formGroup]=\"form\" class=\"quick-order-form-container\">\n <div class=\"quick-order-form-input\">\n <input\n (blur)=\"onBlur($event)\"\n (focus)=\"open()\"\n (keydown.arrowdown)=\"focusNextChild($event)\"\n (keydown.arrowup)=\"focusPreviousChild($event)\"\n (keydown.enter)=\"addProduct($event)\"\n (keydown.escape)=\"clear($event)\"\n [attr.aria-label]=\"'common.search' | cxTranslate\"\n class=\"form-control\"\n formControlName=\"product\"\n placeholder=\"{{ 'quickOrderForm.placeholder' | cxTranslate }}\"\n type=\"text\"\n />\n\n <button\n *ngIf=\"form.get('product')?.value; else searchIcon\"\n (click)=\"clear($event)\"\n (keydown.enter)=\"clear($event)\"\n [attr.aria-label]=\"'common.reset' | cxTranslate\"\n class=\"quick-order-form-reset-icon\"\n >\n <cx-icon [type]=\"iconTypes.RESET\"></cx-icon>\n </button>\n\n <ng-template #searchIcon>\n <button\n [attr.aria-label]=\"'common.search' | cxTranslate\"\n class=\"quick-order-form-search-icon\"\n tabindex=\"-1\"\n >\n <cx-icon [type]=\"iconTypes.SEARCH\"></cx-icon>\n </button>\n </ng-template>\n\n <span\n *ngIf=\"!(canAddProduct() | async) && form.get('product')?.dirty\"\n class=\"list-limit-reached-text\"\n >\n {{ 'quickOrderForm.listLimitReached' | cxTranslate }}\n </span>\n </div>\n\n <div *ngIf=\"isResultsBoxOpen()\" role=\"listbox\" class=\"quick-order-results\">\n <ul *ngIf=\"results.length\" class=\"quick-order-results-products\">\n <li\n *ngFor=\"let product of results; let i = index\"\n class=\"quick-order-results-product-container\"\n >\n <button\n (blur)=\"onBlur($event)\"\n (click)=\"add(product, $event)\"\n (keydown.arrowdown)=\"focusNextChild($event)\"\n (keydown.arrowup)=\"focusPreviousChild($event)\"\n (keydown.enter)=\"add(product, $event)\"\n (keydown.escape)=\"clear($event)\"\n [attr.aria-label]=\"\n 'quickOrderForm.addProduct' | cxTranslate: { product: product.name }\n \"\n [class.has-media]=\"\n config?.quickOrder?.searchForm?.displayProductImages\n \"\n class=\"quick-order-results-product\"\n >\n <cx-media\n *ngIf=\"config?.quickOrder?.searchForm?.displayProductImages\"\n [container]=\"product.images?.PRIMARY\"\n class=\"media\"\n format=\"thumbnail\"\n role=\"presentation\"\n ></cx-media>\n <div class=\"name\" [innerHTML]=\"product.name\"></div>\n <span class=\"id\">\n {{\n 'quickOrderForm.id'\n | cxTranslate\n : {\n id: product.code\n }\n }}\n </span>\n <span class=\"price\">{{ product.price?.formattedValue }}</span>\n </button>\n </li>\n </ul>\n\n <span *ngIf=\"noResults\" class=\"quick-order-no-results\">\n {{ 'quickOrderForm.noResults' | cxTranslate }}\n </span>\n </div>\n</form>\n", components: [{ type: i2__namespace$1.IconComponent, selector: "cx-icon,[cxIcon]", inputs: ["cxIcon", "type"] }, { type: i2__namespace$1.MediaComponent, selector: "cx-media", inputs: ["container", "format", "alt", "role", "loading"], outputs: ["loaded"] }], directives: [{ type: i2__namespace.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { type: i2__namespace.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { type: i2__namespace.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { type: i2__namespace.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { type: i2__namespace.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i2__namespace.FormControlName, selector: "[formControlName]", inputs: ["disabled", "formControlName", "ngModel"], outputs: ["ngModelChange"] }, { type: i7__namespace.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i7__namespace.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], pipes: { "cxTranslate": i1__namespace.TranslatePipe, "async": i7__namespace.AsyncPipe }, changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: QuickOrderFormComponent, decorators: [{ type: i0.Component, args: [{ selector: 'cx-quick-order-form', templateUrl: './quick-order-form.component.html', changeDetection: i0.ChangeDetectionStrategy.OnPush, }] }], ctorParameters: function () { return [{ type: i1__namespace.GlobalMessageService }, { type: i2__namespace$2.QuickOrderFacade }, { type: i1__namespace.Config }, { type: i0__namespace.ChangeDetectorRef }, { type: i1__namespace.WindowRef }]; } }); var QuickOrderItemComponent = /** @class */ (function () { function QuickOrderItemComponent(cd, quickOrderService) { this.cd = cd; this.quickOrderService = quickOrderService; this.loading = false; this.subscription = new rxjs.Subscription(); } Object.defineProperty(QuickOrderItemComponent.prototype, "entry", { get: function () { return this._entry; }, set: function (value) { this._entry = value; this.quantityControl = new i2.FormControl(this.entry.quantity, { updateOn: 'blur', }); }, enumerable: false, configurable: true }); QuickOrderItemComponent.prototype.ngOnInit = function () { var _this = this; this.subscription.add(this.quantityControl.valueChanges.subscribe(function () { _this.quickOrderService.updateEntryQuantity(_this.index, _this.quantityControl.value); })); this.subscription.add(this.watchProductAdd()); }; QuickOrderItemComponent.prototype.removeEntry = function () { this.quickOrderService.softDeleteEntry(this.index); this.cd.detectChanges(); }; QuickOrderItemComponent.prototype.watchProductAdd = function () { var _this = this; return this.quickOrderService.getProductAdded().subscribe(function (productCode) { var _a; if (productCode === ((_a = _this.entry.product) === null || _a === void 0 ? void 0 : _a.code)) { _this.quantityControl = new i2.FormControl(_this.entry.quantity); _this.cd.detectChanges(); } }); }; QuickOrderItemComponent.prototype.ngOnDestroy = function () { var _a; (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe(); }; return QuickOrderItemComponent; }()); QuickOrderItemComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: QuickOrderItemComponent, deps: [{ token: i0__namespace.ChangeDetectorRef }, { token: i2__namespace$2.QuickOrderFacade }], target: i0__namespace.ɵɵFactoryTarget.Component }); QuickOrderItemComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.5", type: QuickOrderItemComponent, selector: "cx-quick-order-item", inputs: { entry: "entry", index: "index", loading: "loading" }, ngImport: i0__namespace, template: "<div class=\"cx-quick-order-table-item\">\n <div class=\"row\">\n <div class=\"col-2 col-md-1 cx-quick-order-image-container\">\n <div class=\"cx-quick-order-table-item-product-image\">\n <a\n [ngClass]=\"{ disabled: loading }\"\n [routerLink]=\"{ cxRoute: 'product', params: entry.product } | cxUrl\"\n tabindex=\"-1\"\n >\n <cx-media\n [container]=\"entry?.product?.images?.PRIMARY\"\n format=\"cartIcon\"\n ></cx-media>\n </a>\n </div>\n </div>\n\n <div class=\"col-10 col-md-11 cx-quick-order-info-container\">\n <div class=\"row\">\n <div\n class=\"\n cx-quick-order-table-item-product-information\n col-md-4 col-lg-4 col-xl-4\n \"\n >\n <div class=\"cx-name\">\n <a\n [ngClass]=\"{ disabled: loading }\"\n [routerLink]=\"\n { cxRoute: 'product', params: entry.product } | cxUrl\n