[FIX] hr_holidays,web: proper use of toggle_boolean in list view

hr_holiday was the only module that used a widget=toggle_boolean on a
button in a list view.  That behaviour was implemented as a column
widget in the previous list view, and was not reimplemented in the new
views. The feature is useful, but this was not done properly: it is
better to use a widget on a field (that was the intent) instead of doing
a weird hack like it was done.

With this commit, we update hr_holidays to use the ToggleBoolean widget,
which is supposed to work on every views.

Also, we fix the toggleboolean widget (it was not properly rendering
tooltips, and changes were not saved in readonly list view).

Note that it as the side effect of being better from the point of rpcs:
before, the list view had to reload itself.  Also, another advantage is
that models do not need to implement custom methods (such as
toggle_payslip_status) just to toggle a boolean...
This commit is contained in:
Géry Debongnie
2017-04-24 11:02:12 +02:00
parent a765ff503d
commit 54a90ca919
5 changed files with 98 additions and 29 deletions
@@ -258,6 +258,43 @@ QUnit.module('basic_fields', {
form.destroy();
});
QUnit.module('FieldToggleButton');
QUnit.test('use toggle_button in list view', function (assert) {
assert.expect(6);
var list = createView({
View: ListView,
model: 'partner',
data: this.data,
arch: '<tree>' +
'<field name="bar" widget="toggle_button" ' +
'options="{&quot;active&quot;: &quot;Reported in last payslips&quot;, &quot;inactive&quot;: &quot;To Report in Payslip&quot;}"/>' +
'</tree>',
res_id: 2,
});
assert.strictEqual(list.$('button i.fa.fa-circle.o_toggle_button_success').length, 4,
"should have 4 green buttons");
assert.strictEqual(list.$('button i.fa.fa-circle.text-muted').length, 1,
"should have 1 muted button");
assert.strictEqual(list.$('button').first().attr('title'), "Reported in last payslips",
"active buttons should have proper tooltip");
assert.strictEqual(list.$('button').last().attr('title'), "To Report in Payslip",
"inactive buttons should have proper tooltip");
// clicking on first button to check the state is properly changed
list.$('button').first().click();
assert.strictEqual(list.$('button i.fa.fa-circle.o_toggle_button_success').length, 3,
"should have 3 green buttons");
list.$('button').first().click();
assert.strictEqual(list.$('button i.fa.fa-circle.o_toggle_button_success').length, 4,
"should have 4 green buttons");
list.destroy();
});
QUnit.module('FieldFloat');