Browse Source

fix: update to new js api

- Force store_dom_value
- add clean colored square in tree view
- update readme and __openerp__.py for maintainers
pull/1113/head
Nicolas JEUDY 9 years ago
committed by Pedro M. Baeza
parent
commit
2b5d7e83e3
  1. 1
      web_widget_color/README.rst
  2. 1
      web_widget_color/__openerp__.py
  3. 7
      web_widget_color/static/src/css/widget.css
  4. 37
      web_widget_color/static/src/js/widget.js
  5. 2
      web_widget_color/static/src/xml/widget.xml

1
web_widget_color/README.rst

@ -87,6 +87,7 @@ Contributors
------------ ------------
* Adil Houmadi <adil.houmadi@gmail.com> * Adil Houmadi <adil.houmadi@gmail.com>
* Nicolas JEUDY (Sudokeys) <https://www.github.com/njeudy>
Maintainer Maintainer
---------- ----------

1
web_widget_color/__openerp__.py

@ -30,6 +30,7 @@
"author": "Savoir-faire Linux, " "author": "Savoir-faire Linux, "
"Anybox, " "Anybox, "
"Taktik SA, " "Taktik SA, "
"Sudokeys, "
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
'depends': ['base', 'web'], 'depends': ['base', 'web'],
'data': [ 'data': [

7
web_widget_color/static/src/css/widget.css

@ -21,3 +21,10 @@
top: 3px; top: 3px;
width: 40px; width: 40px;
} }
.color_box {
width: 10px;
height: 10px;
display: inline-block;
margin-right: 5px;
}

37
web_widget_color/static/src/js/widget.js

@ -1,4 +1,12 @@
openerp.web_widget_color = function (instance) {
odoo.define('web.web_widget_color', function(require) {
"use strict";
var core = require('web.core');
var widget = require('web.form_widgets');
var FormView = require('web.FormView');
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 () {
@ -9,9 +17,7 @@ openerp.web_widget_color = function (instance) {
return jscolor.dir; return jscolor.dir;
}; };
instance.web.form.widgets.add('color', 'instance.web.form.FieldColor');
instance.web.form.FieldColor = instance.web.form.FieldChar.extend({
var FieldColor = widget.FieldChar.extend({
template: 'FieldColor', template: 'FieldColor',
widget_class: 'oe_form_field_color', widget_class: 'oe_form_field_color',
is_syntax_valid: function () { is_syntax_valid: function () {
@ -31,6 +37,21 @@ openerp.web_widget_color = function (instance) {
} }
return true; return true;
}, },
store_dom_value: function() {
if (!this.silent) {
if (!this.get('effective_readonly') &&
this.$('input').val() !== '' &&
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 () { render_value: function () {
var show_value = this.format_value(this.get('value'), ''); var show_value = this.format_value(this.get('value'), '');
if (!this.get("effective_readonly")) { if (!this.get("effective_readonly")) {
@ -45,13 +66,19 @@ openerp.web_widget_color = function (instance) {
} }
}); });
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
*/ */
instance.web.FormView.include({
FormView.include({
to_edit_mode: function () { to_edit_mode: function () {
this._super(); this._super();
jscolor.init(this.$el[0]); jscolor.init(this.$el[0]);
} }
}); });
return {
FieldColor: FieldColor
}; };
});

2
web_widget_color/static/src/xml/widget.xml

@ -19,6 +19,6 @@
</span> </span>
</t> </t>
<tr t-extend="ListView.row"> <tr t-extend="ListView.row">
<t t-jquery="t td t" t-operation="replace"><t t-if="column.widget =='color' || column.type == 'color'"><div t-att-style="'background-color:' + render_cell(record, column)"/></t><t t-raw="render_cell(record, column)"/></t>
<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> </tr>
</templates> </templates>
Loading…
Cancel
Save