[imp] made selection readonly-able
bzr revid: nicolas.vanhoren@openerp.com-20120316122331-ewfto4tzutt87t2h
This commit is contained in:
parent
ff22ac4399
commit
5f5abc4461
|
@ -1808,6 +1808,15 @@ 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.bind_events();
|
||||||
|
this.on("change:effective_readonly", this, function() {
|
||||||
|
this.render_element();
|
||||||
|
this.bind_events();
|
||||||
|
this.render_value();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
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
|
||||||
// event on the select, in order to know what to do on keyup[RETURN]:
|
// event on the select, in order to know what to do on keyup[RETURN]:
|
||||||
// * If the user presses [RETURN] as part of changing the value of a
|
// * If the user presses [RETURN] as part of changing the value of a
|
||||||
|
@ -1820,7 +1829,6 @@ openerp.web.form.FieldSelection = openerp.web.form.AbstractField.extend({
|
||||||
// changing the selected value), takes the action as validating the
|
// changing the selected value), takes the action as validating the
|
||||||
// row
|
// row
|
||||||
var ischanging = false;
|
var ischanging = false;
|
||||||
this._super.apply(this, arguments);
|
|
||||||
this.$element.find('select')
|
this.$element.find('select')
|
||||||
.change(this.on_ui_change)
|
.change(this.on_ui_change)
|
||||||
.change(function () { ischanging = true; })
|
.change(function () { ischanging = true; })
|
||||||
|
@ -1835,21 +1843,31 @@ openerp.web.form.FieldSelection = openerp.web.form.AbstractField.extend({
|
||||||
value = value === null ? false : value;
|
value = value === null ? false : value;
|
||||||
value = value instanceof Array ? value[0] : value;
|
value = value instanceof Array ? value[0] : value;
|
||||||
this._super(value);
|
this._super(value);
|
||||||
var index = 0;
|
this.render_value();
|
||||||
for (var i = 0, ii = this.values.length; i < ii; i++) {
|
},
|
||||||
if (this.values[i][0] === value) index = i;
|
render_value: function() {
|
||||||
|
if (!this.get("effective_readonly")) {
|
||||||
|
var index = 0;
|
||||||
|
for (var i = 0, ii = this.values.length; i < ii; i++) {
|
||||||
|
if (this.values[i][0] === this.value) index = i;
|
||||||
|
}
|
||||||
|
this.$element.find('select')[0].selectedIndex = index;
|
||||||
|
} else {
|
||||||
|
var self = this;
|
||||||
|
var option = _(this.values)
|
||||||
|
.detect(function (record) { return record[0] === self.value; });
|
||||||
|
this.$element.text(option ? option[1] : this.values[0][1]);
|
||||||
}
|
}
|
||||||
this.$element.find('select')[0].selectedIndex = index;
|
|
||||||
},
|
},
|
||||||
set_value_from_ui: function() {
|
set_value_from_ui: function() {
|
||||||
this.value = this.values[this.$element.find('select')[0].selectedIndex][0];
|
this.value = this.values[this.$element.find('select')[0].selectedIndex][0];
|
||||||
this._super();
|
this._super();
|
||||||
},
|
},
|
||||||
update_dom: function() {
|
|
||||||
this._super.apply(this, arguments);
|
|
||||||
this.$element.find('select').prop('disabled', this.readonly);
|
|
||||||
},
|
|
||||||
validate: function() {
|
validate: function() {
|
||||||
|
if (this.get("effective_readonly")) {
|
||||||
|
this.invalid = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
var value = this.values[this.$element.find('select')[0].selectedIndex];
|
var value = this.values[this.$element.find('select')[0].selectedIndex];
|
||||||
this.invalid = !(value && !(this.required && value[0] === false));
|
this.invalid = !(value && !(this.required && value[0] === false));
|
||||||
},
|
},
|
||||||
|
|
|
@ -68,29 +68,6 @@ openerp.web.page = function (openerp) {
|
||||||
/** @namespace */
|
/** @namespace */
|
||||||
openerp.web.page = {};
|
openerp.web.page = {};
|
||||||
|
|
||||||
openerp.web.page.FieldSelectionReadonly = openerp.web.form.AbstractField.extend({
|
|
||||||
form_template: 'FieldChar.readonly',
|
|
||||||
init: function(view, node) {
|
|
||||||
// lifted straight from r/w version
|
|
||||||
var self = this;
|
|
||||||
this._super(view, node);
|
|
||||||
this.values = _.clone(this.field.selection);
|
|
||||||
_.each(this.values, function(v, i) {
|
|
||||||
if (v[0] === false && v[1] === '') {
|
|
||||||
self.values.splice(i, 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.values.unshift([false, '']);
|
|
||||||
},
|
|
||||||
set_value: function (value) {
|
|
||||||
value = value === null ? false : value;
|
|
||||||
value = value instanceof Array ? value[0] : value;
|
|
||||||
var option = _(this.values)
|
|
||||||
.detect(function (record) { return record[0] === value; });
|
|
||||||
this._super(value);
|
|
||||||
this.$element.find('div').text(option ? option[1] : this.values[0][1]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
openerp.web.page.FieldReferenceReadonly = openerp.web.form.FieldMany2One.extend({
|
openerp.web.page.FieldReferenceReadonly = openerp.web.form.FieldMany2One.extend({
|
||||||
set_value: function (value) {
|
set_value: function (value) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
|
@ -144,7 +121,6 @@ openerp.web.page = function (openerp) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
openerp.web.page.readonly = openerp.web.form.widgets.extend({
|
openerp.web.page.readonly = openerp.web.form.widgets.extend({
|
||||||
'selection' : 'openerp.web.page.FieldSelectionReadonly',
|
|
||||||
'reference': 'openerp.web.page.FieldReferenceReadonly',
|
'reference': 'openerp.web.page.FieldReferenceReadonly',
|
||||||
'binary': 'openerp.web.page.FieldBinaryFileReadonly',
|
'binary': 'openerp.web.page.FieldBinaryFileReadonly',
|
||||||
'image': 'openerp.web.page.FieldBinaryImageReaonly',
|
'image': 'openerp.web.page.FieldBinaryImageReaonly',
|
||||||
|
|
|
@ -1022,16 +1022,24 @@
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
<t t-name="FieldSelection">
|
<t t-name="FieldSelection">
|
||||||
<div t-attf-class="oe_form_field_#{type}">
|
<t t-if="!widget.get('effective_readonly')">
|
||||||
<select
|
<div t-attf-class="oe_form_field_#{type}">
|
||||||
t-att-name="widget.name"
|
<select
|
||||||
t-att-id="widget.node.attrs.id"
|
t-att-name="widget.name"
|
||||||
style="width: 100%">
|
t-att-id="widget.node.attrs.id"
|
||||||
<t t-foreach="widget.values" t-as="option">
|
style="width: 100%">
|
||||||
<option><t t-esc="option[1]"/></option>
|
<t t-foreach="widget.values" t-as="option">
|
||||||
</t>
|
<option><t t-esc="option[1]"/></option>
|
||||||
</select>
|
</t>
|
||||||
</div>
|
</select>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
|
<t t-if="widget.get('effective_readonly')">
|
||||||
|
<div
|
||||||
|
t-att-id="widget.element_id"
|
||||||
|
t-attf-class="field_#{widget.type} #{_(['integer', 'float', 'float_time']).contains(widget.type) ? 'oe-number' : ''}">
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
</t>
|
</t>
|
||||||
<t t-name="FieldMany2One">
|
<t t-name="FieldMany2One">
|
||||||
<table t-attf-class="oe_form_field_#{type}" cellpadding="0" cellspacing="0" border="0" width="100%">
|
<table t-attf-class="oe_form_field_#{type}" cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||||
|
|
Loading…
Reference in New Issue