[FIX] web: better handling of isDirty state
When the view is saved (either directly or via a widget in readonly mode), the flag isDirty was not reset to false. also, use the $ function on widgets insted of $el.find and remove some unused imports
This commit is contained in:
committed by
Aaron Bohy
parent
47bb855c7e
commit
00cd7052cb
@@ -9,10 +9,6 @@ odoo.define('web.FieldManagerMixin', function (require) {
|
||||
*/
|
||||
|
||||
var BasicModel = require('web.BasicModel');
|
||||
var Dialog = require('web.Dialog');
|
||||
var core = require('web.core');
|
||||
|
||||
var qweb = core.qweb;
|
||||
|
||||
var FieldManagerMixin = {
|
||||
custom_events: {
|
||||
|
||||
@@ -242,6 +242,7 @@ var FormController = BasicController.extend({
|
||||
if (!stayInEdit) {
|
||||
self._toReadOnlyMode();
|
||||
}
|
||||
self.isDirty = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -313,6 +314,7 @@ var FormController = BasicController.extend({
|
||||
* @param {string} id
|
||||
*/
|
||||
_confirmSave: function (id) {
|
||||
this.isDirty = false;
|
||||
if (id === this.handle) {
|
||||
this.reload();
|
||||
} else {
|
||||
@@ -461,6 +463,7 @@ var FormController = BasicController.extend({
|
||||
var self = this;
|
||||
this.canBeDiscarded().then(function () {
|
||||
self.model.discardChanges(self.handle);
|
||||
self.isDirty = false;
|
||||
if (!self.model.isNew(self.handle)) {
|
||||
self._toReadOnlyMode();
|
||||
} else {
|
||||
|
||||
@@ -1370,8 +1370,8 @@ QUnit.module('Views', {
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual(form.pager.$el.find('.o_pager_value').text(), "1", 'pager value should be 1');
|
||||
assert.strictEqual(form.pager.$el.find('.o_pager_limit').text(), "2", 'pager limit should be 2');
|
||||
assert.strictEqual(form.pager.$('.o_pager_value').text(), "1", 'pager value should be 1');
|
||||
assert.strictEqual(form.pager.$('.o_pager_limit').text(), "2", 'pager limit should be 2');
|
||||
|
||||
// switch to edit mode
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
@@ -1382,23 +1382,84 @@ QUnit.module('Views', {
|
||||
assert.strictEqual(form.$('.o_form_input').val(), 'new value', 'input should contain new value');
|
||||
|
||||
// click on the pager to switch to the next record and cancel the confirm request
|
||||
form.pager.$el.find('.o_pager_next').click(); // click on next
|
||||
form.pager.$('.o_pager_next').click(); // click on next
|
||||
assert.ok($('.modal').length, 'a confirm modal should be displayed');
|
||||
$('.modal .modal-footer .btn-default').click(); // click on cancel
|
||||
assert.strictEqual(form.$('.o_form_input').val(), 'new value', 'input should still contain new value');
|
||||
assert.strictEqual(form.pager.$el.find('.o_pager_value').text(), "1", 'pager value should still be 1');
|
||||
assert.strictEqual(form.pager.$('.o_pager_value').text(), "1", 'pager value should still be 1');
|
||||
|
||||
// click on the pager to switch to the next record and confirm
|
||||
form.pager.$el.find('.o_pager_next').click(); // click on next
|
||||
form.pager.$('.o_pager_next').click(); // click on next
|
||||
assert.ok($('.modal').length, 'a confirm modal should be displayed');
|
||||
$('.modal .modal-footer .btn-primary').click(); // click on confirm
|
||||
assert.strictEqual(form.$('.o_form_input').val(), 'blip', 'input should contain blip');
|
||||
assert.strictEqual(form.pager.$el.find('.o_pager_value').text(), "2", 'pager value should be 2');
|
||||
assert.strictEqual(form.pager.$('.o_pager_value').text(), "2", 'pager value should be 2');
|
||||
|
||||
assert.strictEqual(nbWrite, 0, 'no write RPC should have been done');
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('handling dirty state: switching to another record', function (assert) {
|
||||
assert.expect(12);
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<field name="foo"></field>' +
|
||||
'<field name="priority" widget="priority"></field>' +
|
||||
'</form>',
|
||||
viewOptions: {
|
||||
ids: [1, 2],
|
||||
index: 0,
|
||||
},
|
||||
res_id: 1,
|
||||
});
|
||||
assert.strictEqual(form.pager.$('.o_pager_value').text(), "1", 'pager value should be 1');
|
||||
|
||||
// switch to edit mode
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
assert.strictEqual(form.$('.o_form_input').val(), 'yop', 'input should contain yop');
|
||||
|
||||
// edit the foo field
|
||||
form.$('.o_form_input').val('new value').trigger('input');
|
||||
assert.strictEqual(form.$('.o_form_input').val(), 'new value', 'input should contain new value');
|
||||
|
||||
form.$buttons.find('.o_form_button_save').click();
|
||||
|
||||
// click on the pager to switch to the next record and cancel the confirm request
|
||||
form.pager.$('.o_pager_next').click(); // click on next
|
||||
assert.strictEqual($('.modal').length, 0, 'no confirm modal should be displayed');
|
||||
assert.strictEqual(form.pager.$('.o_pager_value').text(), "2", 'pager value should be 2');
|
||||
|
||||
assert.strictEqual(form.$('.o_priority .fa-star-o').length, 2,
|
||||
'priority widget should have been rendered with correct value');
|
||||
|
||||
// edit the value in readonly
|
||||
form.$('.o_priority .fa-star-o:first').click(); // click on the first star
|
||||
assert.strictEqual(form.$('.o_priority .fa-star').length, 1,
|
||||
'priority widget should have been updated');
|
||||
|
||||
form.pager.$('.o_pager_next').click(); // click on next
|
||||
assert.strictEqual($('.modal').length, 0, 'no confirm modal should be displayed');
|
||||
assert.strictEqual(form.pager.$('.o_pager_value').text(), "1", 'pager value should be 1');
|
||||
|
||||
// switch to edit mode
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
assert.strictEqual(form.$('.o_form_input').val(), 'new value', 'input should contain yop');
|
||||
|
||||
// edit the foo field
|
||||
form.$('.o_form_input').val('wrong value').trigger('input');
|
||||
|
||||
form.$buttons.find('.o_form_button_cancel').click();
|
||||
assert.strictEqual($('.modal').length, 1, 'a confirm modal should be displayed');
|
||||
$('.modal .modal-footer .btn-primary').click(); // click on confirm
|
||||
form.pager.$('.o_pager_next').click(); // click on next
|
||||
assert.strictEqual(form.pager.$('.o_pager_value').text(), "2", 'pager value should be 2');
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('restore local state when switching to another record', function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
@@ -1432,7 +1493,7 @@ QUnit.module('Views', {
|
||||
"second tab should be active");
|
||||
|
||||
// click on the pager to switch to the next record
|
||||
form.pager.$el.find('.o_pager_next').click();
|
||||
form.pager.$('.o_pager_next').click();
|
||||
|
||||
assert.notOk(form.$('.o_notebook li:eq(0)').hasClass('active'),
|
||||
"first tab should not be active");
|
||||
@@ -1499,10 +1560,10 @@ QUnit.module('Views', {
|
||||
});
|
||||
|
||||
assert.strictEqual(form.mode, 'readonly', 'form view should be in readonly mode');
|
||||
assert.strictEqual(form.pager.$el.find('.o_pager_value').text(), "1", 'pager value should be 1');
|
||||
form.pager.$el.find('.o_pager_next').click(); // click on next
|
||||
assert.strictEqual(form.pager.$('.o_pager_value').text(), "1", 'pager value should be 1');
|
||||
form.pager.$('.o_pager_next').click(); // click on next
|
||||
|
||||
assert.strictEqual(form.pager.$el.find('.o_pager_value').text(), "2", 'pager value should be 2');
|
||||
assert.strictEqual(form.pager.$('.o_pager_value').text(), "2", 'pager value should be 2');
|
||||
assert.strictEqual(form.mode, 'readonly', 'form view should be in readonly mode');
|
||||
|
||||
assert.strictEqual(pushStateCount, 2, "should have triggered 2 push_state");
|
||||
|
||||
Reference in New Issue
Block a user