[IMP] form: do not save record if not touched. action_manager: handle manual closing of dialog

bzr revid: fme@openerp.com-20110412203820-x3l9k4mgh82jxsb1
This commit is contained in:
Fabien Meghazi 2011-04-12 22:38:20 +02:00
parent a3eabdbeee
commit be257a5008
2 changed files with 15 additions and 6 deletions

View File

@ -28,6 +28,7 @@ openerp.base.FormView = openerp.base.Controller.extend( /** @lends openerp.base
this.datarecord = {};
this.ready = false;
this.show_invalid = true;
this.touched = false;
},
start: function() {
//this.log('Starting FormView '+this.model+this.view_id)
@ -78,15 +79,19 @@ openerp.base.FormView = openerp.base.Controller.extend( /** @lends openerp.base
this.$element.hide();
},
on_record_loaded: function(record) {
this.touched = false;
if (record) {
this.datarecord = record;
for (var f in this.fields) {
this.fields[f].set_value(this.datarecord[f] || false);
this.fields[f].validate();
var field = this.fields[f];
field.set_value(this.datarecord[f] || false);
field.validate();
field.touched = false;
}
if (!record.id) {
// New record: Second pass in order to trigger the onchanges
this.touched = true;
this.show_invalid = false;
// Second pass in order to trigger the onchanges in case of new record
for (var f in record) {
this.on_form_changed(this.fields[f]);
}
@ -127,7 +132,7 @@ openerp.base.FormView = openerp.base.Controller.extend( /** @lends openerp.base
this.reload();
},
do_update_pager: function(hide_index) {
var $pager = this.$element.find('#' + this.element_id + '_header div.oe_form_pager').eq(0);
var $pager = this.$element.find('#' + this.element_id + '_header div.oe_form_pager');
var index = hide_index ? '-' : this.dataset.index + 1;
$pager.find('span.oe_pager_index').html(index);
$pager.find('span.oe_pager_count').html(this.dataset.count);
@ -505,7 +510,7 @@ openerp.base.form.WidgetButton = openerp.base.form.Widget.extend({
},
on_click: function(saved) {
var self = this;
if (saved !== true) {
if (!this.node.attrs.special && this.view.touched && saved !== true) {
this.view.do_save(function() {
self.on_click(true);
});
@ -620,7 +625,7 @@ openerp.base.form.Field = openerp.base.form.Widget.extend({
}
},
on_ui_change: function() {
this.touched = true;
this.touched = this.view.touched = true;
this.set_value_from_ui();
this.validate();
this.view.on_form_changed(this);

View File

@ -19,6 +19,7 @@ openerp.base.ActionManager = openerp.base.Controller.extend({
* Supported actions: act_window
*/
do_action: function(action) {
var self = this;
// instantiate the right controllers by understanding the action
switch (action.type) {
case 'ir.actions.act_window':
@ -30,6 +31,9 @@ openerp.base.ActionManager = openerp.base.Controller.extend({
modal: true,
width: '50%',
height: 'auto'
}).bind('dialogclose', function(event) {
// When dialog is closed with ESC key or close manually, branch to act_window_close logic
self.do_action({ type: 'ir.actions.act_window_close' });
});
var viewmanager = new openerp.base.ViewManagerAction(this.session ,element_id, action, false);
viewmanager.start();