summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-04-11 16:23:18 +0200
committerAaron Bohy <aab@odoo.com>2017-04-13 14:31:24 +0200
commitec988d412187877c086e01ea007c1ce07d7b1860 (patch)
tree77f67d04fbea4b678f9e9a6643a5a4d35f0191dd /addons/web/static/src/js
parent6b936ba2030e1cb3c6abdaf7f9486afde4ef49ef (diff)
[FIX] web(_editor): field widget html
The field widget html wasn't implemented yet in the new views. A very basic implementation was done in addon web. It only handled the readonly mode so that the field were displayed in studio. This commit removes this basic implementation from web, and re- introduced the old one, converted, in addon web_editor.
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/fields/abstract_field.js10
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js18
-rw-r--r--addons/web/static/src/js/fields/field_registry.js1
-rw-r--r--addons/web/static/src/js/views/form/form_controller.js5
-rw-r--r--addons/web/static/src/js/views/form/form_renderer.js8
5 files changed, 23 insertions, 19 deletions
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js
index 66bf2aaabe7..f36418e3b8b 100644
--- a/addons/web/static/src/js/fields/abstract_field.js
+++ b/addons/web/static/src/js/fields/abstract_field.js
@@ -192,6 +192,16 @@ var AbstractField = Widget.extend({
activate: function () {
},
/**
+ * This function should be implemented by widgets that are not able to
+ * notify their environment when their value changes (maybe because their
+ * are not aware of the changes). It is called before saving, and should
+ * call _setValue() to notify the environment if the value changed.
+ *
+ * @abstract
+ */
+ commitChanges: function () {
+ },
+ /**
* this method is used to determine if the field value is set to a meaningful
* value. This is useful to determine if a field should be displayed as empty
*
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index 15b8b3930df..af5d9bcf233 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -702,23 +702,6 @@ var FieldText = DebouncedField.extend({
},
});
-var FieldHtml = InputField.extend({
- supportedFieldTypes: ['html'],
- text_to_html: function (text) {
- var value = text || "";
- if (value.match(/^\s*$/)) {
- value = '<p><br/></p>';
- } else {
- value = "<p>"+value.split(/<br\/?>/).join("<br/></p><p>")+"</p>";
- value = value.replace(/<p><\/p>/g, '').replace('<p><p>', '<p>').replace('<p><p ', '<p ').replace('</p></p>', '</p>');
- }
- return value;
- },
- _render: function () {
- this.$el.html(this.text_to_html(this.value));
- },
-});
-
/**
* Displays a handle to modify the sequence.
*/
@@ -2068,7 +2051,6 @@ return {
FieldDomain: FieldDomain,
FieldFloat: FieldFloat,
FieldFloatTime: FieldFloatTime,
- FieldHtml: FieldHtml,
FieldInteger: FieldInteger,
FieldMonetary: FieldMonetary,
FieldPercentPie: FieldPercentPie,
diff --git a/addons/web/static/src/js/fields/field_registry.js b/addons/web/static/src/js/fields/field_registry.js
index 83d28c1649f..00423d670fb 100644
--- a/addons/web/static/src/js/fields/field_registry.js
+++ b/addons/web/static/src/js/fields/field_registry.js
@@ -20,7 +20,6 @@ registry
.add('abstract', AbstractField)
.add('input', basic_fields.InputField)
.add('integer', basic_fields.FieldInteger)
- .add('html', basic_fields.FieldHtml)
.add('boolean', basic_fields.FieldBoolean)
.add('date', basic_fields.FieldDate)
.add('datetime', basic_fields.FieldDateTime)
diff --git a/addons/web/static/src/js/views/form/form_controller.js b/addons/web/static/src/js/views/form/form_controller.js
index 7435332ecf4..f97a93e14e8 100644
--- a/addons/web/static/src/js/views/form/form_controller.js
+++ b/addons/web/static/src/js/views/form/form_controller.js
@@ -214,6 +214,11 @@ var FormController = BasicController.extend({
saveRecord: function (options) {
var self = this;
options = options || {};
+
+ // some field widgets (e.g. 'html') can't detect (all) their changes, so
+ // we ask them to commit their current value before saving
+ this.renderer.commitChanges();
+
var stayInEdit = 'stayInEdit' in options ? options.stayInEdit : false;
var shouldReload = 'reload' in options ? options.reload : true;
if (!this.model.isDirty(this.handle) && !this.model.isNew(this.handle)) {
diff --git a/addons/web/static/src/js/views/form/form_renderer.js b/addons/web/static/src/js/views/form/form_renderer.js
index 23ed3a08ad3..e2ec7b3de70 100644
--- a/addons/web/static/src/js/views/form/form_renderer.js
+++ b/addons/web/static/src/js/views/form/form_renderer.js
@@ -77,6 +77,14 @@ return BasicRenderer.extend({
});
},
/**
+ * Calls 'commitChanges' on all field widgets, so that they can notify the
+ * environment with their current value (useful for widgets that can't
+ * detect when their value changes, e.g. field 'html').
+ */
+ commitChanges: function () {
+ _.invoke(this.widgets, 'commitChanges');
+ },
+ /**
* returns the active tab pages for each notebook
*
* @todo currently, this method is unused...