| 1 | import { Interaction } from "@web/public/interaction"; |
| 2 | import { registry } from "@web/core/registry"; |
| 3 | |
| 4 | export class CouponToaster extends Interaction { |
| 5 | static selector = ".coupon-message"; |
| 6 | |
| 7 | start() { |
| 8 | let options = {}; |
| 9 | const titleEl = this.el.querySelector(".coupon-message-title"); |
| 10 | const contentEl = this.el.querySelector(".coupon-message-content"); |
| 11 | let message = null; |
| 12 | |
| 13 | if (contentEl) { |
| 14 | message = contentEl.innerHTML; |
| 15 | if (titleEl) { |
| 16 | Object.assign(options, { title: titleEl.innerHTML }); |
| 17 | } |
| 18 | } else if (titleEl) { |
| 19 | message = titleEl.innerHTML; |
| 20 | } |
| 21 | |
| 22 | if (this.el.classList.contains("coupon-info-message")) { |
| 23 | this.services.notification.add(message, Object.assign({ type: "success" }, options)); |
| 24 | } else if (this.el.classList.contains("coupon-error-message")) { |
| 25 | this.services.notification.add(message, Object.assign({ type: "danger" }, options)); |
| 26 | } else if (this.el.classList.contains("coupon-warning-message")) { |
| 27 | this.services.notification.add(message, Object.assign({ type: "warning" }, options)); |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | registry |
| 33 | .category("public.interactions") |
| 34 | .add("website_sale_loyalty.coupon_toaster", CouponToaster); |