From 4618cbd513036220fc210fadb1024ec1facd6559 Mon Sep 17 00:00:00 2001 From: rde Date: Sun, 15 Oct 2017 23:56:33 +0200 Subject: [PATCH] [FIX] website: new class to disable button after first click Before this commit, if you had a simple link (just a href, not handled in JS), you couldn't simply make it clickable only once. This could be a problem in some cases. (eg: a btn creating a record, it would create as many record as many times you clicked on it) The same behavior could occur for link/button redirecting to a route creating a record. There is a window of time between the click on the btn and the moment the page is getting redirected. You have time to click multiple time on it and it would call the URL multiple time. Now, there is a class 'js_disable_on_click' that will be handled in website_root.js and will disabled the button after the first click. The fix was originally aimed to fix multiple click on "Create Page" btn on 404 --- addons/website/static/src/js/content/website_root.js | 11 +++++++++++ addons/website/views/website_templates.xml | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/addons/website/static/src/js/content/website_root.js b/addons/website/static/src/js/content/website_root.js index cf837b9df7c..7104a323040 100644 --- a/addons/website/static/src/js/content/website_root.js +++ b/addons/website/static/src/js/content/website_root.js @@ -39,6 +39,7 @@ var WebsiteRoot = BodyManager.extend({ 'click .js_change_lang': '_onLangChangeClick', 'click .js_publish_management .js_publish_btn': '_onPublishBtnClick', 'submit .js_website_submit_form': '_onWebsiteFormSubmit', + 'click .js_disable_on_click': '_onDisableOnClick', }), custom_events: _.extend({}, BodyManager.prototype.custom_events || {}, { animation_start_demand: '_onAnimationStartDemand', @@ -224,6 +225,16 @@ var WebsiteRoot = BodyManager.extend({ $btn.button('loading'); }); }, + /** + * Called when the root is notified that the button should be + * disabled after the first click. + * + * @private + * @param {Event} ev + */ + _onDisableOnClick: function (ev) { + $(ev.currentTarget).addClass('disabled'); + }, }); return { diff --git a/addons/website/views/website_templates.xml b/addons/website/views/website_templates.xml index 8447cc766b1..3f2046739d2 100644 --- a/addons/website/views/website_templates.xml +++ b/addons/website/views/website_templates.xml @@ -571,7 +571,7 @@

This page does not exists, but you can create it as you are administrator of this site.

- Create Page + Create Page
Edit the content below this line to adapt the default "page not found" page.