odoo.define('website_profile.website_profile', function (require) { 'use strict'; var publicWidget = require('web.public.widget'); var wysiwygLoader = require('web_editor.loader'); publicWidget.registry.websiteProfile = publicWidget.Widget.extend({ selector: '.o_wprofile_email_validation_container', read_events: { 'click .send_validation_email': '_onSendValidationEmailClick', 'click .validated_email_close': '_onCloseValidatedEmailClick', }, //-------------------------------------------------------------------------- // Handlers //-------------------------------------------------------------------------- /** * @private * @param {Event} ev */ _onSendValidationEmailClick: function (ev) { ev.preventDefault(); var self = this; var $element = $(ev.currentTarget); this._rpc({ route: '/profile/send_validation_email', params: {'redirect_url': $element.data('redirect_url')}, }).then(function (data) { if (data) { self.$('button.validation_email_close').click(); } }); }, /** * @private */ _onCloseValidatedEmailClick: function () { this._rpc({ route: '/profile/validate_email/close', }); }, }); publicWidget.registry.websiteProfileEditor = publicWidget.Widget.extend({ selector: '.o_wprofile_editor_form', read_events: { 'click .o_forum_profile_pic_edit': '_onEditProfilePicClick', 'change .o_forum_file_upload': '_onFileUploadChange', 'click .o_forum_profile_pic_clear': '_onProfilePicClearClick', 'click .o_wprofile_submit_btn': '_onSubmitClick', }, /** * @override */ start: function () { var def = this._super.apply(this, arguments); if (this.editableMode) { return def; } // Warning: Do not activate any option that adds inline style. // Because the style is deleted after save. var toolbar = [ ['style', ['style']], ['font', ['bold', 'italic', 'underline', 'clear']], ['para', ['ul', 'ol', 'paragraph']], ['table', ['table']], ['insert', ['link', 'picture']], ['history', ['undo', 'redo']], ]; var $textarea = this.$('textarea.o_wysiwyg_loader'); var loadProm = wysiwygLoader.load(this, $textarea[0], { toolbar: toolbar, recordInfo: { context: this._getContext(), res_model: 'res.users', res_id: parseInt(this.$('input[name=user_id]').val()), }, disableResizeImage: true, }).then(wysiwyg => { this._wysiwyg = wysiwyg; }); return Promise.all([def, loadProm]); }, //-------------------------------------------------------------------------- // Handlers //-------------------------------------------------------------------------- /** * @private * @param {Event} ev */ _onEditProfilePicClick: function (ev) { ev.preventDefault(); $(ev.currentTarget).closest('form').find('.o_forum_file_upload').trigger('click'); }, /** * @private * @param {Event} ev */ _onFileUploadChange: function (ev) { if (!ev.currentTarget.files.length) { return; } var $form = $(ev.currentTarget).closest('form'); var reader = new window.FileReader(); reader.readAsDataURL(ev.currentTarget.files[0]); reader.onload = function (ev) { $form.find('.o_forum_avatar_img').attr('src', ev.target.result); }; $form.find('#forum_clear_image').remove(); }, /** * @private * @param {Event} ev */ _onProfilePicClearClick: function (ev) { var $form = $(ev.currentTarget).closest('form'); $form.find('.o_forum_avatar_img').attr('src', '/web/static/src/img/placeholder.png'); $form.append($('', { name: 'clear_image', id: 'forum_clear_image', type: 'hidden', })); }, /** * @private */ _onSubmitClick: function () { if (this._wysiwyg) { this._wysiwyg.save(); } }, }); return publicWidget.registry.websiteProfile; });