From cbc8676dd000fa21cc51684dfd35a28bc6813137 Mon Sep 17 00:00:00 2001 From: "Michael (mcm)" Date: Mon, 25 Jul 2022 10:08:25 +0000 Subject: [PATCH] [IMP] event: convert field IconSelector This commit rewrites IconSelectorField using the new framework. closes odoo/odoo#96782 Signed-off-by: Aaron Bohy (aab) --- addons/event/__manifest__.py | 4 +-- .../icon_selection_field.js | 30 +++++++++++++++++++ .../icon_selection_field.xml | 8 +++++ .../static/src/js/field_icon_selection.js | 29 ------------------ .../static/src/xml/field_icon_selection.xml | 6 ---- addons/event/views/event_event_views.xml | 2 +- addons/event/views/event_mail_views.xml | 2 +- 7 files changed, 42 insertions(+), 39 deletions(-) create mode 100644 addons/event/static/src/icon_selection_field/icon_selection_field.js create mode 100644 addons/event/static/src/icon_selection_field/icon_selection_field.xml delete mode 100644 addons/event/static/src/js/field_icon_selection.js delete mode 100644 addons/event/static/src/xml/field_icon_selection.xml diff --git a/addons/event/__manifest__.py b/addons/event/__manifest__.py index db8c29a6b3e..f33b5a6f7bd 100644 --- a/addons/event/__manifest__.py +++ b/addons/event/__manifest__.py @@ -49,13 +49,13 @@ Key Features 'assets': { 'web.assets_backend': [ 'event/static/src/scss/event.scss', - 'event/static/src/js/field_icon_selection.js', + 'event/static/src/icon_selection_field/icon_selection_field.js', ], 'web.assets_common': [ 'event/static/src/js/tours/**/*', ], 'web.assets_qweb': [ - 'event/static/src/xml/**/*', + 'event/static/src/**/*', ], 'web.report_assets_common': [ '/event/static/src/scss/event_foldable_badge_report.scss', diff --git a/addons/event/static/src/icon_selection_field/icon_selection_field.js b/addons/event/static/src/icon_selection_field/icon_selection_field.js new file mode 100644 index 00000000000..ebb9daca39d --- /dev/null +++ b/addons/event/static/src/icon_selection_field/icon_selection_field.js @@ -0,0 +1,30 @@ +/** @odoo-module **/ + +import { registry } from "@web/core/registry"; +import { _lt } from "@web/core/l10n/translation"; +import { standardFieldProps } from "@web/views/fields/standard_field_props"; + +const { Component } = owl; + +export class IconSelectionField extends Component { + get icon() { + return this.props.icons[this.props.value]; + } + get title() { + return this.props.value.charAt(0).toUpperCase() + this.props.value.slice(1); + } +} +IconSelectionField.template = "event.IconSelectionField"; +IconSelectionField.props = { + ...standardFieldProps, + icons: Object, +}; + +IconSelectionField.displayName = _lt("Icon Selection"); +IconSelectionField.supportedTypes = ["char", "text", "selection"]; + +IconSelectionField.extractProps = ({ attrs }) => ({ + icons: attrs.options, +}); + +registry.category("fields").add("event_icon_selection", IconSelectionField); diff --git a/addons/event/static/src/icon_selection_field/icon_selection_field.xml b/addons/event/static/src/icon_selection_field/icon_selection_field.xml new file mode 100644 index 00000000000..70db8d9ed4e --- /dev/null +++ b/addons/event/static/src/icon_selection_field/icon_selection_field.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/addons/event/static/src/js/field_icon_selection.js b/addons/event/static/src/js/field_icon_selection.js deleted file mode 100644 index 95740ea62d9..00000000000 --- a/addons/event/static/src/js/field_icon_selection.js +++ /dev/null @@ -1,29 +0,0 @@ -odoo.define('event.field_icon_selection', function (require) { -"use strict"; - -var core = require('web.core'); -var registry = require('web.field_registry'); -var AbstractField = require('web.AbstractField'); -var QWeb = core.qweb; - -var IconSelection = AbstractField.extend({ - supportedFieldTypes: ['char', 'text', 'selection'], - - /** - * @override - * @private - */ - _render: function () { - this._super.apply(this, arguments); - this.icon = this.nodeOptions[this.value]; - this.title = this.value.charAt(0).toUpperCase() + this.value.slice(1); - this.$el.empty().append(QWeb.render('event.IconSelection', {'widget': this})); - }, - -}); - -registry.add('icon_selection', IconSelection); - -return IconSelection; - -}); diff --git a/addons/event/static/src/xml/field_icon_selection.xml b/addons/event/static/src/xml/field_icon_selection.xml deleted file mode 100644 index 399be360311..00000000000 --- a/addons/event/static/src/xml/field_icon_selection.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/addons/event/views/event_event_views.xml b/addons/event/views/event_event_views.xml index 2c20ebd6fb5..3921777814e 100644 --- a/addons/event/views/event_event_views.xml +++ b/addons/event/views/event_event_views.xml @@ -84,7 +84,7 @@ - diff --git a/addons/event/views/event_mail_views.xml b/addons/event/views/event_mail_views.xml index babcf0672a7..cf6a1907eba 100644 --- a/addons/event/views/event_mail_views.xml +++ b/addons/event/views/event_mail_views.xml @@ -53,7 +53,7 @@ -