|
| 1 | +/** @odoo-module **/ |
| 2 | + |
| 3 | +import { registry } from "@web/core/registry"; |
| 4 | +import { ProductCatalogKanbanRecord } from "@product/product_catalog/kanban_record"; |
| 5 | +import { productCatalogKanbanView } from "@product/product_catalog/kanban_view"; |
| 6 | +import { ProductCatalogKanbanRenderer } from "@product/product_catalog/kanban_renderer"; |
| 7 | +import { useFileViewer } from "@web/core/file_viewer/file_viewer_hook"; |
| 8 | + |
| 9 | +export class InheritProductMobileCatalog extends ProductCatalogKanbanRecord { |
| 10 | + setup() { |
| 11 | + super.setup() |
| 12 | + this.fileViewer = useFileViewer(); |
| 13 | + } |
| 14 | + |
| 15 | + onGlobalClick(e) { |
| 16 | + const imageContainer = e.target.closest('.o_product_image'); |
| 17 | + if(imageContainer){ |
| 18 | + const imageUrl = e.target.getAttribute("src"); |
| 19 | + console.log(imageUrl); |
| 20 | + |
| 21 | + if(imageUrl){ |
| 22 | + this.openImagePreview(imageUrl); |
| 23 | + return; |
| 24 | + } |
| 25 | + } |
| 26 | + super.onGlobalClick(e); |
| 27 | + } |
| 28 | + |
| 29 | + openImagePreview(imageUrl) { |
| 30 | + const fileModel = { |
| 31 | + isImage: true, |
| 32 | + isViewable: true, |
| 33 | + displayName: imageUrl, |
| 34 | + defaultSource: imageUrl, |
| 35 | + downloadUrl: imageUrl, |
| 36 | + } |
| 37 | + this.fileViewer.open(fileModel); |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +//Adding InheritProductMobileCatalog component to the Kanban renderer for the Kanban view |
| 42 | +export class InheritProductMobileCatalogRenderer extends ProductCatalogKanbanRenderer { |
| 43 | + static components = { |
| 44 | + ...ProductCatalogKanbanRenderer.components, |
| 45 | + KanbanRecord: InheritProductMobileCatalog, |
| 46 | + }; |
| 47 | +} |
| 48 | + |
| 49 | +export const ProductMobileKanbanCatalogView = { |
| 50 | + ...productCatalogKanbanView, |
| 51 | + Renderer: InheritProductMobileCatalogRenderer, |
| 52 | +}; |
| 53 | + |
| 54 | +registry.category("views").add("product_mobile_kanban_catalog", ProductMobileKanbanCatalogView); |
0 commit comments