1
odoo.define('web.web_widget_color', function(require) {
4
var core = require('web.core');
5
var widget = require('web.form_widgets');
6
var FormView = require('web.FormView');
11
var _super_getDir = jscolor.getDir.prototype;
12
jscolor.getDir = function () {
13
var dir = _super_getDir.constructor();
14
if (dir.indexOf('web_widget_color') === -1) {
15
jscolor.dir = 'web_widget_color/static/lib/jscolor/';
20
var FieldColor = widget.FieldChar.extend({
21
template: 'FieldColor',
22
widget_class: 'oe_form_field_color',
23
is_syntax_valid: function () {
24
var $input = this.$('input');
25
if (!this.get("effective_readonly") && $input.size() > 0) {
26
var val = $input.val();
27
var isOk = /^#[0-9A-F]{6}$/i.test(val);
32
this.parse_value(this.$('input').val(), '');
40
store_dom_value: function() {
42
if (!this.get('effective_readonly') &&
43
this.$('input').val() !== '' &&
44
this.is_syntax_valid()) {
45
// We use internal_set_value because we were called by
46
// ``.commit_value()`` which is called by a ``.set_value()``
47
// itself called because of a ``onchange`` event
48
this.internal_set_value(
50
this.$('input').val())
55
render_value: function () {
56
var show_value = this.format_value(this.get('value'), '');
57
if (!this.get("effective_readonly")) {
58
var $input = this.$el.find('input');
59
$input.val(show_value);
60
$input.css("background-color", show_value);
61
jscolor.init(this.$el[0]);
63
this.$(".oe_form_char_content").text(show_value);
64
this.$('span').css("background-color", show_value);
69
core.form_widget_registry.add('color', FieldColor);
72
* Init jscolor for each editable mode on view form
75
on_button_edit: function () {
77
jscolor.init(this.$el[0]);
79
on_button_create: function () {
81
jscolor.init(this.$el[0]);
86
FieldColor: FieldColor