diff --git a/web_widget_url_listview/README.rst b/web_widget_url_listview/README.rst new file mode 100644 index 00000000..575e06ea --- /dev/null +++ b/web_widget_url_listview/README.rst @@ -0,0 +1,63 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=================== +Listview URL Widget +=================== + +This module was written to extend the functionality of ListView to support URLs +and allow you transform any text field into an hyperlink. + +Usage +===== + +To use this module, you need to: + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/162/8.0 + +And set widget="url" to the text field that you want to appear as hyperlink. + + +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 smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* George Daramouskas + +Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list `_ or the `appropriate specialized mailinglist `_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues. + +**This module is a backport from Odoo SA and as such, it is not included in the OCA CLA. That means we do not have a copy of the copyright on it like all other OCA modules.** + + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/web_widget_url_listview/__init__.py b/web_widget_url_listview/__init__.py new file mode 100644 index 00000000..5603d45c --- /dev/null +++ b/web_widget_url_listview/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# © 2017 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/web_widget_url_listview/__openerp__.py b/web_widget_url_listview/__openerp__.py new file mode 100644 index 00000000..815b443d --- /dev/null +++ b/web_widget_url_listview/__openerp__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Web Widget ListView Url", + "version": "8.0.1.0.0", + "author": "Therp BV,Odoo SA,Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "web", + "depends": [ + "web", + ], + "data": [ + "data/assets_backend.xml", + ], + "demo": [ + "demo/demo.xml", + ], + "installable": True, + "application": False, +} diff --git a/web_widget_url_listview/data/assets_backend.xml b/web_widget_url_listview/data/assets_backend.xml new file mode 100644 index 00000000..675d4762 --- /dev/null +++ b/web_widget_url_listview/data/assets_backend.xml @@ -0,0 +1,16 @@ + + + + + + diff --git a/web_widget_url_listview/demo/demo.xml b/web_widget_url_listview/demo/demo.xml new file mode 100644 index 00000000..1ec69dd7 --- /dev/null +++ b/web_widget_url_listview/demo/demo.xml @@ -0,0 +1,14 @@ + + + + demo.url.field + ir.module.module + + + + + + + + + diff --git a/web_widget_url_listview/static/description/icon.png b/web_widget_url_listview/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/web_widget_url_listview/static/description/icon.png differ diff --git a/web_widget_url_listview/static/src/js/web_list_url_widget.js b/web_widget_url_listview/static/src/js/web_list_url_widget.js new file mode 100644 index 00000000..cfe1db1f --- /dev/null +++ b/web_widget_url_listview/static/src/js/web_list_url_widget.js @@ -0,0 +1,30 @@ +// -*- coding: utf-8 -*- +// Copyright 2017 Therp BV +// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +openerp.web_widget_url_listview = function (instance) { + "use strict"; + + instance.web.list.Url = instance.web.list.Column.extend({ + PROTOCOL_REGEX: /^(?!\w+:?\/\/)/, + + /** + * Formats the element into a so that it can be clicked. + * @param {Object} row_data The data of this widget. + * @param {Object} options Options for this widget. + * @returns {Object} The data formatted + * */ + _format: function (row_data, options) { + var value = row_data[this.id].value; + if (value) { + return _.template( + "<%-text%>", { + href: value.trim().replace(this.PROTOCOL_REGEX, '//'), + text: value, + }); + } + return this._super(row_data, options); + }, + }); + instance.web.list.columns.add('field.url', 'instance.web.list.Url'); +};