[FIX] web: Form: crash when clicking on buttons in dialogs
In view dialogs (e.g. click on the external button of a many2one in edit mode), the attribute $buttons of the form controller is undefined (the buttons are rendered by the dialog directly). The code that (de)activate the buttons to prevent concurrent clicks made the assumption that $buttons exist, so it crashed when it doesn't.
This commit is contained in:
@@ -74,7 +74,9 @@ var FormController = BasicController.extend({
|
||||
*
|
||||
*/
|
||||
disableButtons: function () {
|
||||
this.$buttons.find('button').attr('disabled', true);
|
||||
if (this.$buttons) {
|
||||
this.$buttons.find('button').attr('disabled', true);
|
||||
}
|
||||
this.renderer.disableButtons();
|
||||
},
|
||||
/**
|
||||
@@ -82,7 +84,9 @@ var FormController = BasicController.extend({
|
||||
*
|
||||
*/
|
||||
enableButtons: function () {
|
||||
this.$buttons.find('button').removeAttr('disabled');
|
||||
if (this.$buttons) {
|
||||
this.$buttons.find('button').removeAttr('disabled');
|
||||
}
|
||||
this.renderer.enableButtons();
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -4511,7 +4511,7 @@ QUnit.module('Views', {
|
||||
execute_action: function (event) {
|
||||
return def.then(function() {
|
||||
event.data.on_success();
|
||||
})
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -4533,6 +4533,71 @@ QUnit.module('Views', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('buttons are disabled until action is resolved (in dialogs)', function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
var def = $.Deferred();
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form>' +
|
||||
'<sheet>' +
|
||||
'<field name="trululu"/>' +
|
||||
'</sheet>' +
|
||||
'</form>',
|
||||
archs: {
|
||||
'partner,false,form': '<form>' +
|
||||
'<sheet>' +
|
||||
'<div name="button_box" class="oe_button_box">' +
|
||||
'<button class="oe_stat_button">' +
|
||||
'<field name="bar"/>' +
|
||||
'</button>' +
|
||||
'</div>' +
|
||||
'<group>' +
|
||||
'<field name="foo"/>' +
|
||||
'</group>' +
|
||||
'</sheet>' +
|
||||
'</form>',
|
||||
},
|
||||
res_id: 1,
|
||||
intercepts: {
|
||||
execute_action: function (event) {
|
||||
return def.then(function() {
|
||||
event.data.on_success();
|
||||
});
|
||||
}
|
||||
},
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === 'get_formview_id') {
|
||||
return $.when(false);
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
viewOptions: {
|
||||
mode: 'edit',
|
||||
},
|
||||
});
|
||||
|
||||
form.$('.o_external_button').click();
|
||||
|
||||
assert.notOk($('.modal .oe_button_box button').attr('disabled'),
|
||||
"stat buttons should be enabled");
|
||||
|
||||
$('.modal .oe_button_box button').click();
|
||||
|
||||
assert.ok($('.modal .oe_button_box button').attr('disabled'),
|
||||
"stat buttons should be disabled");
|
||||
|
||||
def.resolve();
|
||||
|
||||
assert.notOk($('.modal .oe_button_box button').attr('disabled'),
|
||||
"stat buttons should be enabled");
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('multiple clicks on save should reload only once', function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user