Browse Source

Merge pull request #124 from acsone/8.0-add-web-widget-autocolor-ape

[ADD] Add web widget auto color module
pull/138/head
Sylvain LE GAL 10 years ago
parent
commit
4782ff0f52
  1. 54
      web_option_auto_color/README.rst
  2. 1
      web_option_auto_color/__init__.py
  3. 41
      web_option_auto_color/__openerp__.py
  4. 57
      web_option_auto_color/static/src/js/view_list.js
  5. 8
      web_option_auto_color/static/src/xml/templates.xml
  6. 10
      web_option_auto_color/views/web_option_auto_color.xml

54
web_option_auto_color/README.rst

@ -0,0 +1,54 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License
Web Option Auto Color
=====================
This module was written to offer a new autocolor attribute which can be used on
field in trees view. Using this attribute causes an identical coloration for
cells of the same value in a list view.
Installation
============
To install this module, you need to:
* Click on install button
Usage
=====
In the view declaration, put autocolor="1" attribute in the field tag::
...
<field name="arch" type="xml">
<tree string="View name">
...
<field name="name"/>
<field name="name2" autocolor="1"/>
...
</tree>
</field>
...
Credits
=======
Contributors
------------
* Stéphane Bidoul (ACSONE) <stephane.bidoul@acsone.eu>
* Adrien Peiffer (ACSONE) <adrien.peiffer@acsone.eu>
Maintainer
----------
.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://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 http://odoo-community.org.

1
web_option_auto_color/__init__.py

@ -0,0 +1 @@
# -*- coding: utf-8 -*-

41
web_option_auto_color/__openerp__.py

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# This file is part of web_option_auto_color,
# an Odoo module.
#
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
#
# web_option_auto_color is free software:
# you can redistribute it and/or modify it under the terms of the GNU
# Affero General Public License as published by the Free Software
# Foundation,either version 3 of the License, or (at your option) any
# later version.
#
# web_option_auto_color is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with web_option_auto_color.
# If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': "Web Option Auto Color",
'author': "ACSONE SA/NV,Odoo Community Association (OCA)",
'website': "http://acsone.eu",
'category': 'web',
'version': '0.1',
'license': 'AGPL-3',
'depends': [
'web',
],
'data': [
'views/web_option_auto_color.xml',
],
'qweb': [
'static/src/xml/templates.xml',
],
}

57
web_option_auto_color/static/src/js/view_list.js

@ -0,0 +1,57 @@
openerp.web_option_auto_color = function(instance) {
var _t = instance.web._t,
_lt = instance.web._lt;
var QWeb = instance.web.qweb;
instance.web.ListView.include({
dh : function (n){
var hex = (255-n).toString(16).toUpperCase();
if (hex.length==1) {
hex='0'+hex;
}
return (hex);
},
inverse_color: function (couleur) {
var r = /#?(\w{2})(\w{2})(\w{2})/i;
var splitH = r.exec(couleur);
var ar=16*Number('0x'+splitH[1].slice(0,1))+Number('0x'+splitH[1].slice(1,2));
var br=16*Number('0x'+splitH[2].slice(0,1))+Number('0x'+splitH[2].slice(1,2));
var cr=16*Number('0x'+splitH[3].slice(0,1))+Number('0x'+splitH[3].slice(1,2));
return ('#'+this.dh(ar)+this.dh(br)+this.dh(cr));
},
get_seed_random_color: function(seed){
color = Math.floor((Math.abs(Math.sin(seed) * 16777215)) % 16777215);
color = color.toString(16);
while(color.length < 6) {
color = '0' + color;
}
return '#' + color;
},
getIntValue: function(str){
var sum = 0
for (i=0; i<str.length;i++){
sum += str.charCodeAt(i);
}
return sum
},
auto_color_cell_style: function(value){
style = ''
if (value != "" && value != undefined) {
var intValue = this.getIntValue(value)
bgcolor = this.get_seed_random_color(intValue)
fontcolor = this.inverse_color(bgcolor)
style = style + 'background-color: ' + bgcolor + ';' + 'color: ' + fontcolor + ';';
}
return style
}
});
};

8
web_option_auto_color/static/src/xml/templates.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<tr t-extend="ListView.row">
<t t-jquery="td[t-att-data-field='column.id']">
this.attr('t-att-style', "column.autocolor == '1' and view.auto_color_cell_style(render_cell(record, column), column)")
</t>
</tr>
</templates>

10
web_option_auto_color/views/web_option_auto_color.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="web_option_auto_color" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/web_option_auto_color/static/src/js/view_list.js"></script>
</xpath>
</template>
</data>
</openerp>
Loading…
Cancel
Save