diff --git a/web_widget_url_advanced/README.rst b/web_widget_url_advanced/README.rst new file mode 100644 index 000000000000..7452cadba5c4 --- /dev/null +++ b/web_widget_url_advanced/README.rst @@ -0,0 +1,142 @@ +======================= +Web URL widget advanced +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3596008f4a705be27d5f63123a0330ad2e83c021846d6fe34e6007e82d5988fe + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/18.0/web_widget_url_advanced + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_widget_url_advanced + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Extend URL, CopyClipboardURL widget features to ease customization of +anchor's text. + +By default, the URL, CopyClipboardURL widget will show the plain URL. +You can specify an attribute to provide a static label too. + +With this module, you can use a field for link's inner text using +attribute 'text_field'. You can also add a prefix to the link using +attribute 'prefix_name'. + +Until 13.0 this functionality was separated in modules +'web_widget_url_advanced' and 'web_widget_prefixed_url' + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Use url, CopyClipboardURL widget as you do usually, then add an extra +parameter text\_ field to indicate which field (present in the view +already) must be used for the anchor text. + +.. code:: xml + + + +M2O fields are supported: display_name is used automatically. + +For example, in the partner form, if you want to display the website +link with partner's name as anchor you can do: + +.. code:: xml + + + +This is going to change the rendering from + +|image1| + +to + +|image2| + +Or user can add any hyperlink text using 'prefix_name' attribute + +.. code:: xml + + + +both can be applied inside the options attribute too: + +.. code:: xml + + + +.. |image1| image:: https://raw.githubusercontent.com/OCA/web/18.0/web_widget_url_advanced/static/description/before.png +.. |image2| image:: https://raw.githubusercontent.com/OCA/web/18.0/web_widget_url_advanced/static/description/after.png + +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 +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Camptocamp + +Contributors +------------ + +- Simone Orsi +- `CorporateHub `__ + + - Alexey Pelykh + +- Jay Vora +- Swapnesh Shah +- Joan Sisquella +- Peerapong Supasompob +- Nedas Žilinskas +- `Komit `__: + + - Vang Nguyen Phu + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_widget_url_advanced/__init__.py b/web_widget_url_advanced/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/web_widget_url_advanced/__manifest__.py b/web_widget_url_advanced/__manifest__.py new file mode 100644 index 000000000000..7eae904a80f4 --- /dev/null +++ b/web_widget_url_advanced/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2018 Simone Orsi - Camptocamp SA +# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). +{ + "name": "Web URL widget advanced", + "summary": "This module extends URL widget " + "for displaying anchors with custom labels.", + "category": "Web", + "version": "18.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/fields/**/*", + ], + }, + "installable": True, +} diff --git a/web_widget_url_advanced/i18n/es.po b/web_widget_url_advanced/i18n/es.po new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/web_widget_url_advanced/i18n/web_widget_url_advanced.pot b/web_widget_url_advanced/i18n/web_widget_url_advanced.pot new file mode 100644 index 000000000000..716a0702d88a --- /dev/null +++ b/web_widget_url_advanced/i18n/web_widget_url_advanced.pot @@ -0,0 +1,13 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" diff --git a/web_widget_url_advanced/i18n/zh_CN.po b/web_widget_url_advanced/i18n/zh_CN.po new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/web_widget_url_advanced/pyproject.toml b/web_widget_url_advanced/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/web_widget_url_advanced/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/web_widget_url_advanced/readme/CONTRIBUTORS.md b/web_widget_url_advanced/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..a3a09cf398c7 --- /dev/null +++ b/web_widget_url_advanced/readme/CONTRIBUTORS.md @@ -0,0 +1,10 @@ +- Simone Orsi \<\> +- [CorporateHub](https://corporatehub.eu/) + - Alexey Pelykh \<\> +- Jay Vora \<\> +- Swapnesh Shah \<\> +- Joan Sisquella \<\> +- Peerapong Supasompob \<\> +- Nedas Žilinskas \<\> +- [Komit](https://komit-consulting.com): + - Vang Nguyen Phu diff --git a/web_widget_url_advanced/readme/DESCRIPTION.md b/web_widget_url_advanced/readme/DESCRIPTION.md new file mode 100644 index 000000000000..78c2973ca795 --- /dev/null +++ b/web_widget_url_advanced/readme/DESCRIPTION.md @@ -0,0 +1,11 @@ +Extend URL, CopyClipboardURL widget features to ease customization of anchor's text. + +By default, the URL, CopyClipboardURL widget will show the plain URL. You can specify an +attribute to provide a static label too. + +With this module, you can use a field for link's inner text using +attribute 'text_field'. You can also add a prefix to the link using +attribute 'prefix_name'. + +Until 13.0 this functionality was separated in modules +'web_widget_url_advanced' and 'web_widget_prefixed_url' diff --git a/web_widget_url_advanced/readme/USAGE.md b/web_widget_url_advanced/readme/USAGE.md new file mode 100644 index 000000000000..b4eaab404e28 --- /dev/null +++ b/web_widget_url_advanced/readme/USAGE.md @@ -0,0 +1,36 @@ +Use url, CopyClipboardURL widget as you do usually, then add an extra parameter text_ +field to indicate which field (present in the view already) must be used for +the anchor text. + +``` xml + +``` + +M2O fields are supported: display_name is used automatically. + +For example, in the partner form, if you want to display the website +link with partner's name as anchor you can do: + +``` xml + +``` + +This is going to change the rendering from + +![](../static/description/before.png) + +to + +![](../static/description/after.png) + +Or user can add any hyperlink text using 'prefix_name' attribute + +``` xml + +``` + +both can be applied inside the options attribute too: + +``` xml + +``` diff --git a/web_widget_url_advanced/static/description/after.png b/web_widget_url_advanced/static/description/after.png new file mode 100644 index 000000000000..fff2176e77f8 Binary files /dev/null and b/web_widget_url_advanced/static/description/after.png differ diff --git a/web_widget_url_advanced/static/description/before.png b/web_widget_url_advanced/static/description/before.png new file mode 100644 index 000000000000..10d6fc764ec6 Binary files /dev/null and b/web_widget_url_advanced/static/description/before.png differ diff --git a/web_widget_url_advanced/static/description/icon.png b/web_widget_url_advanced/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/web_widget_url_advanced/static/description/icon.png differ diff --git a/web_widget_url_advanced/static/description/index.html b/web_widget_url_advanced/static/description/index.html new file mode 100644 index 000000000000..59da81d8c87b --- /dev/null +++ b/web_widget_url_advanced/static/description/index.html @@ -0,0 +1,472 @@ + + + + + +Web URL widget advanced + + + +
+

Web URL widget advanced

+ + +

Beta License: LGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

Extend URL, CopyClipboardURL widget features to ease customization of +anchor’s text.

+

By default, the URL, CopyClipboardURL widget will show the plain URL. +You can specify an attribute to provide a static label too.

+

With this module, you can use a field for link’s inner text using +attribute ‘text_field’. You can also add a prefix to the link using +attribute ‘prefix_name’.

+

Until 13.0 this functionality was separated in modules +‘web_widget_url_advanced’ and ‘web_widget_prefixed_url’

+

Table of contents

+ +
+

Usage

+

Use url, CopyClipboardURL widget as you do usually, then add an extra +parameter text_ field to indicate which field (present in the view +already) must be used for the anchor text.

+
+<field name="some_url" widget="url" text_field="another_field" />
+
+

M2O fields are supported: display_name is used automatically.

+

For example, in the partner form, if you want to display the website +link with partner’s name as anchor you can do:

+
+<field name="website" widget="url" text_field="name" placeholder="e.g. www.odoo.com"/>
+
+

This is going to change the rendering from

+

image1

+

to

+

image2

+

Or user can add any hyperlink text using ‘prefix_name’ attribute

+
+<field name="skype_name" widget="url" prefix_name="skype"/>
+
+

both can be applied inside the options attribute too:

+
+<field name="skype_name" widget="url" options="{'prefix_name': 'skype'}"/>
+
+
+
+

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 +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +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.

+

This module is part of the OCA/web project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + 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 000000000000..b17c32c1b2f6 --- /dev/null +++ b/web_widget_url_advanced/static/src/fields/url_field.esm.js @@ -0,0 +1,59 @@ +/* Copyright 2018 Simone Orsi - Camptocamp SA +License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). */ + +import {UrlField, formUrlField, urlField} from "@web/views/fields/url/url_field"; +import {copyClipboardURLField} from "@web/views/fields/copy_clipboard/copy_clipboard_field"; +import {patch} from "@web/core/utils/patch"; + +const AdvancedUrlFieldProps = { + text_field: {type: String, optional: true}, + prefix_name: {type: String, optional: true}, +}; + +patch(UrlField.props, AdvancedUrlFieldProps); +patch(copyClipboardURLField.component.props, AdvancedUrlFieldProps); + +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()); +patch(copyClipboardURLField, 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 000000000000..f54386a2971f --- /dev/null +++ b/web_widget_url_advanced/static/src/fields/url_field.xml @@ -0,0 +1,26 @@ + + + + + + title + formattedHrefWithPrefix + + + + + + title + formattedHrefWithPrefix + + + +