From a8d23ac374945c506538a2186ec6d6fe2e5d60a2 Mon Sep 17 00:00:00 2001 From: Dharmraj Jhala Date: Wed, 25 Aug 2021 09:36:09 +0000 Subject: [PATCH] [IMP] website_crm_partner_assign: fix multi datepickers on portal When a portal user is editing opportunity from front-end, there are two date inputs, 'Expected Cloing' and 'Next Activity Date'. But both of them have two pickers for selecting date, a native one and a bootstrap one, which was probably side effect of commit[1]. With this commit, we only keep the bootstrap picker so that it respects the date format based on language, and for the check, to make sure it doesnt break the backend (see ticket from commit[1] for more details), we simply consider the date with year less than 1900 as invalid. We also provide a bit more space for bootstrap datpicker to open while setting the closing date, so that the scrollbar is not introduced on the modal. And for the next activity date, we make sure that the picker is opened always on top of the input (which is not the case currenlty in some screensizes, sometimes it is opened below the input so it is hidden under the extra scroll introduced with picker). commit[1] - https://github.com/odoo/odoo/commit/b2b639b693dd7215e3ee501ac89c35f3a6b88bb5 TaskID-2624728 closes odoo/odoo#77289 X-original-commit: da7cac9b1293a0b8d5375e1b4a470f41fe76e8a4 Signed-off-by: awa-odoo --- .../static/src/js/crm_partner_assign.js | 24 ++++++++++++------- .../website_crm_partner_assign_templates.xml | 8 +++---- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/addons/website_crm_partner_assign/static/src/js/crm_partner_assign.js b/addons/website_crm_partner_assign/static/src/js/crm_partner_assign.js index 3cce848575b..e43d1430579 100644 --- a/addons/website_crm_partner_assign/static/src/js/crm_partner_assign.js +++ b/addons/website_crm_partner_assign/static/src/js/crm_partner_assign.js @@ -15,7 +15,7 @@ publicWidget.registry.crmPartnerAssign = publicWidget.Widget.extend({ 'click .new_opp_confirm': '_onNewOppConfirm', 'click .edit_opp_confirm': '_onEditOppConfirm', 'change .edit_opp_form .next_activity': '_onChangeNextActivity', - 'click div.input-group span.fa-calendar': '_onCalendarIconClick', + 'click div.input-group.date[data-target-input="nearest"]': '_onCalendarInputGroupClick', }, //-------------------------------------------------------------------------- @@ -227,9 +227,7 @@ publicWidget.registry.crmPartnerAssign = publicWidget.Widget.extend({ _onEditOppConfirm: function (ev) { ev.preventDefault(); ev.stopPropagation(); - if ($(".edit_opp_form")[0].checkValidity()) { - this._buttonExec($(ev.currentTarget), this._editOpportunity); - } + this._buttonExec($(ev.currentTarget), this._editOpportunity); }, /** * @private @@ -250,8 +248,9 @@ publicWidget.registry.crmPartnerAssign = publicWidget.Widget.extend({ * @private * @param {Event} ev */ - _onCalendarIconClick: function (ev) { - $(ev.currentTarget).closest('div.date').datetimepicker({ + _onCalendarInputGroupClick: function (ev) { + const $calendarInputGroup = $(ev.currentTarget); + const calendarOptions = { format : time.getLangDateFormat(), icons: { time: 'fa fa-clock-o', @@ -259,13 +258,20 @@ publicWidget.registry.crmPartnerAssign = publicWidget.Widget.extend({ up: 'fa fa-chevron-up', down: 'fa fa-chevron-down', }, - }); + }; + // in some screen sizes, the automatic position opens the picker below input, + // but because #next_activity_div is the last element, we always open the + // picker on top the input to prevent extra scroll + if ($calendarInputGroup.is('#next_activity_div')) { + calendarOptions.widgetPositioning = {vertical: 'top'}; + } + $calendarInputGroup.datetimepicker(calendarOptions); }, _parse_date: function (value) { console.log(value); - var date = moment(value, "YYYY-MM-DD", true); - if (date.isValid()) { + var date = moment(value, time.getLangDateFormat(), true); + if (date.isValid() && date.year() >= 1900) { return time.date_to_str(date.toDate()); } else { diff --git a/addons/website_crm_partner_assign/views/website_crm_partner_assign_templates.xml b/addons/website_crm_partner_assign/views/website_crm_partner_assign_templates.xml index 517e6035613..796dae42fff 100644 --- a/addons/website_crm_partner_assign/views/website_crm_partner_assign_templates.xml +++ b/addons/website_crm_partner_assign/views/website_crm_partner_assign_templates.xml @@ -645,7 +645,7 @@
-
+
-
+
- +
@@ -699,7 +699,7 @@
- +