[imp] introduced reinitialize mixin

bzr revid: nicolas.vanhoren@openerp.com-20120319103116-pmnpnapzl0po3tqz
This commit is contained in:
niv-openerp 2012-03-19 11:31:16 +01:00
parent cade2c3f16
commit 5e5e9cdc03
1 changed files with 26 additions and 23 deletions

View File

@ -1450,20 +1450,32 @@ openerp.web.form.AbstractField = openerp.web.form.Widget.extend(/** @lends opene
} }
}); });
openerp.web.form.FieldChar = openerp.web.form.AbstractField.extend({ /**
* A mixin to apply on any field that has to completely re-render when its readonly state
* switch.
*/
openerp.web.form.ReinitializeFieldMixin = {
start: function() {
this.on("change:effective_readonly", this, function() {
this.renderElement();
this.bind_events();
this.render_value();
});
this.bind_events();
},
bind_events: function() {},
render_value: function() {},
};
openerp.web.form.FieldChar = openerp.web.form.AbstractField.extend(_.extend({}, openerp.web.form.ReinitializeFieldMixin, {
template: 'FieldChar', template: 'FieldChar',
init: function (view, node) { init: function (view, node) {
this._super(view, node); this._super(view, node);
this.password = this.node.attrs.password === 'True' || this.node.attrs.password === '1'; this.password = this.node.attrs.password === 'True' || this.node.attrs.password === '1';
}, },
start: function() { start: function() {
this._super.apply(this, arguments); this._super();
this.bind_events(); openerp.web.form.ReinitializeFieldMixin.start.call(this);
this.on("change:effective_readonly", this, function() {
this.renderElement();
this.bind_events();
this.render_value();
});
}, },
bind_events: function() { bind_events: function() {
this.$element.find('input').change(this.on_ui_change); this.$element.find('input').change(this.on_ui_change);
@ -1499,13 +1511,10 @@ openerp.web.form.FieldChar = openerp.web.form.AbstractField.extend({
focus: function($element) { focus: function($element) {
this._super($element || this.$element.find('input:first')); this._super($element || this.$element.find('input:first'));
} }
}); }));
openerp.web.form.FieldID = openerp.web.form.FieldChar.extend({ openerp.web.form.FieldID = openerp.web.form.FieldChar.extend({
update_dom: function() {
this._super.apply(this, arguments);
this.$element.find('input').prop('readonly', true);
}
}); });
openerp.web.form.FieldEmail = openerp.web.form.FieldChar.extend({ openerp.web.form.FieldEmail = openerp.web.form.FieldChar.extend({
@ -1814,7 +1823,7 @@ openerp.web.form.FieldTextXml = openerp.web.form.AbstractField.extend({
// to replace view editor // to replace view editor
}); });
openerp.web.form.FieldSelection = openerp.web.form.AbstractField.extend({ openerp.web.form.FieldSelection = openerp.web.form.AbstractField.extend(_.extend({}, openerp.web.form.ReinitializeFieldMixin, {
template: 'FieldSelection', template: 'FieldSelection',
init: function(view, node) { init: function(view, node) {
var self = this; var self = this;
@ -1828,13 +1837,8 @@ openerp.web.form.FieldSelection = openerp.web.form.AbstractField.extend({
this.values.unshift([false, '']); this.values.unshift([false, '']);
}, },
start: function() { start: function() {
this._super.apply(this, arguments); this._super();
this.bind_events(); openerp.web.form.ReinitializeFieldMixin.start.call(this);
this.on("change:effective_readonly", this, function() {
this.renderElement();
this.bind_events();
this.render_value();
});
}, },
bind_events: function() { bind_events: function() {
// Flag indicating whether we're in an event chain containing a change // Flag indicating whether we're in an event chain containing a change
@ -1894,7 +1898,7 @@ openerp.web.form.FieldSelection = openerp.web.form.AbstractField.extend({
focus: function($element) { focus: function($element) {
this._super($element || this.$element.find('select:first')); this._super($element || this.$element.find('select:first'));
} }
}); }));
// jquery autocomplete tweak to allow html // jquery autocomplete tweak to allow html
(function() { (function() {
@ -2301,7 +2305,6 @@ openerp.web.form.FieldMany2One = openerp.web.form.AbstractField.extend({
this._super($element || this.$input); this._super($element || this.$input);
} }
}); });
openerp.web.check_interface(openerp.web.form.FieldMany2One, openerp.web.form.FieldInterface);
/* /*
# Values: (0, 0, { fields }) create # Values: (0, 0, { fields }) create