From 7a357dd55d34fcf8a927b8a78c0a097af21f148e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nedas=20=C5=BDilinskas?= Date: Mon, 27 May 2024 20:16:28 +0300 Subject: [PATCH] [MIG] web_widget_url_advanced: Migration to 17.0 --- web_widget_url_advanced/README.rst | 8 +-- web_widget_url_advanced/__manifest__.py | 6 +- .../readme/CONTRIBUTORS.md | 1 + web_widget_url_advanced/readme/ROADMAP.md | 1 - web_widget_url_advanced/readme/USAGE.md | 2 +- .../static/description/index.html | 41 +++++++------- .../static/src/fields/url_field.esm.js | 56 +++++++++++++++++++ .../static/src/fields/url_field.xml | 30 ++++++++++ .../static/src/js/url_widget.js | 50 ----------------- 9 files changed, 113 insertions(+), 82 deletions(-) delete mode 100644 web_widget_url_advanced/readme/ROADMAP.md create mode 100644 web_widget_url_advanced/static/src/fields/url_field.esm.js create mode 100644 web_widget_url_advanced/static/src/fields/url_field.xml delete mode 100644 web_widget_url_advanced/static/src/js/url_widget.js diff --git a/web_widget_url_advanced/README.rst b/web_widget_url_advanced/README.rst index 242ef3146..53900d8d7 100644 --- a/web_widget_url_advanced/README.rst +++ b/web_widget_url_advanced/README.rst @@ -77,7 +77,7 @@ Or user can add any hyperlink text using 'prefix_name' attribute .. code:: xml - + both can be applied inside the options attribute too: @@ -88,11 +88,6 @@ both can be applied inside the options attribute too: .. |image1| image:: https://raw.githubusercontent.com/OCA/web/17.0/web_widget_url_advanced/static/description/before.png .. |image2| image:: https://raw.githubusercontent.com/OCA/web/17.0/web_widget_url_advanced/static/description/after.png -Known issues / Roadmap -====================== - -- ```` is not supported in tree views. - Bug Tracker =========== @@ -123,6 +118,7 @@ Contributors - Swapnesh Shah - Joan Sisquella - Peerapong Supasompob +- Nedas Žilinskas Maintainers ----------- diff --git a/web_widget_url_advanced/__manifest__.py b/web_widget_url_advanced/__manifest__.py index bfd7b8a06..e7437211d 100644 --- a/web_widget_url_advanced/__manifest__.py +++ b/web_widget_url_advanced/__manifest__.py @@ -5,14 +5,16 @@ "summary": "This module extends URL widget " "for displaying anchors with custom labels.", "category": "Web", - "version": "15.0.1.0.0", + "version": "17.0.1.0.0", "license": "LGPL-3", "author": "Camptocamp, Odoo Community Association (OCA)", "website": "https://github.com/OCA/web", "depends": ["web"], "data": [], "assets": { - "web.assets_backend": ["web_widget_url_advanced/static/src/js/url_widget.js"], + "web.assets_backend": [ + "web_widget_url_advanced/static/src/fields/**/*", + ], }, "installable": True, } diff --git a/web_widget_url_advanced/readme/CONTRIBUTORS.md b/web_widget_url_advanced/readme/CONTRIBUTORS.md index af152415b..0ac59dd26 100644 --- a/web_widget_url_advanced/readme/CONTRIBUTORS.md +++ b/web_widget_url_advanced/readme/CONTRIBUTORS.md @@ -5,3 +5,4 @@ - Swapnesh Shah \<\> - Joan Sisquella \<\> - Peerapong Supasompob \<\> +- Nedas Žilinskas \<\> diff --git a/web_widget_url_advanced/readme/ROADMAP.md b/web_widget_url_advanced/readme/ROADMAP.md deleted file mode 100644 index 29709154a..000000000 --- a/web_widget_url_advanced/readme/ROADMAP.md +++ /dev/null @@ -1 +0,0 @@ -- `` is not supported in tree views. diff --git a/web_widget_url_advanced/readme/USAGE.md b/web_widget_url_advanced/readme/USAGE.md index c035778d5..f24106d2b 100644 --- a/web_widget_url_advanced/readme/USAGE.md +++ b/web_widget_url_advanced/readme/USAGE.md @@ -26,7 +26,7 @@ to Or user can add any hyperlink text using 'prefix_name' attribute ``` xml - + ``` both can be applied inside the options attribute too: diff --git a/web_widget_url_advanced/static/description/index.html b/web_widget_url_advanced/static/description/index.html index 178c36307..505788e6e 100644 --- a/web_widget_url_advanced/static/description/index.html +++ b/web_widget_url_advanced/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ pre.literal-block, pre.doctest-block, pre.math, pre.code { margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.option { span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -381,12 +382,11 @@ attribute ‘prefix_name’.

-
-

Known issues / Roadmap

-
    -
  • <field text_field="foo"/> is not supported in tree views.
  • -
-
-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -433,15 +427,15 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • Camptocamp
-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

diff --git a/web_widget_url_advanced/static/src/fields/url_field.esm.js b/web_widget_url_advanced/static/src/fields/url_field.esm.js new file mode 100644 index 000000000..bec036e9b --- /dev/null +++ b/web_widget_url_advanced/static/src/fields/url_field.esm.js @@ -0,0 +1,56 @@ +/** @odoo-module **/ + +/* Copyright 2018 Simone Orsi - Camptocamp SA +License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). */ + +import {patch} from "@web/core/utils/patch"; +import {UrlField, formUrlField, urlField} from "@web/views/fields/url/url_field"; + +patch(UrlField.props, { + text_field: {type: String, optional: true}, + prefix_name: {type: String, optional: true}, +}); + +patch(UrlField.prototype, { + _get_text_field() { + if (this.props.text_field) { + let field_value = this.props.record.data[this.props.text_field]; + if (Array.isArray(field_value) && field_value.length == 2) { + field_value = field_value[1]; + } + return field_value; + } + return false; + }, + + get title() { + return ( + this._get_text_field() || + this.props.text || + this.props.record.data[this.props.name] || + "" + ); + }, + + get formattedHrefWithPrefix() { + let value = this.formattedHref; + + if (this.props.prefix_name) { + value = this.props.prefix_name + ":" + value; + } + + return value; + }, +}); + +const patchExtractProps = { + extractProps({attrs, options}) { + const props = super.extractProps(...arguments); + props.text_field = attrs.text_field || options.text_field; + props.prefix_name = attrs.prefix_name || options.prefix_name; + return props; + }, +}; + +patch(urlField, patchExtractProps); +patch(formUrlField, patchExtractProps); diff --git a/web_widget_url_advanced/static/src/fields/url_field.xml b/web_widget_url_advanced/static/src/fields/url_field.xml new file mode 100644 index 000000000..be568aaf3 --- /dev/null +++ b/web_widget_url_advanced/static/src/fields/url_field.xml @@ -0,0 +1,30 @@ + + + + + + + title + formattedHrefWithPrefix + + + + + + + + title + formattedHrefWithPrefix + + + + + diff --git a/web_widget_url_advanced/static/src/js/url_widget.js b/web_widget_url_advanced/static/src/js/url_widget.js deleted file mode 100644 index 64ec85f81..000000000 --- a/web_widget_url_advanced/static/src/js/url_widget.js +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright 2018 Simone Orsi - Camptocamp SA -License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). */ - -odoo.define("web_widget_url_advanced", function (require) { - "use strict"; - var basic_fields = require("web.basic_fields"); - - basic_fields.UrlWidget.include({ - /** - * @override - */ - init: function () { - this._super.apply(this, arguments); - // Retrieve customized `` text from a field - // via `text_field` attribute or `options.text_field` - this.text_field = this.attrs.text_field || this.attrs.options.text_field; - }, - /** - * Retrieve anchor text based on options. - * @returns {String} - */ - _get_text: function () { - if (this.text_field) { - var field_value = this.recordData[this.text_field]; - if (_.isObject(field_value) && _.has(field_value.data)) { - field_value = field_value.data.display_name; - } - return field_value; - } - return this.attrs.text; - }, - /** - * - * @override - * @private - */ - _renderReadonly: function () { - // Base widget uses `this.attrs.text` instead of `this.value` when available. - // TODO: To check better way for update link - this.attrs.text = this._get_text(); - this._super.apply(this, arguments); - var prefix = this.attrs.prefix_name || this.attrs.options.prefix_name; - if (prefix) { - this.$el.html( - $(this.$el.html()).attr("href", prefix + ":" + this.value) - ); - } - }, - }); -});