Browse Source

Merge pull request #777 from etobella/11.0-mig-web_widget_color

[11.0] [MIG] web_widget_color
pull/795/head
Pedro M. Baeza 7 years ago
committed by GitHub
parent
commit
82f232c46b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 100
      web_widget_color/README.rst
  2. 2
      web_widget_color/__init__.py
  3. 28
      web_widget_color/__manifest__.py
  4. BIN
      web_widget_color/images/form_view.png
  5. BIN
      web_widget_color/images/list_view.png
  6. BIN
      web_widget_color/images/picker.png
  7. BIN
      web_widget_color/static/description/icon.png
  8. BIN
      web_widget_color/static/lib/jscolor/arrow.gif
  9. BIN
      web_widget_color/static/lib/jscolor/cross.gif
  10. 12
      web_widget_color/static/lib/jscolor/demo.html
  11. BIN
      web_widget_color/static/lib/jscolor/hs.png
  12. BIN
      web_widget_color/static/lib/jscolor/hv.png
  13. 1010
      web_widget_color/static/lib/jscolor/jscolor.js
  14. 30
      web_widget_color/static/src/css/widget.css
  15. 53
      web_widget_color/static/src/js/widget.js
  16. 22
      web_widget_color/static/src/xml/widget.xml
  17. 10
      web_widget_color/view/web_widget_color_view.xml

100
web_widget_color/README.rst

@ -0,0 +1,100 @@
Color widget for Odoo web client
================================
This module aims to add a color picker to Odoo.
It's a `jsColor <http://jscolor.com/>`_ lib integration.
Features
========
* The picker allow the user to quickly select a color on edit mode
|picker|
.. note::
Notice how html code and the background color is updating when selecting a color.
* Display the color on form view when you are not editing it
|formview|
* Display the color on list view to quickly find what's wrong!
|listview|
Usage
=====
You need to declare a char field::
color = fields.Char(
string="Color",
help="Choose your color"
)
In the view declaration, put widget='color' attribute in the field tag::
...
<field name="arch" type="xml">
<tree string="View name">
...
<field name="color" widget="color"/>
...
</tree>
</field>
...
<field name="arch" type="xml">
<form string="View name">
...
<field name="color" widget="color"/>
...
</form>
</field>
...
.. |picker| image:: ./images/picker.png
.. |formview| image:: ./images/form_view.png
.. |listview| image:: ./images/list_view.png
.. 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/11.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/OCA/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
=======
Contributors
------------
* Adil Houmadi <adil.houmadi@gmail.com>
* Enric Tobella <etobella@creublanca.es>
* Nicolas JEUDY (Sudokeys) <https://www.github.com/njeudy>
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.

2
web_widget_color/__init__.py

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

28
web_widget_color/__manifest__.py

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Odoo, Open Source Web Widget Color
# Copyright (C) 2012 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
# Copyright (C) 2014 Anybox <http://anybox.fr>
# Copyright (C) 2015 Taktik SA <http://taktik.be>
#
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).#
{
'name': "Web Widget Color",
'category': "web",
'version': "11.0.1.0.0",
"author": "Savoir-faire Linux, "
"Anybox, "
"Taktik SA, "
"Sudokeys, "
"Odoo Community Association (OCA)",
'depends': ['base', 'web'],
'data': [
'view/web_widget_color_view.xml'
],
'qweb': [
'static/src/xml/widget.xml',
],
'license': 'AGPL-3',
'auto_install': False,
'installable': True,
'web_preload': True,
}

BIN
web_widget_color/images/form_view.png

After

Width: 307  |  Height: 62  |  Size: 1.8 KiB

BIN
web_widget_color/images/list_view.png

After

Width: 570  |  Height: 217  |  Size: 14 KiB

BIN
web_widget_color/images/picker.png

After

Width: 266  |  Height: 179  |  Size: 5.9 KiB

BIN
web_widget_color/static/description/icon.png

After

Width: 64  |  Height: 64  |  Size: 3.4 KiB

BIN
web_widget_color/static/lib/jscolor/arrow.gif

After

Width: 7  |  Height: 11  |  Size: 66 B

BIN
web_widget_color/static/lib/jscolor/cross.gif

After

Width: 15  |  Height: 15  |  Size: 83 B

12
web_widget_color/static/lib/jscolor/demo.html

@ -0,0 +1,12 @@
<html>
<head>
<title>jscolor demo</title>
</head>
<body>
<script type="text/javascript" src="jscolor.js"></script>
Click here: <input class="color" value="66ff00">
</body>
</html>

BIN
web_widget_color/static/lib/jscolor/hs.png

After

Width: 181  |  Height: 101  |  Size: 2.6 KiB

BIN
web_widget_color/static/lib/jscolor/hv.png

After

Width: 181  |  Height: 101  |  Size: 2.8 KiB

1010
web_widget_color/static/lib/jscolor/jscolor.js
File diff suppressed because it is too large
View File

30
web_widget_color/static/src/css/widget.css

@ -0,0 +1,30 @@
.openerp .oe_form .oe_form_field_color input {
width: 100%;
}
.openerp .oe_form .oe_form_field_color div {
border: 1px solid;
display: inline-block;
height: 14px;
margin-right: 10px;
position: relative;
top: 3px;
width: 40px;
}
.oe_list_field_color div {
border: 1px solid;
display: inline-block;
height: 14px;
margin-right: 10px;
position: relative;
top: 3px;
width: 40px;
}
.color_box {
width: 10px;
height: 10px;
display: inline-block;
margin-right: 5px;
}

53
web_widget_color/static/src/js/widget.js

@ -0,0 +1,53 @@
odoo.define('web.web_widget_color', function(require) {
"use strict";
var basic_fields = require('web.basic_fields');
var field_registry = require('web.field_registry');
var FormController = require('web.FormController');
var field_utils = require('web.field_utils');
var _super_getDir = jscolor.getDir.prototype;
jscolor.getDir = function () {
var dir = _super_getDir.constructor();
if (dir.indexOf('web_widget_color') === -1) {
jscolor.dir = '/web_widget_color/static/lib/jscolor/';
}
return jscolor.dir;
};
var FieldColor = basic_fields.FieldChar.extend({
template: 'FieldColor',
widget_class: 'oe_form_field_color',
_getValue: function() {
return field_utils.format.char(this.$('input').val());
},
_render: function () {
var show_value = field_utils.format.char(this.value);
jscolor.init(this.$el[0]);
if (this.mode !== 'readonly') {
var $input = this.$el.find('input');
$input.val(show_value);
$input.css("background-color", show_value);
this.$input = $input;
this.$(".oe_form_char_content").text(show_value);
this.$('span').css("background-color", show_value);
} else {
this.$(".oe_form_char_content").text(show_value);
this.$('span').css("background-color", show_value);
}
}
});
field_registry.add('color', FieldColor);
/*
* Init jscolor for each editable mode on view form
*/
FormController.include({
_updateEnv : function (parentID) {
this._super(parentID);
jscolor.init(this.$el[0]);
}
});
return FieldColor
});

22
web_widget_color/static/src/xml/widget.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="FieldColor">
<span t-att-class="'oe_form_field '+widget.widget_class" t-att-style="widget.attrs.style">
<input type="text"
t-att-id="widget.id_for_label"
t-att-tabindex="widget.attrs.tabindex"
t-att-autofocus="widget.attrs.autofocus"
t-att-placeholder="widget.attrs.placeholder"
t-att-maxlength="widget.field.size"
class="color {hash:true} o_input"
t-if="widget.mode !== 'readonly'"/>
<t t-else="">
<div/>
<span class="oe_form_char_content"></span>
</t>
</span>
</t>
<tr t-extend="ListView.row">
<t t-jquery="t td t" t-operation="replace"><t t-if="column.widget =='color' || column.type == 'color'"><div class="color_box" t-att-style="'background-color:' + render_cell(record, column)"/></t><t t-raw="render_cell(record, column)"/></t>
</tr>
</templates>

10
web_widget_color/view/web_widget_color_view.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="assets_backend" name="web_widget_color assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/web_widget_color/static/src/css/widget.css"/>
<script type="text/javascript" src="/web_widget_color/static/lib/jscolor/jscolor.js"></script>
<script type="text/javascript" src="/web_widget_color/static/src/js/widget.js"></script>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save