mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[MIG] web_widget_color: Migration to 11.0
This commit is contained in:
@@ -30,16 +30,7 @@ Features
|
|||||||
Usage
|
Usage
|
||||||
=====
|
=====
|
||||||
|
|
||||||
You need to declare a char field of at least size 7::
|
You need to declare a char field::
|
||||||
|
|
||||||
_columns = {
|
|
||||||
'color': fields.char(
|
|
||||||
u"Couleur",
|
|
||||||
help=u"Toutes couleur valid css, exemple blue ou #f57900"
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
||||||
OR
|
|
||||||
|
|
||||||
color = fields.Char(
|
color = fields.Char(
|
||||||
string="Color",
|
string="Color",
|
||||||
@@ -53,12 +44,19 @@ In the view declaration, put widget='color' attribute in the field tag::
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="View name">
|
<tree string="View name">
|
||||||
...
|
...
|
||||||
<field name="name"/>
|
|
||||||
<field name="color" widget="color"/>
|
<field name="color" widget="color"/>
|
||||||
...
|
...
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
...
|
...
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="View name">
|
||||||
|
...
|
||||||
|
<field name="color" widget="color"/>
|
||||||
|
...
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
...
|
||||||
|
|
||||||
.. |picker| image:: ./images/picker.png
|
.. |picker| image:: ./images/picker.png
|
||||||
.. |formview| image:: ./images/form_view.png
|
.. |formview| image:: ./images/form_view.png
|
||||||
@@ -66,7 +64,7 @@ In the view declaration, put widget='color' attribute in the field tag::
|
|||||||
|
|
||||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||||
:alt: Try me on Runbot
|
:alt: Try me on Runbot
|
||||||
:target: https://runbot.odoo-community.org/runbot/162/10.0
|
:target: https://runbot.odoo-community.org/runbot/162/11.0
|
||||||
|
|
||||||
Bug Tracker
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
@@ -83,6 +81,7 @@ Contributors
|
|||||||
------------
|
------------
|
||||||
|
|
||||||
* Adil Houmadi <adil.houmadi@gmail.com>
|
* Adil Houmadi <adil.houmadi@gmail.com>
|
||||||
|
* Enric Tobella <etobella@creublanca.es>
|
||||||
* Nicolas JEUDY (Sudokeys) <https://www.github.com/njeudy>
|
* Nicolas JEUDY (Sudokeys) <https://www.github.com/njeudy>
|
||||||
|
|
||||||
Maintainer
|
Maintainer
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
# Copyright (C) 2014 Anybox <http://anybox.fr>
|
# Copyright (C) 2014 Anybox <http://anybox.fr>
|
||||||
# Copyright (C) 2015 Taktik SA <http://taktik.be>
|
# Copyright (C) 2015 Taktik SA <http://taktik.be>
|
||||||
#
|
#
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).#
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).#
|
||||||
{
|
{
|
||||||
'name': "Web Widget Color",
|
'name': "Web Widget Color",
|
||||||
'category': "web",
|
'category': "web",
|
||||||
'version': "10.0.1.0.0",
|
'version': "11.0.1.0.0",
|
||||||
"author": "Savoir-faire Linux, "
|
"author": "Savoir-faire Linux, "
|
||||||
"Anybox, "
|
"Anybox, "
|
||||||
"Taktik SA, "
|
"Taktik SA, "
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* jscolor, JavaScript Color Picker
|
* jscolor, JavaScript Color Picker
|
||||||
*
|
*
|
||||||
* @version 1.4.4
|
* @version 1.4.4
|
||||||
* @license GNU Lesser General Public License, http://www.gnu.org/copyleft/lesser.html
|
* @license GNU Lesser General Public License, https://www.gnu.org/copyleft/lesser.html
|
||||||
* @author Jan Odvarko, http://odvarko.cz
|
* @author Jan Odvarko, http://odvarko.cz
|
||||||
* @created 2008-06-15
|
* @created 2008-06-15
|
||||||
* @updated 2014-12-09
|
* @updated 2014-12-09
|
||||||
|
|||||||
@@ -1,88 +1,53 @@
|
|||||||
odoo.define('web.web_widget_color', function(require) {
|
odoo.define('web.web_widget_color', function(require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var core = require('web.core');
|
var basic_fields = require('web.basic_fields');
|
||||||
var widget = require('web.form_widgets');
|
var field_registry = require('web.field_registry');
|
||||||
var FormView = require('web.FormView');
|
var FormController = require('web.FormController');
|
||||||
|
var field_utils = require('web.field_utils');
|
||||||
var QWeb = core.qweb;
|
|
||||||
var _lt = core._lt;
|
|
||||||
|
|
||||||
var _super_getDir = jscolor.getDir.prototype;
|
var _super_getDir = jscolor.getDir.prototype;
|
||||||
jscolor.getDir = function () {
|
jscolor.getDir = function () {
|
||||||
var dir = _super_getDir.constructor();
|
var dir = _super_getDir.constructor();
|
||||||
if (dir.indexOf('web_widget_color') === -1) {
|
if (dir.indexOf('web_widget_color') === -1) {
|
||||||
jscolor.dir = 'web_widget_color/static/lib/jscolor/';
|
jscolor.dir = '/web_widget_color/static/lib/jscolor/';
|
||||||
}
|
}
|
||||||
return jscolor.dir;
|
return jscolor.dir;
|
||||||
};
|
};
|
||||||
|
|
||||||
var FieldColor = widget.FieldChar.extend({
|
var FieldColor = basic_fields.FieldChar.extend({
|
||||||
template: 'FieldColor',
|
template: 'FieldColor',
|
||||||
widget_class: 'oe_form_field_color',
|
widget_class: 'oe_form_field_color',
|
||||||
is_syntax_valid: function () {
|
_getValue: function() {
|
||||||
var $input = this.$('input');
|
return field_utils.format.char(this.$('input').val());
|
||||||
if (!this.get("effective_readonly") && $input.size() > 0) {
|
|
||||||
var val = $input.val();
|
|
||||||
var isOk = /^#[0-9A-F]{6}$/i.test(val);
|
|
||||||
if (!isOk) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
this.parse_value(this.$('input').val(), '');
|
|
||||||
return true;
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
store_dom_value: function() {
|
_render: function () {
|
||||||
if (!this.silent) {
|
var show_value = field_utils.format.char(this.value);
|
||||||
if (!this.get('effective_readonly') &&
|
jscolor.init(this.$el[0]);
|
||||||
this.$('input').val() !== '' &&
|
if (this.mode !== 'readonly') {
|
||||||
this.is_syntax_valid()) {
|
|
||||||
// We use internal_set_value because we were called by
|
|
||||||
// ``.commit_value()`` which is called by a ``.set_value()``
|
|
||||||
// itself called because of a ``onchange`` event
|
|
||||||
this.internal_set_value(
|
|
||||||
this.parse_value(
|
|
||||||
this.$('input').val())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
render_value: function () {
|
|
||||||
var show_value = this.format_value(this.get('value'), '');
|
|
||||||
if (!this.get("effective_readonly")) {
|
|
||||||
var $input = this.$el.find('input');
|
var $input = this.$el.find('input');
|
||||||
$input.val(show_value);
|
$input.val(show_value);
|
||||||
$input.css("background-color", show_value);
|
$input.css("background-color", show_value);
|
||||||
jscolor.init(this.$el[0]);
|
this.$input = $input;
|
||||||
|
this.$(".oe_form_char_content").text(show_value);
|
||||||
|
this.$('span').css("background-color", show_value);
|
||||||
} else {
|
} else {
|
||||||
this.$(".oe_form_char_content").text(show_value);
|
this.$(".oe_form_char_content").text(show_value);
|
||||||
this.$('span').css("background-color", show_value);
|
this.$('span').css("background-color", show_value);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
field_registry.add('color', FieldColor);
|
||||||
core.form_widget_registry.add('color', FieldColor);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Init jscolor for each editable mode on view form
|
* Init jscolor for each editable mode on view form
|
||||||
*/
|
*/
|
||||||
FormView.include({
|
FormController.include({
|
||||||
on_button_edit: function () {
|
_updateEnv : function (parentID) {
|
||||||
this._super();
|
this._super(parentID);
|
||||||
jscolor.init(this.$el[0]);
|
|
||||||
},
|
|
||||||
on_button_create: function () {
|
|
||||||
this._super();
|
|
||||||
jscolor.init(this.$el[0]);
|
jscolor.init(this.$el[0]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return FieldColor
|
||||||
return {
|
|
||||||
FieldColor: FieldColor
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<templates>
|
<templates>
|
||||||
<t t-name="FieldColor">
|
<t t-name="FieldColor">
|
||||||
<span t-att-class="'oe_form_field '+widget.widget_class" t-att-style="widget.node.attrs.style">
|
<span t-att-class="'oe_form_field '+widget.widget_class" t-att-style="widget.attrs.style">
|
||||||
<t t-if="!widget.get('effective_readonly')">
|
|
||||||
<input type="text"
|
<input type="text"
|
||||||
t-att-id="widget.id_for_label"
|
t-att-id="widget.id_for_label"
|
||||||
t-att-tabindex="widget.node.attrs.tabindex"
|
t-att-tabindex="widget.attrs.tabindex"
|
||||||
t-att-autofocus="widget.node.attrs.autofocus"
|
t-att-autofocus="widget.attrs.autofocus"
|
||||||
t-att-placeholder="widget.node.attrs.placeholder"
|
t-att-placeholder="widget.attrs.placeholder"
|
||||||
t-att-maxlength="widget.field.size"
|
t-att-maxlength="widget.field.size"
|
||||||
class="color {hash:true}"
|
class="color {hash:true} o_input"
|
||||||
/>
|
t-if="widget.mode !== 'readonly'"/>
|
||||||
</t>
|
<t t-else="">
|
||||||
<t t-if="widget.get('effective_readonly')">
|
|
||||||
<div/>
|
<div/>
|
||||||
<span class="oe_form_char_content"></span>
|
<span class="oe_form_char_content"></span>
|
||||||
</t>
|
</t>
|
||||||
|
|||||||
Reference in New Issue
Block a user