[FIX] website_event: unblock button when no reserve

The website_event_questions override EventRegistrationForm's method
on_click and expects the returns is a deferred.

This commit provides a deferred in all instances avoiding an error.

Also what was done in e9454e79 and enables back the Register Now
button if no ticket was selected.

opw-1850527

In 11.0, this change e9454e79 solved the use case of:

- opening the registration of a ticket
- discard

=> the page must be reloaded to register a ticket

A new report is that since 9.0, if we try to register 0 ticket we would
also have to reload the page.

This commit backports e9454e79 and solves the 0 ticket registration.
Also if website_event_questions was installed there was an error
preventing an error message to be displayed.

saas-15 version of 9.0's #24966
opw-1851622
closes #24967
This commit is contained in:
Nicolas Lempereur
2018-06-01 15:55:56 +02:00
parent 6bbf38e171
commit f71b934ce6
2 changed files with 19 additions and 5 deletions
@@ -421,6 +421,13 @@ msgstr ""
msgid "Photos of Past Events"
msgstr ""
#. module: website_event
#. openerp-web
#: code:addons/website_event/static/src/js/website_event.js:37
#, python-format
msgid "Please select at least one ticket."
msgstr ""
#. module: website_event
#: model:ir.ui.view,arch_db:website_event.registration_template
msgid "Price"
@@ -1,9 +1,12 @@
odoo.define('website_event.website_event', function (require) {
var ajax = require('web.ajax');
var core = require('web.core');
var Widget = require('web.Widget');
var web_editor_base = require('web_editor.base')
var _t = core._t;
// Catch registration form event, because of JS for attendee details
var EventRegistrationForm = Widget.extend({
start: function() {
@@ -13,7 +16,6 @@ var EventRegistrationForm = Widget.extend({
.off('click')
.removeClass('a-submit')
.click(function (ev) {
$(this).attr('disabled', true);
self.on_click(ev);
});
});
@@ -23,23 +25,28 @@ var EventRegistrationForm = Widget.extend({
ev.preventDefault();
ev.stopPropagation();
var $form = $(ev.currentTarget).closest('form');
var $button = $(ev.currentTarget).closest('[type="submit"]');
var post = {};
$('#registration_form table').siblings('.alert').remove();
$("#registration_form select").each(function() {
post[$(this).attr('name')] = $(this).val();
});
var tickets_ordered = _.some(_.map(post, function(value, key) { return parseInt(value) }));
if (! tickets_ordered) {
return $('#registration_form table').after(
'<div class="alert alert-info">Please select at least one ticket.</div>'
);
$('<div class="alert alert-info"/>')
.text(_t('Please select at least one ticket.'))
.insertAfter('#registration_form table');
return $.Deferred();
}
else {
$button.attr('disabled', true);
return ajax.jsonRpc($form.attr('action'), 'call', post).then(function (modal) {
var $modal = $(modal);
$modal.find('.modal-body > div').removeClass('container'); // retrocompatibility - REMOVE ME in master / saas-19
$modal.after($form).modal();
$modal.insertAfter($form).modal();
$modal.on('click', '.js_goto_event', function () {
$modal.modal('hide');
$button.prop('disabled', false);
});
});
}