From 785f554cd5477ac7d1abdcf08b72b17736db1a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 12 Jun 2019 18:59:39 +0200 Subject: [PATCH] Add view modified It is needed to detect all cases of modified record. issue8377 review259511002 --- CHANGELOG | 1 + src/screen.js | 4 +- src/view.js | 1 + src/view/form.js | 133 +++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 129 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ebe686e615..1dc1dee51c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add view modified * Add Dict widget for tree view Version 5.2.0 - 2019-05-06 diff --git a/src/screen.js b/src/screen.js index 911afee005..3ae9589130 100644 --- a/src/screen.js +++ b/src/screen.js @@ -1477,7 +1477,9 @@ return true; } } - // TODO test view modified + if (this.current_view.modified) { + return true; + } return false; }, unremove: function() { diff --git a/src/view.js b/src/view.js index fdefdff4e4..db6e1461b0 100644 --- a/src/view.js +++ b/src/view.js @@ -8,6 +8,7 @@ el: null, mnemonic_widget: null, view_id: null, + modified: null, editable: null, children_field: null, xml_parser: null, diff --git a/src/view/form.js b/src/view/form.js index e6169143d7..d26ab9a2df 100644 --- a/src/view/form.js +++ b/src/view/form.js @@ -329,6 +329,17 @@ function eval_pyson(value){ } return []; }, + get modified() { + for (var name in this.widgets) { + var widgets = this.widgets[name]; + for (var i=0; i < widgets.length; i++) { + if (widgets[i].modified) { + return true; + } + } + } + return false; + }, set_cursor: function(new_, reset_view) { var i, name, j; var focus_el, notebook, child, group; @@ -990,6 +1001,9 @@ function eval_pyson(value){ }, set_required: function(required) { }, + get modified() { + return false; + }, set_invisible: function(invisible) { this.visible = !invisible; if (invisible) { @@ -1301,9 +1315,19 @@ function eval_pyson(value){ this.input.attr('size', length); this.group.css('width', width); }, + get modified() { + if (this.record && this.field) { + var value = this.get_client_value(); + return value != this.get_value(); + } + return false; + }, set_value: function() { this.field.set_client(this.record, this.input.val()); }, + get_value: function() { + return this.input.val(); + }, set_readonly: function(readonly) { this.input.prop('readonly', readonly); }, @@ -1453,6 +1477,13 @@ function eval_pyson(value){ focus: function() { this.input.focus(); }, + get modified() { + if (this.record && this.field) { + var field_value = this.field.get_client(this.record); + return field_value != this.get_value(); + } + return false; + }, set_value: function() { this.field.set_client(this.record, this.get_value()); }, @@ -1520,6 +1551,13 @@ function eval_pyson(value){ focus: function() { this.input.focus(); }, + get modified() { + if (this.record && this.field) { + var value = this.input.val(); + return this.field.get_client(this.record) != value; + } + return false; + }, set_value: function() { this.field.set_client(this.record, this.input.val()); }, @@ -1559,9 +1597,19 @@ function eval_pyson(value){ this.group.css('width', ''); this.factor = Number(attributes.factor || 1); }, + get modified() { + if (this.record && this.field) { + var value = this.get_client_value(); + return value != this.get_value(); + } + return false; + }, set_value: function() { this.field.set_client( - this.record, this.input.val(), undefined, this.factor); + this.record, this.get_value(), undefined, this.factor); + }, + get_value: function() { + return this.input.val(); }, get_client_value: function() { var value = ''; @@ -1695,11 +1743,17 @@ function eval_pyson(value){ focus: function() { this.select.focus(); }, - value_get: function() { + get_value: function() { return JSON.parse(this.select.val()); }, + get modified() { + if (this.record && this.field) { + return this.field.get(this.record) != this.get_value(); + } + return false; + }, set_value: function() { - var value = this.value_get(); + var value = this.get_value(); this.field.set_client(this.record, value); }, set_readonly: function(readonly) { @@ -1790,6 +1844,11 @@ function eval_pyson(value){ focus: function() { this.input.focus(); }, + get modified() { + if (this.record && this.field) { + } + return false; + }, set_value: function() { var value = this.input.val() || ''; this.field.set_client(this.record, value); @@ -2012,6 +2071,14 @@ function eval_pyson(value){ } }); }, + get modified() { + if (this.record && this.field) { + var value = this.field.get_client(this.record) || ''; + this._normalize(this.input); + return value != (this.input.html() || ''); + } + return false; + }, set_readonly: function(readonly) { this.input.prop('contenteditable', !readonly); if (this.toolbar) { @@ -2217,6 +2284,13 @@ function eval_pyson(value){ get create_access() { return this.attributes.create && this.get_access('create'); }, + get modified() { + if (this.record && this.field) { + var value = this.entry.val(); + return this.field.get_client(this.record) != value; + } + return false; + }, id_from_value: function(value) { return value; }, @@ -2511,6 +2585,20 @@ function eval_pyson(value){ })); }); }, + get modified() { + if (this.record && this.field) { + var value = this.field.get_client(this.record); + var model = '', + name = ''; + if (value) { + model = value[0]; + name = value[1]; + } + return ((model != this.get_model()) || + (name != this.entry.val())); + } + return false; + }, id_from_value: function(value) { return parseInt(value.split(',')[1], 10); }, @@ -2794,6 +2882,9 @@ function eval_pyson(value){ this.but_switch.prop('disabled', this.screen.number_of_views <= 0); }, + get modified() { + return this.screen.current_view.modified; + }, set_readonly: function(readonly) { this._readonly = readonly; this._set_button_sensitive(); @@ -3621,6 +3712,17 @@ function eval_pyson(value){ this, view, attributes); this.select.prop('multiple', true); }, + get modified() { + if (this.record && this.field) { + var group = new Set(this.field.get_client(this.record) + .map(function(r) { + return r.id; + })); + var value = new Set(this.get_value()); + return !Sao.common.compare(value, group); + } + return false; + }, display_update_selection: function(record, field) { var i, len, element; this.update_selection(record, field, function() { @@ -3646,15 +3748,13 @@ function eval_pyson(value){ this.select.val(value); }.bind(this)); }, - set_value: function() { + get_value: function() { var value = this.select.val(); if (value) { - value = value.map(function(e) { return parseInt(e, 10); }); - } else { - value = []; + return value.map(function(e) { return parseInt(e, 10); }); } - this.field.set_client(this.record, value); - } + return []; + }, }); Sao.View.Form.Image = Sao.class_(Sao.View.Form.BinaryMixin, { @@ -4022,6 +4122,18 @@ function eval_pyson(value){ } return value; }, + get modified() { + if (this.record && this.field) { + var value = this.field.get_client(this.record); + for (var key in this.fields) { + var widget = this.fields[key]; + if (widget.modified(value)) { + return true; + } + } + } + return false; + }, set_readonly: function(readonly) { this._readonly = readonly; this._set_button_sensitive(); @@ -4195,6 +4307,9 @@ function eval_pyson(value){ this.el.change( this.parent_widget.focus_out.bind(this.parent_widget)); }, + modified: function(value) { + return this.get_value() != value.get(this.name); + }, get_value: function() { return this.input.val(); },