Browse Source

[ADD] Adding web_list_url_widget module

pull/826/head
George Daramouskas 7 years ago
parent
commit
b23c5d294a
No known key found for this signature in database GPG Key ID: 5B4EF742F8CD859C
  1. 63
      web_widget_url_listview/README.rst
  2. 3
      web_widget_url_listview/__init__.py
  3. 21
      web_widget_url_listview/__openerp__.py
  4. 16
      web_widget_url_listview/data/assets_backend.xml
  5. 14
      web_widget_url_listview/demo/demo.xml
  6. BIN
      web_widget_url_listview/static/description/icon.png
  7. 30
      web_widget_url_listview/static/src/js/web_list_url_widget.js

63
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
<https://github.com/OCA/web/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 <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* George Daramouskas <gdaramouskas@therp.nl>
Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ 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.

3
web_widget_url_listview/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

21
web_widget_url_listview/__openerp__.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Therp BV <http://therp.nl>
# 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,
}

16
web_widget_url_listview/data/assets_backend.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<template
id="assets_backend"
name="web_widget_url_listview assets"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/web_widget_url_listview/static/src/js/web_list_url_widget.js">
</script>
</xpath>
</template>
</data>
</openerp>

14
web_widget_url_listview/demo/demo.xml

@ -0,0 +1,14 @@
<openerp>
<data>
<record id="demo_url_field" model="ir.ui.view">
<field name="name">demo.url.field</field>
<field name="model">ir.module.module</field>
<field name="inherit_id" ref="base.module_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='author']" position="after">
<field name="website" widget="url"/>
</xpath>
</field>
</record>
</data>
</openerp>

BIN
web_widget_url_listview/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

30
web_widget_url_listview/static/src/js/web_list_url_widget.js

@ -0,0 +1,30 @@
// -*- coding: utf-8 -*-
// Copyright 2017 Therp BV <http://therp.nl>
// 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 <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(
"<a href='<%-href%>' target='_blank'><%-text%></a>", {
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');
};
Loading…
Cancel
Save