[imp] made reference readonly-able

bzr revid: nicolas.vanhoren@openerp.com-20120319130952-k1921f9za3duezyn
This commit is contained in:
niv-openerp 2012-03-19 14:09:52 +01:00
parent e9ff845347
commit 993c99a414
3 changed files with 55 additions and 54 deletions

View File

@ -3158,7 +3158,7 @@ openerp.web.form.FormOpenDataset = openerp.web.ProxyDataSet.extend({
}
});
openerp.web.form.FieldReference = openerp.web.form.AbstractField.extend({
openerp.web.form.FieldReference = openerp.web.form.AbstractField.extend(_.extend({}, openerp.web.form.ReinitializeFieldMixin, {
template: 'FieldReference',
init: function(view, node) {
this._super(view, node);
@ -3181,17 +3181,7 @@ openerp.web.form.FieldReference = openerp.web.form.AbstractField.extend({
this.widgets = {};
this.fields = {};
this.fields_order = [];
this.selection = new openerp.web.form.FieldSelection(this, { attrs: {
name: 'selection',
widget: 'selection'
}});
this.reference_ready = true;
this.selection.on_value_changed.add_last(this.on_selection_changed);
this.m2o = new openerp.web.form.FieldMany2One(this, { attrs: {
name: 'm2o',
widget: 'many2one'
}});
this.m2o.on_ui_change.add_last(this.on_ui_change);
},
on_nop: function() {
},
@ -3205,10 +3195,37 @@ openerp.web.form.FieldReference = openerp.web.form.AbstractField.extend({
},
start: function() {
this._super();
// TODO: not niv compliant
this.selection.$element = $(".oe_form_view_reference_selection", this.$element);
this.selection.renderElement();
this.selection.start();
openerp.web.form.ReinitializeFieldMixin.start.call(this);
},
renderElement: function() {
if (this.selection) {
this.selection.stop();
this.selection = undefined;
}
if (this.m2o) {
this.m2o.stop();
this.m2o.undefined;
}
this._super();
},
bind_events: function() {
if (!this.get("effective_readonly")) {
this.selection = new openerp.web.form.FieldSelection(this, { attrs: {
name: 'selection',
widget: 'selection'
}});
this.selection.on_value_changed.add_last(this.on_selection_changed);
this.selection.$element = $(".oe_form_view_reference_selection", this.$element);
this.selection.renderElement();
this.selection.start();
}
this.m2o = new openerp.web.form.FieldMany2One(this, { attrs: {
name: 'm2o',
widget: 'many2one'
}});
this.m2o.set({"readonly": this.get("effective_readonly")});
this.m2o.on_ui_change.add_last(this.on_ui_change);
this.m2o.$element = $(".oe_form_view_reference_m2o", this.$element);
this.m2o.renderElement();
this.m2o.start();
@ -3221,14 +3238,19 @@ openerp.web.form.FieldReference = openerp.web.form.AbstractField.extend({
},
set_value: function(value) {
this._super(value);
this.render_value();
},
render_value: function() {
this.reference_ready = false;
var vals = [], sel_val, m2o_val;
if (typeof(value) === 'string') {
vals = value.split(',');
if (typeof(this.value) === 'string') {
vals = this.value.split(',');
}
sel_val = vals[0] || false;
m2o_val = vals[1] ? parseInt(vals[1], 10) : false;
this.selection.set_value(sel_val);
if (!this.get("effective_readonly")) {
this.selection.set_value(sel_val);
}
this.m2o.field.relation = sel_val;
this.m2o.set_value(m2o_val);
this.m2o.$element.toggle(sel_val !== false);
@ -3243,7 +3265,7 @@ openerp.web.form.FieldReference = openerp.web.form.AbstractField.extend({
return false;
}
}
});
}));
openerp.web.form.FieldBinary = openerp.web.form.AbstractField.extend({
init: function(view, node) {

View File

@ -67,31 +67,6 @@ openerp.web.page = function (openerp) {
/** @namespace */
openerp.web.page = {};
openerp.web.page.FieldReferenceReadonly = openerp.web.form.FieldMany2One.extend({
set_value: function (value) {
if (!value) {
return this._super(null);
}
var reference = value.split(',');
this.field.relation = reference[0];
var id = parseInt(reference[1], 10);
return this._super(id);
},
get_value: function () {
if (!this.value) {
return null;
}
var id;
if (typeof this.value === 'number') {
// name_get has not run yet
id = this.value;
} else {
id = this.value[0];
}
return _.str.sprintf('%s,%d', this.field.relation, id);
}
});
openerp.web.page.FieldBinaryImageReaonly = openerp.web.form.FieldBinaryImage.extend({
update_dom: function() {
@ -121,7 +96,6 @@ openerp.web.page = function (openerp) {
}
});
openerp.web.page.readonly = openerp.web.form.widgets.extend({
'reference': 'openerp.web.page.FieldReferenceReadonly',
'binary': 'openerp.web.page.FieldBinaryFileReadonly',
'image': 'openerp.web.page.FieldBinaryImageReaonly',

View File

@ -1057,7 +1057,7 @@
</table>
</t>
<t t-name="FieldMany2One_readonly">
<a href="#" class="oe_form_uri"/>
<a href="#" class="oe_form_uri"/>
</t>
<t t-name="FieldMany2One.context_menu">
<ul>
@ -1074,14 +1074,19 @@
</ul>
</t>
<t t-name="FieldReference">
<table t-attf-class="oe_form_field_#{widget.type}" border="0" cellpadding="0" cellspacing="0" class="oe_frame oe_forms">
<tr>
<td t-attf-class="oe_form_frame_cell oe_form_selection oe_form_view_reference_selection">
</td>
<td t-attf-class="oe_form_frame_cell oe_form_many2one oe_form_view_reference_m2o" nowrap="true" style="display: none">
</td>
</tr>
</table>
<t t-if="!widget.get('effective_readonly')">
<table t-attf-class="oe_form_field_#{widget.type}" border="0" cellpadding="0" cellspacing="0" class="oe_frame oe_forms">
<tr>
<td t-attf-class="oe_form_frame_cell oe_form_selection oe_form_view_reference_selection">
</td>
<td t-attf-class="oe_form_frame_cell oe_form_many2one oe_form_view_reference_m2o" nowrap="true" style="display: none">
</td>
</tr>
</table>
</t>
<t t-if="widget.get('effective_readonly')">
<a href="#" class="oe_form_uri"/>
</t>
</t>
<t t-name="FieldBoolean">
<div t-attf-class="oe_form_field_#{widget.type}">