[FIX] Fixed niv's mood
bzr revid: fme@openerp.com-20110727102519-at3qxx4sxc3fqp44
This commit is contained in:
parent
9d6085e99e
commit
216ab84e5f
|
@ -31,7 +31,7 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormVi
|
||||||
this.datarecord = {};
|
this.datarecord = {};
|
||||||
this.ready = false;
|
this.ready = false;
|
||||||
this.show_invalid = true;
|
this.show_invalid = true;
|
||||||
this.touched = false;
|
this.dirty = false;
|
||||||
this.default_focus_field = null;
|
this.default_focus_field = null;
|
||||||
this.default_focus_button = null;
|
this.default_focus_button = null;
|
||||||
this.registry = openerp.base.form.widgets;
|
this.registry = openerp.base.form.widgets;
|
||||||
|
@ -133,22 +133,22 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormVi
|
||||||
this.$form_header.find('.oe_form_on_update').show();
|
this.$form_header.find('.oe_form_on_update').show();
|
||||||
this.$form_header.find('button.oe_form_button_new').show();
|
this.$form_header.find('button.oe_form_button_new').show();
|
||||||
}
|
}
|
||||||
this.touched = false;
|
this.dirty = false;
|
||||||
this.datarecord = record;
|
this.datarecord = record;
|
||||||
for (var f in this.fields) {
|
for (var f in this.fields) {
|
||||||
var field = this.fields[f];
|
var field = this.fields[f];
|
||||||
field.touched = false;
|
field.dirty = false;
|
||||||
field.set_value(this.datarecord[f] || false);
|
field.set_value(this.datarecord[f] || false);
|
||||||
field.validate();
|
field.validate();
|
||||||
}
|
}
|
||||||
if (!record.id) {
|
if (!record.id) {
|
||||||
// New record: Second pass in order to trigger the onchanges
|
// New record: Second pass in order to trigger the onchanges
|
||||||
this.touched = true;
|
this.dirty = true;
|
||||||
this.show_invalid = false;
|
this.show_invalid = false;
|
||||||
for (var f in record) {
|
for (var f in record) {
|
||||||
var field = this.fields[f];
|
var field = this.fields[f];
|
||||||
if (field) {
|
if (field) {
|
||||||
field.touched = true;
|
field.dirty = true;
|
||||||
this.do_onchange(field);
|
this.do_onchange(field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormVi
|
||||||
processed.push(field.name);
|
processed.push(field.name);
|
||||||
if (field.get_value() != value) {
|
if (field.get_value() != value) {
|
||||||
field.set_value(value);
|
field.set_value(value);
|
||||||
field.touched = true;
|
field.dirty = true;
|
||||||
if (_.indexOf(processed, field.name) < 0) {
|
if (_.indexOf(processed, field.name) < 0) {
|
||||||
this.do_onchange(field, processed);
|
this.do_onchange(field, processed);
|
||||||
}
|
}
|
||||||
|
@ -315,28 +315,28 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormVi
|
||||||
if (!this.ready) {
|
if (!this.ready) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var dirty = false;
|
var form_dirty = false,
|
||||||
var invalid = false,
|
form_invalid = false,
|
||||||
values = {},
|
values = {},
|
||||||
first_invalid_field = null;
|
first_invalid_field = null;
|
||||||
for (var f in this.fields) {
|
for (var f in this.fields) {
|
||||||
f = this.fields[f];
|
f = this.fields[f];
|
||||||
if (f.invalid) {
|
if (!f.is_valid()) {
|
||||||
invalid = true;
|
form_invalid = true;
|
||||||
f.update_dom();
|
f.update_dom();
|
||||||
if (!first_invalid_field) {
|
if (!first_invalid_field) {
|
||||||
first_invalid_field = f;
|
first_invalid_field = f;
|
||||||
}
|
}
|
||||||
} else if (f.touched) {
|
} else if (f.is_dirty()) {
|
||||||
dirty = true;
|
form_dirty = true;
|
||||||
values[f.name] = f.get_value();
|
values[f.name] = f.get_value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (invalid) {
|
if (form_invalid) {
|
||||||
first_invalid_field.focus();
|
first_invalid_field.focus();
|
||||||
this.on_invalid();
|
this.on_invalid();
|
||||||
return false;
|
return false;
|
||||||
} else if (dirty) {
|
} else if (form_dirty) {
|
||||||
this.log("About to save", values);
|
this.log("About to save", values);
|
||||||
if (!this.datarecord.id) {
|
if (!this.datarecord.id) {
|
||||||
return this.dataset.create(values, function(r) {
|
return this.dataset.create(values, function(r) {
|
||||||
|
@ -362,7 +362,7 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormVi
|
||||||
on_invalid: function() {
|
on_invalid: function() {
|
||||||
var msg = "<ul>";
|
var msg = "<ul>";
|
||||||
_.each(this.fields, function(f) {
|
_.each(this.fields, function(f) {
|
||||||
if (f.invalid) {
|
if (!f.is_valid()) {
|
||||||
msg += "<li>" + f.string + "</li>";
|
msg += "<li>" + f.string + "</li>";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -729,7 +729,7 @@ openerp.base.form.WidgetButton = openerp.base.form.Widget.extend({
|
||||||
},
|
},
|
||||||
on_click: function(saved) {
|
on_click: function(saved) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (!this.node.attrs.special && this.view.touched && saved !== true) {
|
if (!this.node.attrs.special && this.view.dirty && saved !== true) {
|
||||||
this.view.do_save(function() {
|
this.view.do_save(function() {
|
||||||
self.on_click(true);
|
self.on_click(true);
|
||||||
});
|
});
|
||||||
|
@ -809,7 +809,7 @@ openerp.base.form.Field = openerp.base.form.Widget.extend({
|
||||||
this.readonly = this.modifiers['readonly'] === true;
|
this.readonly = this.modifiers['readonly'] === true;
|
||||||
this.required = this.modifiers['required'] === true;
|
this.required = this.modifiers['required'] === true;
|
||||||
this.invalid = false;
|
this.invalid = false;
|
||||||
this.touched = false;
|
this.dirty = false;
|
||||||
},
|
},
|
||||||
set_value: function(value) {
|
set_value: function(value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
@ -822,6 +822,12 @@ openerp.base.form.Field = openerp.base.form.Widget.extend({
|
||||||
get_value: function() {
|
get_value: function() {
|
||||||
return this.value;
|
return this.value;
|
||||||
},
|
},
|
||||||
|
is_valid: function() {
|
||||||
|
return !this.invalid;
|
||||||
|
},
|
||||||
|
is_dirty: function() {
|
||||||
|
return this.dirty;
|
||||||
|
},
|
||||||
get_on_change_value: function() {
|
get_on_change_value: function() {
|
||||||
return this.get_value();
|
return this.get_value();
|
||||||
},
|
},
|
||||||
|
@ -830,13 +836,13 @@ openerp.base.form.Field = openerp.base.form.Widget.extend({
|
||||||
this.$element.toggleClass('disabled', this.readonly);
|
this.$element.toggleClass('disabled', this.readonly);
|
||||||
this.$element.toggleClass('required', this.required);
|
this.$element.toggleClass('required', this.required);
|
||||||
if (this.view.show_invalid) {
|
if (this.view.show_invalid) {
|
||||||
this.$element.toggleClass('invalid', this.invalid);
|
this.$element.toggleClass('invalid', !this.is_valid());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
on_ui_change: function() {
|
on_ui_change: function() {
|
||||||
this.touched = this.view.touched = true;
|
this.dirty = this.view.dirty = true;
|
||||||
this.validate();
|
this.validate();
|
||||||
if (!this.invalid) {
|
if (this.is_valid()) {
|
||||||
this.set_value_from_ui();
|
this.set_value_from_ui();
|
||||||
this.view.do_onchange(this);
|
this.view.do_onchange(this);
|
||||||
this.view.on_form_changed();
|
this.view.on_form_changed();
|
||||||
|
@ -934,7 +940,7 @@ openerp.base.form.FieldEmail = openerp.base.form.FieldChar.extend({
|
||||||
this.$element.find('button').click(this.on_button_clicked);
|
this.$element.find('button').click(this.on_button_clicked);
|
||||||
},
|
},
|
||||||
on_button_clicked: function() {
|
on_button_clicked: function() {
|
||||||
if (!this.value || this.invalid) {
|
if (!this.value || !this.is_valid()) {
|
||||||
this.notification.warn("E-mail error", "Can't send email to invalid e-mail address");
|
this.notification.warn("E-mail error", "Can't send email to invalid e-mail address");
|
||||||
} else {
|
} else {
|
||||||
location.href = 'mailto:' + this.value;
|
location.href = 'mailto:' + this.value;
|
||||||
|
@ -975,7 +981,7 @@ openerp.base.form.FieldFloat = openerp.base.form.FieldChar.extend({
|
||||||
if (value === false || value === undefined) {
|
if (value === false || value === undefined) {
|
||||||
// As in GTK client, floats default to 0
|
// As in GTK client, floats default to 0
|
||||||
value = 0;
|
value = 0;
|
||||||
this.touched = true;
|
this.dirty = true;
|
||||||
}
|
}
|
||||||
var show_value = value.toFixed(2);
|
var show_value = value.toFixed(2);
|
||||||
this.$element.find('input').val(show_value);
|
this.$element.find('input').val(show_value);
|
||||||
|
@ -995,7 +1001,7 @@ openerp.base.form.FieldInteger = openerp.base.form.FieldFloat.extend({
|
||||||
if (value === false || value === undefined) {
|
if (value === false || value === undefined) {
|
||||||
// TODO fme: check if GTK client default integers to 0 (like it does with floats)
|
// TODO fme: check if GTK client default integers to 0 (like it does with floats)
|
||||||
value = 0;
|
value = 0;
|
||||||
this.touched = true;
|
this.dirty = true;
|
||||||
}
|
}
|
||||||
var show_value = parseInt(value, 10);
|
var show_value = parseInt(value, 10);
|
||||||
this.$element.find('input').val(show_value);
|
this.$element.find('input').val(show_value);
|
||||||
|
@ -1082,7 +1088,7 @@ openerp.base.form.FieldFloatTime = openerp.base.form.FieldChar.extend({
|
||||||
if (value === false || value === undefined) {
|
if (value === false || value === undefined) {
|
||||||
// As in GTK client, floats default to 0
|
// As in GTK client, floats default to 0
|
||||||
value = 0;
|
value = 0;
|
||||||
this.touched = true;
|
this.dirty = true;
|
||||||
}
|
}
|
||||||
var show_value = _.sprintf("%02d:%02d", Math.floor(value), Math.round((value % 1) * 60));
|
var show_value = _.sprintf("%02d:%02d", Math.floor(value), Math.round((value % 1) * 60));
|
||||||
this.$element.find('input').val(show_value);
|
this.$element.find('input').val(show_value);
|
||||||
|
@ -1759,7 +1765,7 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
||||||
} else if (self.viewmanager.active_view === "form") {
|
} else if (self.viewmanager.active_view === "form") {
|
||||||
for (var f in view.fields) {
|
for (var f in view.fields) {
|
||||||
f = view.fields[f];
|
f = view.fields[f];
|
||||||
if (f.invalid) {
|
if (!f.is_valid()) {
|
||||||
this.invalid = true;
|
this.invalid = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue