diff --git a/addons/auth_password_policy_signup/static/src/js/signup_policy.js b/addons/auth_password_policy_signup/static/src/js/signup_policy.js index e5f8384bf55..85229135c8d 100644 --- a/addons/auth_password_policy_signup/static/src/js/signup_policy.js +++ b/addons/auth_password_policy_signup/static/src/js/signup_policy.js @@ -1,18 +1,20 @@ /** @odoo-module */ -import "web.dom_ready"; import { ConcretePolicy, recommendations } from "@auth_password_policy/password_policy"; import PasswordMeter from "@auth_password_policy_signup/js/password_meter"; +import { whenReady } from "@odoo/owl"; -const signupForm = document.querySelector('.oe_signup_form, .oe_reset_password_form'); -if (signupForm) { - const password = document.querySelector("[type=password][minlength]"); - const minlength = Number(password.getAttribute("minlength")); - if (!isNaN(minlength)) { - const meter = new PasswordMeter(null, new ConcretePolicy({minlength}), recommendations); - meter.insertAfter(password); - password.addEventListener("input", (e) => { - meter.update(e.target.value); - }); +whenReady(() => { + const signupForm = document.querySelector('.oe_signup_form, .oe_reset_password_form'); + if (signupForm) { + const password = document.querySelector("[type=password][minlength]"); + const minlength = Number(password.getAttribute("minlength")); + if (!isNaN(minlength)) { + const meter = new PasswordMeter(null, new ConcretePolicy({minlength}), recommendations); + meter.insertAfter(password); + password.addEventListener("input", (e) => { + meter.update(e.target.value); + }); + } } -} +}); diff --git a/addons/im_livechat/__manifest__.py b/addons/im_livechat/__manifest__.py index e66a1b29bb2..d1b22b3b3a7 100644 --- a/addons/im_livechat/__manifest__.py +++ b/addons/im_livechat/__manifest__.py @@ -171,7 +171,6 @@ Help your customers with this chat, and analyse their feedback. 'web/static/src/legacy/js/core/cookie_utils.js', 'web/static/src/legacy/js/core/utils.js', 'web/static/src/legacy/js/core/dom.js', - 'web/static/src/legacy/js/core/dom_ready.js', 'web/static/src/legacy/js/core/qweb.js', 'web/static/src/legacy/js/core/bus.js', 'web/static/src/legacy/js/services/core.js', diff --git a/addons/mass_mailing/static/src/js/mailing_portal.js b/addons/mass_mailing/static/src/js/mailing_portal.js index 417cc0a2131..8ad3aeedd16 100644 --- a/addons/mass_mailing/static/src/js/mailing_portal.js +++ b/addons/mass_mailing/static/src/js/mailing_portal.js @@ -1,189 +1,192 @@ /** @odoo-module **/ - import session from "web.session"; - import ajax from "web.ajax"; - import core from "web.core"; - import "web.dom_ready"; - import { sprintf, escape } from "@web/core/utils/strings"; +import session from "web.session"; +import ajax from "web.ajax"; +import core from "web.core"; +import { sprintf, escape } from "@web/core/utils/strings"; +import { whenReady } from "@odoo/owl"; - var _t = core._t; +var _t = core._t; +whenReady(() => { var email = $("input[name='email']").val(); var mailing_id = parseInt($("input[name='mailing_id']").val()); var res_id = parseInt($("input[name='res_id']").val()); var token = (location.search.split('token' + '=')[1] || '').split('&')[0]; -if ($('.o_unsubscribe_form').length) { - session.load_translations().then(function () { - if (email != '' && email != undefined){ - ajax.jsonRpc('/mailing/blacklist/check', 'call', {'email': email, 'mailing_id': mailing_id, 'res_id': res_id, 'token': token}) - .then(function (result) { - if (result == 'unauthorized'){ - $('#button_add_blacklist').hide(); - $('#button_remove_blacklist').hide(); - } - else if (result == true) { - $('#button_remove_blacklist').show(); - toggle_opt_out_section(false); - } - else if (result == false) { - $('#button_add_blacklist').show(); - toggle_opt_out_section(true); - } - else { + if ($('.o_unsubscribe_form').length) { + session.load_translations().then(function () { + if (email != '' && email != undefined){ + ajax.jsonRpc('/mailing/blacklist/check', 'call', {'email': email, 'mailing_id': mailing_id, 'res_id': res_id, 'token': token}) + .then(function (result) { + if (result == 'unauthorized'){ + $('#button_add_blacklist').hide(); + $('#button_remove_blacklist').hide(); + } + else if (result == true) { + $('#button_remove_blacklist').show(); + toggle_opt_out_section(false); + } + else if (result == false) { + $('#button_add_blacklist').show(); + toggle_opt_out_section(true); + } + else { + $('#subscription_info').text(_t('An error occurred. Please try again later or contact us.')); + $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error'); + } + }) + .guardedCatch(function () { $('#subscription_info').text(_t('An error occurred. Please try again later or contact us.')); $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error'); + }); + } + else { + $('#div_blacklist').hide(); + } + + var unsubscribed_list = $("input[name='unsubscribed_list']").val(); + if (unsubscribed_list){ + $('#subscription_info').html(sprintf( + _t("You have been successfully unsubscribed from %s."), + escape(unsubscribed_list) + )); + } + else{ + $('#subscription_info').html(_t('You have been successfully unsubscribed.')); + } + }); + + $('#unsubscribe_form').on('submit', function (e) { + e.preventDefault(); + + var checked_ids = []; + $("input[type='checkbox']:checked").each(function (i){ + checked_ids[i] = parseInt($(this).val()); + }); + + var unchecked_ids = []; + $("input[type='checkbox']:not(:checked)").each(function (i){ + unchecked_ids[i] = parseInt($(this).val()); + }); + + ajax.jsonRpc('/mailing/list/update', 'call', {'opt_in_ids': checked_ids, 'opt_out_ids': unchecked_ids, 'email': email, 'mailing_id': mailing_id, 'res_id': res_id, 'token': token}) + .then(function (result) { + if (result == 'unauthorized'){ + $('#subscription_info').text(_t('You are not authorized to do this!')); + $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-error').addClass('alert-warning'); + } + else if (result == true) { + $('#subscription_info').text(_t('Your changes have been saved.')); + $('#info_state').removeClass('alert-info').addClass('alert-success'); + } + else { + $('#subscription_info').text(_t('An error occurred. Your changes have not been saved, try again later.')); + $('#info_state').removeClass('alert-info').addClass('alert-warning'); + } + }) + .guardedCatch(function () { + $('#subscription_info').text(_t('An error occurred. Your changes have not been saved, try again later.')); + $('#info_state').removeClass('alert-info').addClass('alert-warning'); + }); + }); + + // ================== + // Blacklist + // ================== + $('#button_add_blacklist').click(function (e) { + e.preventDefault(); + + ajax.jsonRpc('/mailing/blacklist/add', 'call', {'email': email, 'mailing_id': mailing_id, 'res_id': res_id, 'token': token}) + .then(function (result) { + if (result == 'unauthorized'){ + $('#subscription_info').text(_t('You are not authorized to do this!')); + $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-error').addClass('alert-warning'); + } + else + { + if (result) { + $('#subscription_info').html(_t('You have been successfully added to our blacklist. ' + + 'You will not be contacted anymore by our services.')); + $('#info_state').removeClass('alert-warning').removeClass('alert-info').removeClass('alert-error').addClass('alert-success'); + toggle_opt_out_section(false); + } + else { + $('#subscription_info').text(_t('An error occurred. Please try again later or contact us.')); + $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error'); + } + $('#button_add_blacklist').hide(); + $('#button_remove_blacklist').show(); + $('#unsubscribed_info').hide(); } }) .guardedCatch(function () { $('#subscription_info').text(_t('An error occurred. Please try again later or contact us.')); $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error'); }); - } - else { - $('#div_blacklist').hide(); - } - - var unsubscribed_list = $("input[name='unsubscribed_list']").val(); - if (unsubscribed_list){ - $('#subscription_info').html(sprintf( - _t("You have been successfully unsubscribed from %s."), - escape(unsubscribed_list) - )); - } - else{ - $('#subscription_info').html(_t('You have been successfully unsubscribed.')); - } - }); - - $('#unsubscribe_form').on('submit', function (e) { - e.preventDefault(); - - var checked_ids = []; - $("input[type='checkbox']:checked").each(function (i){ - checked_ids[i] = parseInt($(this).val()); }); - - var unchecked_ids = []; - $("input[type='checkbox']:not(:checked)").each(function (i){ - unchecked_ids[i] = parseInt($(this).val()); - }); - - ajax.jsonRpc('/mailing/list/update', 'call', {'opt_in_ids': checked_ids, 'opt_out_ids': unchecked_ids, 'email': email, 'mailing_id': mailing_id, 'res_id': res_id, 'token': token}) - .then(function (result) { - if (result == 'unauthorized'){ - $('#subscription_info').text(_t('You are not authorized to do this!')); - $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-error').addClass('alert-warning'); - } - else if (result == true) { - $('#subscription_info').text(_t('Your changes have been saved.')); - $('#info_state').removeClass('alert-info').addClass('alert-success'); - } - else { - $('#subscription_info').text(_t('An error occurred. Your changes have not been saved, try again later.')); - $('#info_state').removeClass('alert-info').addClass('alert-warning'); - } - }) - .guardedCatch(function () { - $('#subscription_info').text(_t('An error occurred. Your changes have not been saved, try again later.')); - $('#info_state').removeClass('alert-info').addClass('alert-warning'); - }); - }); - - // ================== - // Blacklist - // ================== - $('#button_add_blacklist').click(function (e) { - e.preventDefault(); - - ajax.jsonRpc('/mailing/blacklist/add', 'call', {'email': email, 'mailing_id': mailing_id, 'res_id': res_id, 'token': token}) - .then(function (result) { - if (result == 'unauthorized'){ - $('#subscription_info').text(_t('You are not authorized to do this!')); - $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-error').addClass('alert-warning'); - } - else - { - if (result) { - $('#subscription_info').html(_t('You have been successfully added to our blacklist. ' - + 'You will not be contacted anymore by our services.')); - $('#info_state').removeClass('alert-warning').removeClass('alert-info').removeClass('alert-error').addClass('alert-success'); - toggle_opt_out_section(false); + + $('#button_remove_blacklist').click(function (e) { + e.preventDefault(); + + ajax.jsonRpc('/mailing/blacklist/remove', 'call', {'email': email, 'mailing_id': mailing_id, 'res_id': res_id, 'token': token}) + .then(function (result) { + if (result == 'unauthorized'){ + $('#subscription_info').text(_t('You are not authorized to do this!')); + $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-error').addClass('alert-warning'); } - else { - $('#subscription_info').text(_t('An error occurred. Please try again later or contact us.')); - $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error'); + else + { + if (result) { + $('#subscription_info').html(_t("You have been successfully removed from our blacklist. " + + "You are now able to be contacted by our services.")); + $('#info_state').removeClass('alert-warning').removeClass('alert-info').removeClass('alert-error').addClass('alert-success'); + toggle_opt_out_section(true); + } + else { + $('#subscription_info').text(_t('An error occurred. Please try again later or contact us.')); + $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error'); + } + $('#button_add_blacklist').show(); + $('#button_remove_blacklist').hide(); + $('#unsubscribed_info').hide(); } - $('#button_add_blacklist').hide(); - $('#button_remove_blacklist').show(); - $('#unsubscribed_info').hide(); - } - }) - .guardedCatch(function () { - $('#subscription_info').text(_t('An error occurred. Please try again later or contact us.')); - $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error'); - }); - }); - - $('#button_remove_blacklist').click(function (e) { - e.preventDefault(); - - ajax.jsonRpc('/mailing/blacklist/remove', 'call', {'email': email, 'mailing_id': mailing_id, 'res_id': res_id, 'token': token}) - .then(function (result) { - if (result == 'unauthorized'){ - $('#subscription_info').text(_t('You are not authorized to do this!')); - $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-error').addClass('alert-warning'); - } - else - { - if (result) { - $('#subscription_info').html(_t("You have been successfully removed from our blacklist. " - + "You are now able to be contacted by our services.")); - $('#info_state').removeClass('alert-warning').removeClass('alert-info').removeClass('alert-error').addClass('alert-success'); - toggle_opt_out_section(true); - } - else { - $('#subscription_info').text(_t('An error occurred. Please try again later or contact us.')); - $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error'); - } - $('#button_add_blacklist').show(); - $('#button_remove_blacklist').hide(); - $('#unsubscribed_info').hide(); - } - }) - .guardedCatch(function () { - $('#subscription_info').text(_t('An error occurred. Please try again later or contact us.')); - $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error'); - }); - }); - - // ================== - // Feedback - // ================== - $('#button_feedback').click(function (e) { - var feedback = $("textarea[name='opt_out_feedback']").val(); - e.preventDefault(); - ajax.jsonRpc('/mailing/feedback', 'call', {'mailing_id': mailing_id, 'res_id': res_id, 'email': email, 'feedback': feedback, 'token': token}) - .then(function (result) { - if (result == 'unauthorized'){ - $('#subscription_info').text(_t('You are not authorized to do this!')); - $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-error').addClass('alert-warning'); - } - else if (result == true){ - $('#subscription_info').text(_t('Thank you! Your feedback has been sent successfully!')); - $('#info_state').removeClass('alert-warning').removeClass('alert-info').removeClass('alert-error').addClass('alert-success'); - $("#div_feedback").hide(); - } - else { + }) + .guardedCatch(function () { $('#subscription_info').text(_t('An error occurred. Please try again later or contact us.')); - $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-error').addClass('alert-warning'); - } - }) - .guardedCatch(function () { - $('#subscription_info').text(_t('An error occurred. Please try again later or contact us.')); - $('#info_state').removeClass('alert-info').removeClass('alert-success').removeClass('alert-error').addClass('alert-warning'); - }); - }); + $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-warning').addClass('alert-error'); + }); + }); + + // ================== + // Feedback + // ================== + $('#button_feedback').click(function (e) { + var feedback = $("textarea[name='opt_out_feedback']").val(); + e.preventDefault(); + ajax.jsonRpc('/mailing/feedback', 'call', {'mailing_id': mailing_id, 'res_id': res_id, 'email': email, 'feedback': feedback, 'token': token}) + .then(function (result) { + if (result == 'unauthorized'){ + $('#subscription_info').text(_t('You are not authorized to do this!')); + $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-error').addClass('alert-warning'); + } + else if (result == true){ + $('#subscription_info').text(_t('Thank you! Your feedback has been sent successfully!')); + $('#info_state').removeClass('alert-warning').removeClass('alert-info').removeClass('alert-error').addClass('alert-success'); + $("#div_feedback").hide(); + } + else { + $('#subscription_info').text(_t('An error occurred. Please try again later or contact us.')); + $('#info_state').removeClass('alert-success').removeClass('alert-info').removeClass('alert-error').addClass('alert-warning'); + } + }) + .guardedCatch(function () { + $('#subscription_info').text(_t('An error occurred. Please try again later or contact us.')); + $('#info_state').removeClass('alert-info').removeClass('alert-success').removeClass('alert-error').addClass('alert-warning'); + }); + }); + } +}); function toggle_opt_out_section(value) { var result = !value; @@ -193,4 +196,3 @@ function toggle_opt_out_section(value) { if (value) { $('[name="button_subscription"]').addClass('clickable'); } else { $('[name="button_subscription"]').removeClass('clickable'); } } -} diff --git a/addons/web/__manifest__.py b/addons/web/__manifest__.py index f199b842ac7..a4f7a05e362 100644 --- a/addons/web/__manifest__.py +++ b/addons/web/__manifest__.py @@ -146,7 +146,6 @@ This module provides the core of the Odoo Web Client. 'web/static/src/legacy/js/core/owl_dialog.js', 'web/static/src/legacy/js/core/popover.js', 'web/static/src/legacy/js/core/dom.js', - 'web/static/src/legacy/js/core/dom_ready.js', 'web/static/src/legacy/js/core/local_storage.js', 'web/static/src/legacy/js/core/mixins.js', 'web/static/src/legacy/js/core/qweb.js', @@ -380,7 +379,6 @@ This module provides the core of the Odoo Web Client. 'web/static/src/legacy/js/core/owl_dialog.js', 'web/static/src/legacy/js/core/popover.js', 'web/static/src/legacy/js/core/dom.js', - 'web/static/src/legacy/js/core/dom_ready.js', 'web/static/src/legacy/js/core/local_storage.js', 'web/static/src/legacy/js/core/menu.js', 'web/static/src/legacy/js/core/mixins.js', diff --git a/addons/web/static/src/legacy/js/core/dom_ready.js b/addons/web/static/src/legacy/js/core/dom_ready.js deleted file mode 100644 index 9368c7d3a13..00000000000 --- a/addons/web/static/src/legacy/js/core/dom_ready.js +++ /dev/null @@ -1,5 +0,0 @@ -/** @odoo-module alias=web.dom_ready **/ - -export default new Promise(function (resolve, reject) { - $(resolve); -}); diff --git a/addons/website/static/src/js/content/compatibility.js b/addons/website/static/src/js/content/compatibility.js index 7589f15f991..de5681255c5 100644 --- a/addons/website/static/src/js/content/compatibility.js +++ b/addons/website/static/src/js/content/compatibility.js @@ -5,8 +5,6 @@ * content too. */ -import "web.dom_ready"; - // Check the browser and its version and add the info as an attribute of the // HTML element so that css selectors can match it var browser = _.findKey($.browser, function (v) { return v === true; }); diff --git a/addons/website_blog/static/src/js/options.js b/addons/website_blog/static/src/js/options.js index 3805d13f581..735e2c9590f 100644 --- a/addons/website_blog/static/src/js/options.js +++ b/addons/website_blog/static/src/js/options.js @@ -1,6 +1,5 @@ /** @odoo-module **/ -import "web.dom_ready"; import {_t} from "web.core"; import options from "web_editor.snippets.options"; import "website.editor.snippets.options"; diff --git a/addons/website_slides/__manifest__.py b/addons/website_slides/__manifest__.py index d3e767ed973..99348388770 100644 --- a/addons/website_slides/__manifest__.py +++ b/addons/website_slides/__manifest__.py @@ -220,7 +220,6 @@ Featuring 'web/static/src/legacy/js/core/owl_dialog.js', 'web/static/src/legacy/js/core/popover.js', 'web/static/src/legacy/js/core/dom.js', - 'web/static/src/legacy/js/core/dom_ready.js', 'web/static/src/legacy/js/core/local_storage.js', 'web/static/src/legacy/js/core/mixins.js', 'web/static/src/legacy/js/core/qweb.js',