From 60976e4d02650f40208c7e05dabe66d7b954bcee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 21 Feb 2013 14:16:19 +0100 Subject: [PATCH] Manage focus_out and set_value on Form widgets --- src/view.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/view.js b/src/view.js index a68c81108b..ab8734d193 100644 --- a/src/view.js +++ b/src/view.js @@ -626,6 +626,7 @@ } var widget = new WidgetFactory(name, model, attributes); widget.position = this.widget_id += 1; + widget.view = this; // TODO expand, fill, help, height, width container.add( Number(node.getAttribute('colspan') || 1), @@ -830,6 +831,26 @@ }, display: function(record, field) { // TODO set state + }, + record: function() { + if (this.view && this.view.screen) { + return this.view.screen.current_record; + } + }, + field: function() { + var record = this.record(); + if (record) { + return record.model.fields[this.field_name]; + } + }, + focus_out: function() { + if (!this.field()) { + return; + } + // TODO visible + this.set_value(this.record(), this.field()); + }, + set_value: function(record, field) { } }); @@ -842,11 +863,16 @@ 'type': 'input', 'class': this.class_ }); + this.el.change(this.focus_out.bind(this)); }, display: function(record, field) { Sao.View.Form.Char._super.display.call(this, record, field); var value = record.field_get_client(this.field_name); this.el.val(value || ''); + }, + set_value: function(record, field) { + var value = this.el.val() || ''; + field.set_client(record, value); } }); @@ -868,11 +894,16 @@ 'class': 'form-date' }); this.el.datepicker(); + this.el.change(this.focus_out.bind(this)); }, display: function(record, field) { Sao.View.Form.Date._super.display.call(this, record, field); var value = record.field_get_client(this.field_name); this.el.datepicker('setDate', value); + }, + set_value: function(record, field) { + var value = this.el.datepicker('getDate'); + field.set_client(record, value); } }); @@ -884,6 +915,10 @@ Sao.View.Form.Integer._super.init.call(this, field_name, model, attributes); this.el.css('text-align', 'right'); + }, + set_value: function(record, field) { + var value = Number(this.el.val()); + field.set_client(record, value); } }); @@ -898,6 +933,7 @@ this.el = jQuery('