|
1 |
| -/** @odoo-module **/ |
| 1 | +import options from "@web_editor/js/editor/snippets.options"; |
2 | 2 |
|
3 |
| -import publicWidget from "@web_editor/js/public/widget"; |
4 |
| - |
5 |
| -publicWidget.registry.dynamic_snippet_sale_order = publicWidget.Widget.extend({ |
6 |
| - selector: ".categories_section", |
7 |
| - |
8 |
| - xmlDependencies: ["/website_dynamic_snippet/static/src/xml/sale_order_snippet.xml"], |
9 |
| - |
10 |
| - start: function () { |
11 |
| - this.layout = this.el.dataset.layout || 'list'; |
12 |
| - this._render(); |
13 |
| - return this._super(...arguments); |
| 3 | +options.registry.DynamicSnippetOptions = options.Class.extend({ |
| 4 | + confirmOrderOnly(previewMode, widgetValue, params) { |
| 5 | + const confirmOrderOnly = widgetValue; |
| 6 | + this.$target[0].attr("data-confirm-order-only", widgetValue); |
14 | 7 | },
|
15 | 8 |
|
16 |
| - _render: function () { |
17 |
| - this._rpc({ |
18 |
| - route: '/your/data/route', |
19 |
| - params: { /* your logic */ }, |
20 |
| - }).then(data => { |
21 |
| - this.$el.find(".card_list_wrapper").html( |
22 |
| - qweb.render("website_dynamic_snippet.sale_order_snippet", { |
23 |
| - result: data.orders, |
24 |
| - layout: this.layout, |
25 |
| - }) |
26 |
| - ); |
27 |
| - }); |
| 9 | + setLayout(previewMode, widgetValue, params) { |
| 10 | + const snippetList = this.$target[0].querySelector(".list_sale_order"); |
| 11 | + const snippetCard = this.$target[0].querySelector(".card_sale_order"); |
| 12 | + if (widgetValue && widgetValue === "list") { |
| 13 | + snippetList.classList.remove("d-none"); |
| 14 | + snippetCard.classList.add("d-none"); |
| 15 | + } else if (widgetValue && widgetValue === "grid") { |
| 16 | + snippetList.classList.add("d-none"); |
| 17 | + snippetCard.classList.remove("d-none"); |
| 18 | + } else { |
| 19 | + snippetList.classList.remove("d-none"); |
| 20 | + snippetCard.classList.add("d-none"); |
| 21 | + } |
28 | 22 | },
|
29 | 23 |
|
30 |
| - onChangeOption(previewMode, widgetValue, params) { |
31 |
| - if (['grid', 'list'].includes(widgetValue)) { |
32 |
| - this.layout = widgetValue; |
33 |
| - this._render(); |
| 24 | + //-------------------------------------------------------------------------- |
| 25 | + // Private |
| 26 | + //-------------------------------------------------------------------------- |
| 27 | + |
| 28 | + /** |
| 29 | + * @override |
| 30 | + */ |
| 31 | + _computeWidgetState(methodName, widgetName, params, widgetValue) { |
| 32 | + if (methodName === "confirmOrderOnly") { |
| 33 | + return this.$target[0].dataset.isConfirmOrder === 'true' || this.$target[0].dataset.isConfirmOrder === true; |
34 | 34 | }
|
| 35 | + if (methodName === "setLayout") { |
| 36 | + return this.$target[0].querySelector(".list_sale_order").classList.contains('d-none') ? "grid" : "list"; |
| 37 | + } |
| 38 | + return this._super(...arguments); |
35 | 39 | },
|
36 | 40 | });
|
0 commit comments