From 54a90ca91910ea4345cf4261b80ea1cb7cfbae9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Sun, 23 Apr 2017 21:03:52 +0200 Subject: [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... --- .../web/static/tests/fields/basic_fields_tests.js | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index d9e3f55a646..c4884658508 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -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: '' + + '' + + '', + 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'); -- cgit v1.2.3