diff --git a/addons/auth_totp_portal/static/src/js/totp_frontend.js b/addons/auth_totp_portal/static/src/js/totp_frontend.js index 0f1d1b6ee2d..0defc7591c5 100644 --- a/addons/auth_totp_portal/static/src/js/totp_frontend.js +++ b/addons/auth_totp_portal/static/src/js/totp_frontend.js @@ -1,9 +1,10 @@ /** @odoo-module **/ import { _t } from "@web/core/l10n/translation"; +import { markup } from "@odoo/owl"; +import { InputConfirmationDialog } from "@portal/js/components/input_confirmation_dialog/input_confirmation_dialog"; +import { handleCheckIdentity } from "@portal/js/portal_security"; import publicWidget from "@web/legacy/js/public/public_widget"; -import Dialog from "@web/legacy/js/core/dialog"; -import {handleCheckIdentity} from "@portal/js/portal_security"; /** * Replaces specific elements by normal HTML, strip out the rest entirely @@ -131,67 +132,6 @@ function fixupViewBody(oldNode, record) { return [node, qrcode, code] } -/** - * Converts a backend + + + + + + + + + + + + diff --git a/addons/website_slides/static/src/js/slides_category_add.js b/addons/website_slides/static/src/js/slides_category_add.js index 35494e3c3e8..b79155bc6d4 100644 --- a/addons/website_slides/static/src/js/slides_category_add.js +++ b/addons/website_slides/static/src/js/slides_category_add.js @@ -1,68 +1,8 @@ /** @odoo-module **/ -import publicWidget from '@web/legacy/js/public/public_widget'; -import Dialog from '@web/legacy/js/core/dialog'; import { _t } from "@web/core/l10n/translation"; - -var CategoryAddDialog = Dialog.extend({ - template: 'slides.category.add', - events: Object.assign( - { "submit form#slide_category_add_form": "_onClickFormSubmit" }, - Dialog.events - ), - - /** - * @override - */ - init: function (parent, options) { - options = Object.assign({ - title: _t('Add a section'), - size: 'medium', - buttons: [{ - text: _t('Save'), - classes: 'btn-primary o_js_website_slides_add_category_btn', - click: this._onClickFormSubmit.bind(this), - }, { - text: _t('Back'), - close: true - }] - }, options || {}); - - this.csrf_token = odoo.csrf_token; - this.channelId = options.channelId; - this._super(parent, options); - }, - - //-------------------------------------------------------------------------- - // Private - //-------------------------------------------------------------------------- - - _formValidate: function ($form) { - $form.addClass('was-validated'); - return $form[0].checkValidity(); - }, - - //-------------------------------------------------------------------------- - // Handlers - //-------------------------------------------------------------------------- - - /** - * Handle form submission on click button or press ENTER key. Prevent multiple submissions - * @private - * @param {Event} ev - */ - _onClickFormSubmit: function (ev) { - ev.preventDefault(); - const form = document.getElementById("slide_category_add_form"); - if (!form.classList.contains("o_js_website_slides_form_submitted")) { - if (this._formValidate($(form))) { - form.classList.add("o_js_website_slides_form_submitted"); - document.querySelector("button.o_js_website_slides_add_category_btn").disabled = true; - form.submit(); - } - } - }, -}); +import publicWidget from '@web/legacy/js/public/public_widget'; +import { CategoryAddDialog } from "@website_slides/js/public/components/category_add_dialog/category_add_dialog"; publicWidget.registry.websiteSlidesCategoryAdd = publicWidget.Widget.extend({ selector: '.o_wslides_js_slide_section_add', @@ -75,7 +15,21 @@ publicWidget.registry.websiteSlidesCategoryAdd = publicWidget.Widget.extend({ //-------------------------------------------------------------------------- _openDialog: function (channelId) { - new CategoryAddDialog(this, {channelId: channelId}).open(); + this.call("dialog", "add", CategoryAddDialog, { + title: _t("Add a section"), + confirmLabel: _t("Save"), + confirm: ({ formEl }) => { + if (!formEl.checkValidity()) { + return false; + } + formEl.classList.add("was-validated"); + formEl.submit(); + return true; + }, + cancelLabel: _t("Back"), + cancel: () => {}, + channelId, + }); }, //-------------------------------------------------------------------------- @@ -93,6 +47,5 @@ publicWidget.registry.websiteSlidesCategoryAdd = publicWidget.Widget.extend({ }); export default { - categoryAddDialog: CategoryAddDialog, websiteSlidesCategoryAdd: publicWidget.registry.websiteSlidesCategoryAdd }; diff --git a/addons/website_slides/static/src/js/slides_category_delete.js b/addons/website_slides/static/src/js/slides_category_delete.js index 15913f8228b..700d9c36517 100644 --- a/addons/website_slides/static/src/js/slides_category_delete.js +++ b/addons/website_slides/static/src/js/slides_category_delete.js @@ -1,58 +1,13 @@ /** @odoo-module **/ -import publicWidget from '@web/legacy/js/public/public_widget'; -import Dialog from '@web/legacy/js/core/dialog'; +import { ConfirmationDialog } from "@web/core/confirmation_dialog/confirmation_dialog"; +import publicWidget from "@web/legacy/js/public/public_widget"; import { _t } from "@web/core/l10n/translation"; -const categoryDeleteDialog = Dialog.extend({ - template: 'slides.category.delete', - - /** - * @constructor - * @param {Widget} parent - * @param {DOM Object} slideTarget - */ - init(parent, slideTarget) { - this.categoryId = parseInt(slideTarget.dataset.categoryId); - this._super(parent, { - title: _t('Delete Category'), - size: 'medium', - buttons: [{ - text: _t('Delete'), - classes: 'btn-primary', - click: () => this._onClickDelete(), - }, { - text: _t('Cancel'), - close: true - }] - }); - }, - - //-------------------------------------------------------------------------- - // Handlers - //-------------------------------------------------------------------------- - - /** - * Calls 'unlink' method on slides.slide to delete the category and - * reloads page after deletion to re-arrange the content on UI - * - * @private - */ - _onClickDelete() { - this._rpc({ - model: 'slide.slide', - method: 'unlink', - args: [this.categoryId], - }).then(function () { - window.location.reload(); - }); - } -}); - publicWidget.registry.websiteSlidesCategoryDelete = publicWidget.Widget.extend({ - selector: '.o_wslides_js_category_delete', + selector: ".o_wslides_js_category_delete", events: { - 'click': '_onClickDeleteCateogry', + click: "_onClickDeleteCateogry", }, //-------------------------------------------------------------------------- @@ -64,11 +19,28 @@ publicWidget.registry.websiteSlidesCategoryDelete = publicWidget.Widget.extend({ * @param {MouseEvent} ev */ _onClickDeleteCateogry(ev) { - new categoryDeleteDialog(this, ev.currentTarget).open(); + const categoryId = parseInt(ev.currentTarget.dataset.categoryId); + this.call("dialog", "add", ConfirmationDialog, { + title: _t("Delete Category"), + body: _t("Are you sure you want to delete this category?"), + confirmLabel: _t("Delete"), + confirm: async () => { + /** + * Calls 'unlink' method on slides.slide to delete the category and + * reloads page after deletion to re-arrange the content on UI + */ + await this._rpc({ + model: "slide.slide", + method: "unlink", + args: [categoryId], + }); + window.location.reload(); + }, + cancel: () => {}, + }); }, }); export default { - categoryDeleteDialog: categoryDeleteDialog, - websiteSlidesCategoryDelete: publicWidget.registry.websiteSlidesCategoryDelete + websiteSlidesCategoryDelete: publicWidget.registry.websiteSlidesCategoryDelete, }; diff --git a/addons/website_slides/static/src/js/slides_course_unsubscribe.js b/addons/website_slides/static/src/js/slides_course_unsubscribe.js index 81af04aeba6..07e9dd0e34c 100644 --- a/addons/website_slides/static/src/js/slides_course_unsubscribe.js +++ b/addons/website_slides/static/src/js/slides_course_unsubscribe.js @@ -1,135 +1,7 @@ /** @odoo-module **/ -import Dialog from '@web/legacy/js/core/dialog'; import publicWidget from '@web/legacy/js/public/public_widget'; -import { _t } from "@web/core/l10n/translation"; -import { renderToElement } from "@web/core/utils/render"; - -var SlideUnsubscribeDialog = Dialog.extend({ - template: 'slides.course.unsubscribe.modal', - _texts: { - titleSubscribe: _t("Subscribe"), - titleUnsubscribe: _t("Notifications"), - titleLeaveCourse: _t("Leave the course") - }, - - /** - * @override - * @param {Object} parent - * @param {Object} options - */ - init: function (parent, options) { - options = Object.assign({ - title: options.isFollower === 'True' ? this._texts.titleSubscribe : this._texts.titleUnsubscribe, - size: 'medium', - }, options || {}); - this._super(parent, options); - - this.set('state', '_subscription'); - this.on('change:state', this, this._onChangeType); - - this.channelID = parseInt(options.channelId, 10); - this.isFollower = options.isFollower === 'True'; - this.enroll = options.enroll; - this.visibility = options.visibility; - }, - /** - * @override - */ - start: function () { - var self = this; - return this._super.apply(this, arguments).then(function () { - self.$('input#subscribed').prop('checked', self.isFollower); - self._resetModal(); - }); - }, - - getSubscriptionState: function () { - return this.$('input#subscribed').prop('checked'); - }, - - //-------------------------------------------------------------------------- - // Private - //-------------------------------------------------------------------------- - _getModalButtons: function () { - var btnList = []; - var state = this.get('state'); - if (state === '_subscription') { - btnList.push({text: _t("Save"), classes: "btn-primary", click: this._onClickSubscriptionSubmit.bind(this)}); - btnList.push({text: _t("Discard"), close: true}); - btnList.push({text: _t("or Leave the course"), classes: "btn-danger ms-auto", click: this._onClickLeaveCourse.bind(this)}); - } else if (state === '_leave') { - btnList.push({text: _t("Leave the course"), classes: "btn-danger", click: this._onClickLeaveCourseSubmit.bind(this)}); - btnList.push({text: _t("Discard"), click: this._onClickLeaveCourseCancel.bind(this)}); - } - return btnList; - }, - - /** - * @private - */ - _resetModal: function () { - var state = this.get('state'); - if (state === '_subscription') { - this.set_title(this.isFollower ? this._texts.titleUnsubscribe : this._texts.titleSubscribe); - this.$('input#subscribed').prop('checked', this.isFollower); - } - else if (state === '_leave') { - this.set_title(this._texts.titleLeaveCourse); - } - this.set_buttons(this._getModalButtons()); - }, - - //-------------------------------------------------------------------------- - // Handler - //-------------------------------------------------------------------------- - _onClickLeaveCourse: function () { - this.set('state', '_leave'); - }, - - _onClickLeaveCourseCancel: function () { - this.set('state', '_subscription'); - }, - - _onClickLeaveCourseSubmit: async function () { - await this._rpc({ - route: '/slides/channel/leave', - params: {channel_id: this.channelID}, - }); - if (this.visibility === 'public' || this.visibility === 'connected') { - window.location.reload(); - } else { - window.location.href = '/slides'; - } - }, - - _onClickSubscriptionSubmit: function () { - if (this.isFollower === this.getSubscriptionState()) { - this.destroy(); - return; - } - this._rpc({ - route: this.getSubscriptionState() ? '/slides/channel/subscribe' : '/slides/channel/unsubscribe', - params: {channel_id: this.channelID}, - }).then(function () { - window.location.reload(); - }); - }, - - _onChangeType: function () { - var currentType = this.get('state'); - var tmpl; - if (currentType === '_subscription') { - tmpl = 'slides.course.unsubscribe.modal.subscription'; - } else if (currentType === '_leave') { - tmpl = 'slides.course.unsubscribe.modal.leave'; - } - this.$('.o_w_slide_unsubscribe_modal_container').empty(); - this.$('.o_w_slide_unsubscribe_modal_container').append(renderToElement(tmpl, {widget: this})); - - this._resetModal(); - }, -}); +import { SlideUnsubscribeDialog } from "./public/components/slide_unsubscribe_dialog/slide_unsubscribe_dialog"; publicWidget.registry.websiteSlidesUnsubscribe = publicWidget.Widget.extend({ selector: '.o_wslides_js_channel_unsubscribe', @@ -142,7 +14,7 @@ publicWidget.registry.websiteSlidesUnsubscribe = publicWidget.Widget.extend({ _openDialog: function ($element) { var data = $element.data(); - return new SlideUnsubscribeDialog(this, data).open(); + this.call("dialog", "add", SlideUnsubscribeDialog, data); }, //-------------------------------------------------------------------------- @@ -160,6 +32,5 @@ publicWidget.registry.websiteSlidesUnsubscribe = publicWidget.Widget.extend({ }); export default { - SlideUnsubscribeDialog: SlideUnsubscribeDialog, websiteSlidesUnsubscribe: publicWidget.registry.websiteSlidesUnsubscribe }; diff --git a/addons/website_slides/static/src/js/slides_slide_archive.js b/addons/website_slides/static/src/js/slides_slide_archive.js index 90a5c522a3d..0d1bebe1fb2 100644 --- a/addons/website_slides/static/src/js/slides_slide_archive.js +++ b/addons/website_slides/static/src/js/slides_slide_archive.js @@ -1,77 +1,13 @@ /** @odoo-module **/ -import publicWidget from '@web/legacy/js/public/public_widget'; -import Dialog from '@web/legacy/js/core/dialog'; +import { ConfirmationDialog } from "@web/core/confirmation_dialog/confirmation_dialog"; import { _t } from "@web/core/l10n/translation"; - -var SlideArchiveDialog = Dialog.extend({ - template: 'slides.slide.archive', - - /** - * @override - */ - init: function (parent, options) { - options = Object.assign({ - title: _t('Archive Content'), - size: 'medium', - buttons: [{ - text: _t('Archive'), - classes: 'btn-primary', - click: this._onClickArchive.bind(this) - }, { - text: _t('Cancel'), - close: true - }] - }, options || {}); - - this.$slideTarget = options.slideTarget; - this.slideId = this.$slideTarget.data('slideId'); - this._super(parent, options); - }, - _checkForEmptySections: function (){ - $('.o_wslides_slide_list_category').each(function (){ - var $categoryHeader = $(this).find('.o_wslides_slide_list_category_header'); - var categorySlideCount = $(this).find('.o_wslides_slides_list_slide:not(.o_not_editable)').length; - var $emptyFlagContainer = $categoryHeader.find('.o_wslides_slides_list_drag').first(); - var $emptyFlag = $emptyFlagContainer.find('small'); - if (categorySlideCount === 0 && $emptyFlag.length === 0){ - $emptyFlagContainer.append($('', { - 'class': "ms-1 text-muted fw-bold", - text: _t("(empty)") - })); - } - }); - }, - - //-------------------------------------------------------------------------- - // Handlers - //-------------------------------------------------------------------------- - - /** - * Calls 'archive' on slide controller and then visually removes the slide dom element - */ - _onClickArchive: function () { - var self = this; - - this._rpc({ - route: '/slides/slide/archive', - params: { - slide_id: this.slideId - }, - }).then(function (isArchived) { - if (isArchived){ - self.$slideTarget.closest('.o_wslides_slides_list_slide').remove(); - self._checkForEmptySections(); - } - self.close(); - }); - } -}); +import publicWidget from "@web/legacy/js/public/public_widget"; publicWidget.registry.websiteSlidesSlideArchive = publicWidget.Widget.extend({ - selector: '.o_wslides_js_slide_archive', + selector: ".o_wslides_js_slide_archive", events: { - 'click': '_onArchiveSlideClick', + click: "_onArchiveSlideClick", }, //-------------------------------------------------------------------------- @@ -79,7 +15,45 @@ publicWidget.registry.websiteSlidesSlideArchive = publicWidget.Widget.extend({ //-------------------------------------------------------------------------- _openDialog: function ($slideTarget) { - new SlideArchiveDialog(this, {slideTarget: $slideTarget}).open(); + const slideId = $slideTarget.data("slideId"); + this.call("dialog", "add", ConfirmationDialog, { + title: _t("Archive Content"), + body: _t("Are you sure you want to archive this content?"), + confirmLabel: _t("Archive"), + confirm: async () => { + /** + * Calls 'archive' on slide controller and then visually removes the slide dom element + */ + const isArchived = await this._rpc({ + route: "/slides/slide/archive", + params: { + slide_id: slideId, + }, + }); + if (isArchived) { + $slideTarget.closest(".o_wslides_slides_list_slide").remove(); + $(".o_wslides_slide_list_category").each(function () { + var $categoryHeader = $(this).find(".o_wslides_slide_list_category_header"); + var categorySlideCount = $(this).find( + ".o_wslides_slides_list_slide:not(.o_not_editable)" + ).length; + var $emptyFlagContainer = $categoryHeader + .find(".o_wslides_slides_list_drag") + .first(); + var $emptyFlag = $emptyFlagContainer.find("small"); + if (categorySlideCount === 0 && $emptyFlag.length === 0) { + $emptyFlagContainer.append( + $("", { + class: "ms-1 text-muted fw-bold", + text: _t("(empty)"), + }) + ); + } + }); + } + }, + cancel: () => {}, + }); }, //-------------------------------------------------------------------------- @@ -98,6 +72,5 @@ publicWidget.registry.websiteSlidesSlideArchive = publicWidget.Widget.extend({ }); export default { - slideArchiveDialog: SlideArchiveDialog, - websiteSlidesSlideArchive: publicWidget.registry.websiteSlidesSlideArchive + websiteSlidesSlideArchive: publicWidget.registry.websiteSlidesSlideArchive, }; diff --git a/addons/website_slides/static/src/xml/slide_management.xml b/addons/website_slides/static/src/xml/slide_management.xml index 59a04ff972e..d8bfffd3a2b 100644 --- a/addons/website_slides/static/src/xml/slide_management.xml +++ b/addons/website_slides/static/src/xml/slide_management.xml @@ -13,19 +13,4 @@ - -
-
- - -
- -
- -
-
-
-
-
- diff --git a/addons/website_slides/static/src/xml/website_slides_unsubscribe.xml b/addons/website_slides/static/src/xml/website_slides_unsubscribe.xml deleted file mode 100644 index 97470c81b49..00000000000 --- a/addons/website_slides/static/src/xml/website_slides_unsubscribe.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - -
-
- -
-
-
- - -
-
- - -
-
-
- - -

Do you really want to leave the course?

-

All progress will be lost until you rejoin this course.

-
- -