[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, '']);
|
||||
},
|
||||
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
|
||||
// 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
|
||||
|
@ -1820,7 +1829,6 @@ openerp.web.form.FieldSelection = openerp.web.form.AbstractField.extend({
|
|||
// changing the selected value), takes the action as validating the
|
||||
// row
|
||||
var ischanging = false;
|
||||
this._super.apply(this, arguments);
|
||||
this.$element.find('select')
|
||||
.change(this.on_ui_change)
|
||||
.change(function () { ischanging = true; })
|
||||
|
@ -1835,21 +1843,31 @@ openerp.web.form.FieldSelection = openerp.web.form.AbstractField.extend({
|
|||
value = value === null ? false : value;
|
||||
value = value instanceof Array ? value[0] : value;
|
||||
this._super(value);
|
||||
var index = 0;
|
||||
for (var i = 0, ii = this.values.length; i < ii; i++) {
|
||||
if (this.values[i][0] === value) index = i;
|
||||
this.render_value();
|
||||
},
|
||||
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() {
|
||||
this.value = this.values[this.$element.find('select')[0].selectedIndex][0];
|
||||
this._super();
|
||||
},
|
||||
update_dom: function() {
|
||||
this._super.apply(this, arguments);
|
||||
this.$element.find('select').prop('disabled', this.readonly);
|
||||
},
|
||||
validate: function() {
|
||||
if (this.get("effective_readonly")) {
|
||||
this.invalid = false;
|
||||
return;
|
||||
}
|
||||
var value = this.values[this.$element.find('select')[0].selectedIndex];
|
||||
this.invalid = !(value && !(this.required && value[0] === false));
|
||||
},
|
||||
|
|
|
@ -68,29 +68,6 @@ openerp.web.page = function (openerp) {
|
|||
/** @namespace */
|
||||
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({
|
||||
set_value: function (value) {
|
||||
if (!value) {
|
||||
|
@ -144,7 +121,6 @@ openerp.web.page = function (openerp) {
|
|||
}
|
||||
});
|
||||
openerp.web.page.readonly = openerp.web.form.widgets.extend({
|
||||
'selection' : 'openerp.web.page.FieldSelectionReadonly',
|
||||
'reference': 'openerp.web.page.FieldReferenceReadonly',
|
||||
'binary': 'openerp.web.page.FieldBinaryFileReadonly',
|
||||
'image': 'openerp.web.page.FieldBinaryImageReaonly',
|
||||
|
|
|
@ -1022,16 +1022,24 @@
|
|||
</div>
|
||||
</t>
|
||||
<t t-name="FieldSelection">
|
||||
<div t-attf-class="oe_form_field_#{type}">
|
||||
<select
|
||||
t-att-name="widget.name"
|
||||
t-att-id="widget.node.attrs.id"
|
||||
style="width: 100%">
|
||||
<t t-foreach="widget.values" t-as="option">
|
||||
<option><t t-esc="option[1]"/></option>
|
||||
</t>
|
||||
</select>
|
||||
</div>
|
||||
<t t-if="!widget.get('effective_readonly')">
|
||||
<div t-attf-class="oe_form_field_#{type}">
|
||||
<select
|
||||
t-att-name="widget.name"
|
||||
t-att-id="widget.node.attrs.id"
|
||||
style="width: 100%">
|
||||
<t t-foreach="widget.values" t-as="option">
|
||||
<option><t t-esc="option[1]"/></option>
|
||||
</t>
|
||||
</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-name="FieldMany2One">
|
||||
<table t-attf-class="oe_form_field_#{type}" cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
|
|
Loading…
Reference in New Issue