Skip to content
Permalink
Browse files

[IMP] base: notify user when there are modifications in settings

Purpose
=======

When user will modify something in settings, there will be a message shown that will tell
the user that he/she has unsaved changes.

The commit is related to Task ID: 1917637

Co-authored-by: Mohammed Shekha <msh@openerp.com>
  • Loading branch information...
pch-odoo and msh-odoo committed Mar 18, 2019
1 parent 9a8f59a commit f82ecc5d9ab0224f0b0fd372f4baf89502ef753f
@@ -10,6 +10,7 @@ var FormRenderer = require('web.FormRenderer');
var view_registry = require('web.view_registry');

var QWeb = core.qweb;
var _t = core._t;

var BaseSettingRenderer = FormRenderer.extend({
events: _.extend({}, FormRenderer.prototype.events, {
@@ -33,6 +34,19 @@ var BaseSettingRenderer = FormRenderer.extend({
return prom;
},

/**
* @override
* overridden to show a message, informing user that there are changes
*/
confirmChange: function () {
var self = this;
return this._super.apply(this, arguments).then(function () {
if (!self.$(".o_dirty_warning").length) {
self.$('.o_statusbar_buttons')
.append($('<span/>', {text: _t("There are unsaved changes"), class: 'text-muted ml-2 o_dirty_warning'}))
}
});
},
/**
* @override
*/
@@ -179,5 +179,41 @@ QUnit.module('base_settings_tests', {
form.destroy();
});

QUnit.test('settings view shows a message if there are changes', async function (assert) {
assert.expect(5);

var form = await createView({
View: BaseSettingsView,
model: 'project',
data: this.data,
arch: '<form string="Settings" class="oe_form_configuration o_base_settings">' +
'<header>' +
'<button string="Save" type="object" name="execute" class="oe_highlight" />' +
'<button string="Discard" type="object" name="cancel" special="cancel" />'+
'</header>' +
'<div class="o_setting_container">' +
'<div class="settings_tab"/>' +
'<div class="settings">' +
'<div class="notFound o_hidden">No Record Found</div>' +
'<div class="app_settings_block" string="Base Setting" data-key="base-setting">' +
'<field name="bar"/>Make Changes' +
'</div>' +
'</div>' +
'</div>' +
'</form>',
});

await testUtils.mock.intercept(form, "field_changed", function (event) {
assert.ok(true,"field changed");
}, true);

assert.containsNone(form, '.o_field_boolean input:checked', "checkbox should not be checked");
assert.strictEqual(form.$(".o_dirty_warning").length,0, "warning message should not be shown");
await testUtils.dom.click(form.$("input[type='checkbox']"));
assert.strictEqual(form.$('.o_field_boolean input:checked').length, 1,"checkbox is now checked");
assert.strictEqual(form.$(".o_dirty_warning").length,1, "warning message is shown");
form.destroy();
});

});
});

0 comments on commit f82ecc5

Please sign in to comment.
You can’t perform that action at this time.