[FIX] web: correctly display the enterprise label
The `upgrade_boolean` widget should display an `Enterprise` label next to it. There is however an issue when a `label` is specified for this field. In this case, the `Enterprise` label should be placed next to the field label (and not the field itself). The easiest solution would have been to instantiate the field widget with its label, but this can't work because the field widget is instantiated before its label. We thus re-render the widget after its label creation.
This commit is contained in:
@@ -52,9 +52,9 @@ var AbstractFieldUpgrade = {
|
||||
*
|
||||
* @abstract
|
||||
* @private
|
||||
* @param {JQuery} the 'Enterprise' label to insert
|
||||
* @param {jQuery} $enterpriseLabel the 'Enterprise' label to insert
|
||||
*/
|
||||
_insertEnterpriseLabel: function ($enterprise_label) {},
|
||||
_insertEnterpriseLabel: function ($enterpriseLabel) {},
|
||||
/**
|
||||
* Opens the Upgrade dialog.
|
||||
*
|
||||
@@ -127,6 +127,15 @@ var UpgradeBoolean = FieldBoolean.extend(AbstractFieldUpgrade, {
|
||||
events: _.extend({}, AbstractField.prototype.events, {
|
||||
'click input': '_onInputClicked',
|
||||
}),
|
||||
/**
|
||||
* Re-renders the widget with the label
|
||||
*
|
||||
* @param {jQuery} $label
|
||||
*/
|
||||
renderWithLabel: function ($label) {
|
||||
this.$label = $label;
|
||||
this._render();
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
@@ -136,8 +145,9 @@ var UpgradeBoolean = FieldBoolean.extend(AbstractFieldUpgrade, {
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_insertEnterpriseLabel: function ($enterprise_label) {
|
||||
this.$el.append(' ').append($enterprise_label);
|
||||
_insertEnterpriseLabel: function ($enterpriseLabel) {
|
||||
var $el = this.$label || this.$el;
|
||||
$el.append(' ').append($enterpriseLabel);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
@@ -170,8 +180,8 @@ var UpgradeRadio = FieldRadio.extend(AbstractFieldUpgrade, {
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_insertEnterpriseLabel: function ($enterprise_label) {
|
||||
this.$('label').last().append(' ').append($enterprise_label);
|
||||
_insertEnterpriseLabel: function ($enterpriseLabel) {
|
||||
this.$('label').last().append(' ').append($enterpriseLabel);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
|
||||
@@ -809,11 +809,16 @@ var FormRenderer = BasicRenderer.extend({
|
||||
|
||||
// Attach the tooltips on the fields' label
|
||||
_.each(this.allFieldWidgets[this.state.id], function (widget) {
|
||||
var idForLabel = self.idsForLabels[widget.name];
|
||||
var $label = idForLabel ? self.$('label[for=' + idForLabel + ']') : $();
|
||||
if (core.debug || widget.attrs.help || widget.field.help) {
|
||||
var idForLabel = self.idsForLabels[widget.name];
|
||||
var $label = idForLabel ? self.$('label[for=' + idForLabel + ']') : $();
|
||||
self._addFieldTooltip(widget, $label);
|
||||
}
|
||||
if (widget.attrs.widget === 'upgrade_boolean') {
|
||||
// this widget needs a reference to its $label to be correctly
|
||||
// rendered
|
||||
widget.renderWithLabel($label);
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -39,6 +39,28 @@ QUnit.module('upgrade_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('widget upgrade_boolean in a form view', function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form>' +
|
||||
'<div class="o_field"><field name="bar" widget="upgrade_boolean"/></div>' +
|
||||
'<div class="o_label"><label for="bar"/><div>Coucou</div></div>' +
|
||||
'</form>',
|
||||
});
|
||||
|
||||
assert.strictEqual(form.$('.o_field .label').length, 0,
|
||||
"the upgrade label shouldn't be inside the field section");
|
||||
assert.strictEqual(form.$('.o_label .label').length, 1,
|
||||
"the upgrade label should be inside the label section");
|
||||
assert.strictEqual(form.$('.o_label').text(), "Bar EnterpriseCoucou",
|
||||
"the upgrade label should be inside the label section");
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user