summaryrefslogtreecommitdiff
path: root/addons/website_profile/static/src/js
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/website_profile/static/src/js
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/website_profile/static/src/js')
-rw-r--r--addons/website_profile/static/src/js/website_profile.js143
1 files changed, 143 insertions, 0 deletions
diff --git a/addons/website_profile/static/src/js/website_profile.js b/addons/website_profile/static/src/js/website_profile.js
new file mode 100644
index 00000000..105bdb03
--- /dev/null
+++ b/addons/website_profile/static/src/js/website_profile.js
@@ -0,0 +1,143 @@
+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($('<input/>', {
+ name: 'clear_image',
+ id: 'forum_clear_image',
+ type: 'hidden',
+ }));
+ },
+ /**
+ * @private
+ */
+ _onSubmitClick: function () {
+ if (this._wysiwyg) {
+ this._wysiwyg.save();
+ }
+ },
+});
+
+return publicWidget.registry.websiteProfile;
+
+});