summaryrefslogtreecommitdiff
path: root/addons/website_mail_channel/static
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_mail_channel/static
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/website_mail_channel/static')
-rw-r--r--addons/website_mail_channel/static/description/icon.pngbin0 -> 7319 bytes
-rw-r--r--addons/website_mail_channel/static/description/icon.svg1
-rw-r--r--addons/website_mail_channel/static/src/css/website_mail_channel.css7
-rw-r--r--addons/website_mail_channel/static/src/js/website_mail_channel.js71
-rw-r--r--addons/website_mail_channel/static/src/snippets/s_channel/000.js148
-rw-r--r--addons/website_mail_channel/static/src/snippets/s_channel/options.js107
6 files changed, 334 insertions, 0 deletions
diff --git a/addons/website_mail_channel/static/description/icon.png b/addons/website_mail_channel/static/description/icon.png
new file mode 100644
index 00000000..2c737fbe
--- /dev/null
+++ b/addons/website_mail_channel/static/description/icon.png
Binary files differ
diff --git a/addons/website_mail_channel/static/description/icon.svg b/addons/website_mail_channel/static/description/icon.svg
new file mode 100644
index 00000000..779be805
--- /dev/null
+++ b/addons/website_mail_channel/static/description/icon.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="70" height="70" viewBox="0 0 70 70"><defs><path id="a" d="M4 0h61c4 0 5 1 5 5v60c0 4-1 5-5 5H4c-3 0-4-1-4-5V5c0-4 1-5 4-5z"/><linearGradient id="c" x1="100%" x2="0%" y1="0%" y2="100%"><stop offset="0%" stop-color="#CD7690"/><stop offset="100%" stop-color="#CA5377"/></linearGradient></defs><g fill="none" fill-rule="evenodd"><mask id="b" fill="#fff"><use xlink:href="#a"/></mask><g mask="url(#b)"><path fill="url(#c)" d="M0 0H70V70H0z"/><path fill="#FFF" fill-opacity=".383" d="M4 1h61c2.667 0 4.333.667 5 2V0H0v3c.667-1.333 2-2 4-2z"/><path fill="#393939" d="M42.474 69H4c-2 0-4-.146-4-4.075V39.178L21 15h30l-2 6.113h3l-3 5.095h6l-5 10.188 4.213 1.034L53 54.736 42.474 69z" opacity=".324"/><path fill="#000" fill-opacity=".383" d="M4 69h61c2.667 0 4.333-1 5-3v4H0v-4c.667 2 2 3 4 3z"/><path fill="#000" d="M15 36.646h12.813l2.562 3.416h10.25l3.417-3.416H56l-2.563 19.646H17.563L15 36.646zm.854-10.25h39.292v7.687h-5.98v-3.416H20.98v3.416h-5.125v-7.687zm2.563-5.125h34.166v3.416H18.417v-3.416zM20.979 17h29.896v2.563H20.979V17z" opacity=".3"/><path fill="#FFF" d="M15 34.646h12.813l2.562 3.416h10.25l3.417-3.416H56l-2.563 19.646H17.563L15 34.646zm.854-10.25h39.292v7.687h-5.98v-3.416H20.98v3.416h-5.125v-7.687zm2.563-5.125h34.166v3.416H18.417v-3.416zM20.979 15h29.896v2.563H20.979V15z"/></g></g></svg> \ No newline at end of file
diff --git a/addons/website_mail_channel/static/src/css/website_mail_channel.css b/addons/website_mail_channel/static/src/css/website_mail_channel.css
new file mode 100644
index 00000000..2365860f
--- /dev/null
+++ b/addons/website_mail_channel/static/src/css/website_mail_channel.css
@@ -0,0 +1,7 @@
+.o_mg_link_show {
+ display: none;
+}
+
+.o_mg_link_content {
+ display: none;
+}
diff --git a/addons/website_mail_channel/static/src/js/website_mail_channel.js b/addons/website_mail_channel/static/src/js/website_mail_channel.js
new file mode 100644
index 00000000..30928d78
--- /dev/null
+++ b/addons/website_mail_channel/static/src/js/website_mail_channel.js
@@ -0,0 +1,71 @@
+odoo.define('website_mail_channel', function (require) {
+'use strict';
+
+var publicWidget = require('web.public.widget');
+
+publicWidget.registry.websiteMailChannel = publicWidget.Widget.extend({
+ selector: '#wrapwrap',
+ events: {
+ 'click .o_mg_link_hide': '_onHideLinkClick',
+ 'click .o_mg_link_show': '_onShowLinkClick',
+ 'click button.o_mg_read_more': '_onReadMoreClick',
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ * @param {Event} ev
+ */
+ _onHideLinkClick: function (ev) {
+ ev.preventDefault();
+ ev.stopPropagation();
+ var $link = $(ev.currentTarget);
+ var $container = $link.parents('div').first();
+ $container.find('.o_mg_link_hide').first().hide();
+ $container.find('.o_mg_link_show').first().show();
+ $container.find('.o_mg_link_content').first().show();
+ },
+ /**
+ * @private
+ * @param {Event} ev
+ */
+ _onShowLinkClick: function (ev) {
+ ev.preventDefault();
+ ev.stopPropagation();
+ var $link = $(ev.currentTarget);
+ var $container = $link.parents('div').first();
+ $container.find('.o_mg_link_hide').first().show();
+ $container.find('.o_mg_link_show').first().hide();
+ $container.find('.o_mg_link_content').first().hide();
+ },
+ /**
+ * @private
+ * @param {Event} ev
+ */
+ _onReadMoreClick: function (ev) {
+ var $link = $(ev.target);
+ this._rpc({
+ route: $link.data('href'),
+ params: {
+ last_displayed_id: $link.data('msg-id'),
+ },
+ }).then(function (data) {
+ if (!data) {
+ return;
+ }
+ var $threadContainer = $link.parents('.o_mg_replies').first().find('ul.list-unstyled');
+ if ($threadContainer) {
+ var $lastMsg = $threadContainer.find('li.media').last();
+ $(data).find('li.media').insertAfter($lastMsg);
+ $(data).find('.o_mg_read_more').parent().appendTo($threadContainer);
+ }
+ var $showMore = $link.parent();
+ $showMore.remove();
+ return;
+ });
+ },
+});
+});
diff --git a/addons/website_mail_channel/static/src/snippets/s_channel/000.js b/addons/website_mail_channel/static/src/snippets/s_channel/000.js
new file mode 100644
index 00000000..afcd22c6
--- /dev/null
+++ b/addons/website_mail_channel/static/src/snippets/s_channel/000.js
@@ -0,0 +1,148 @@
+odoo.define('website_mail_channel.s_channel', function (require) {
+'use strict';
+
+var publicWidget = require('web.public.widget');
+
+publicWidget.registry.Channel = publicWidget.Widget.extend({
+ selector: '.s_channel',
+ disabledInEditableMode: false,
+ read_events: {
+ 'click .js_follow_btn, .js_unfollow_btn': '_onFollowUnFollowBtnClick',
+ 'click .js_follow_btn': '_onFollowBtnClick',
+ },
+
+ /**
+ * @override
+ */
+ start: function () {
+ var self = this;
+ this.is_user = false;
+ var unsubscribePage = window.location.search.slice(1).split('&').indexOf("unsubscribe") >= 0;
+
+ var always = function (data) {
+ self.is_user = data.is_user;
+ self.email = data.email;
+ self.$target.find('.js_mg_link').attr('href', '/groups/' + self.$target.data('id'));
+ if (unsubscribePage && self.is_user) {
+ self.$target.find(".js_mg_follow_form").remove();
+ }
+ self._toggleSubscription(data.is_member ? 'on' : 'off', data.email);
+ self.$target.removeClass('d-none');
+ };
+
+ this._rpc({
+ route: '/groups/is_member',
+ params: {
+ model: this.$target.data('object'),
+ channel_id: this.$target.data('id'),
+ get_alias_info: true,
+ },
+ }).then(always).guardedCatch(always);
+
+ // not if editable mode to allow designer to edit alert field
+ if (!this.editableMode) {
+ this.$('> .alert').addClass('d-none');
+ this.$('> .input-group-append.d-none').removeClass('d-none');
+ }
+ return this._super.apply(this, arguments);
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ */
+ _getAliasInfo: function () {
+ var self = this;
+ if (! this.$target.data('id')) {
+ return Promise.resolve();
+ }
+ return this._rpc({route: '/groups/' + this.$target.data('id') + '/get_alias_info'}).then(function (data) {
+ if (data.alias_name) {
+ self.$target.find('.js_mg_email').attr('href', 'mailto:' + data.alias_name);
+ self.$target.find('.js_mg_email').removeClass('d-none');
+ } else {
+ self.$target.find('.js_mg_email').addClass('d-none');
+ }
+ });
+ },
+ /**
+ * @private
+ */
+ _toggleSubscription: function (follow, email) {
+ // .js_mg_follow_form contains subscribe form
+ // .js_mg_details contains send/archives/unsubscribe links
+ // .js_mg_confirmation contains message warning has been sent
+ var aliasDone = this._getAliasInfo();
+ if (follow === "on") {
+ // user is connected and can unsubscribe
+ this.$target.find(".js_mg_follow_form").addClass('d-none');
+ this.$target.find(".js_mg_details").removeClass('d-none');
+ this.$target.find(".js_mg_confirmation").addClass('d-none');
+ } else if (follow === "off") {
+ // user is connected and can subscribe
+ this.$target.find(".js_mg_follow_form").removeClass('d-none');
+ this.$target.find(".js_mg_details").addClass('d-none');
+ this.$target.find(".js_mg_confirmation").addClass('d-none');
+ } else if (follow === "email") {
+ // a confirmation email has been sent
+ this.$target.find(".js_mg_follow_form").addClass('d-none');
+ this.$target.find(".js_mg_details").addClass('d-none');
+ this.$target.find(".js_mg_confirmation").removeClass('d-none');
+ } else {
+ console.error("Unknown subscription action", follow);
+ }
+ this.$target.find('input.js_follow_email')
+ .val(email ? email : "")
+ .attr("disabled", follow === "on" || (email.length && this.is_user) ? "disabled" : false);
+ this.$target.attr("data-follow", follow);
+ return Promise.resolve(aliasDone);
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ */
+ _onFollowBtnClick: function (ev) {
+ if ($(ev.currentTarget).closest('.js_mg_follow_form').length) {
+ this.$('.js_follow_email').val($(ev.currentTarget).closest('.js_mg_follow_form').find('.js_follow_email').val());
+ }
+ },
+ /**
+ * @private
+ */
+ _onFollowUnFollowBtnClick: function (ev) {
+ ev.preventDefault();
+ var self = this;
+ var $email = this.$target.find(".js_follow_email");
+
+ if ($email.length && !$email.val().match(/.+@.+/)) {
+ this.$target.addClass('o_has_error').find('.form-control, .custom-select').addClass('is-invalid');
+ return false;
+ }
+ this.$target.removeClass('o_has_error').find('.form-control, .custom-select').removeClass('is-invalid');
+
+ var subscriptionAction = this.$target.attr("data-follow") || "off";
+ if (window.location.search.slice(1).split('&').indexOf("unsubscribe") >= 0) {
+ // force unsubscribe mode via URI /groups?unsubscribe
+ subscriptionAction = 'on';
+ }
+ this._rpc({
+ route: '/groups/subscription',
+ params: {
+ 'channel_id': +this.$target.data('id'),
+ 'object': this.$target.data('object'),
+ 'subscription': subscriptionAction,
+ 'email': $email.length ? $email.val() : false,
+ },
+ }).then(function (follow) {
+ self._toggleSubscription(follow, self.email);
+ });
+ },
+});
+});
diff --git a/addons/website_mail_channel/static/src/snippets/s_channel/options.js b/addons/website_mail_channel/static/src/snippets/s_channel/options.js
new file mode 100644
index 00000000..5b51bb6a
--- /dev/null
+++ b/addons/website_mail_channel/static/src/snippets/s_channel/options.js
@@ -0,0 +1,107 @@
+odoo.define('website_mail_channel.s_channel_options', function (require) {
+'use strict';
+
+var core = require('web.core');
+var options = require('web_editor.snippets.options');
+var wUtils = require('website.utils');
+
+var _t = core._t;
+
+options.registry.Channel = options.Class.extend({
+ /**
+ * @override
+ */
+ async start() {
+ await this._super(...arguments);
+ this.publicChannels = await this._getPublicChannels();
+ },
+ /**
+ * @override
+ */
+ cleanForSave: function () {
+ this.$target.addClass('d-none');
+ },
+ /**
+ * If we have already created channels => select the first one
+ * else => modal prompt (create a new channel)
+ *
+ * @override
+ */
+ onBuilt() {
+ if (this.publicChannels.length) {
+ this.$target[0].dataset.id = this.publicChannels[0][0];
+ } else {
+ const widget = this._requestUserValueWidgets('create_mail_channel_opt')[0];
+ widget.$el.click();
+ }
+ },
+
+ //--------------------------------------------------------------------------
+ // Options
+ //--------------------------------------------------------------------------
+
+ /**
+ * Creates a new mail.channel through a modal prompt.
+ *
+ * @see this.selectClass for parameters
+ */
+ createChannel: function (previewMode, widgetValue, params) {
+ var self = this;
+ return wUtils.prompt({
+ id: "editor_new_mail_channel_subscribe",
+ window_title: _t("New Mail Channel"),
+ input: _t("Name"),
+ }).then(function (result) {
+ var name = result.val;
+ if (!name) {
+ return;
+ }
+ return self._rpc({
+ model: 'mail.channel',
+ method: 'create',
+ args: [{
+ name: name,
+ public: 'public',
+ }],
+ }).then(function (id) {
+ self.$target.attr("data-id", id);
+ return self._rerenderXML();
+ });
+ });
+ },
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @override
+ */
+ _renderCustomXML(uiFragment) {
+ // TODO remove this part in master
+ const createChannelEl = uiFragment.querySelector('we-button[data-create-channel]');
+ createChannelEl.dataset.name = 'create_mail_channel_opt';
+
+ return this._getPublicChannels().then(channels => {
+ const menuEl = uiFragment.querySelector('.select_discussion_list');
+ for (const channel of channels) {
+ const el = document.createElement('we-button');
+ el.dataset.selectDataAttribute = channel[0];
+ el.textContent = channel[1];
+ menuEl.appendChild(el);
+ }
+ });
+ },
+ /**
+ * @private
+ * @return {Promise}
+ */
+ _getPublicChannels() {
+ return this._rpc({
+ model: 'mail.channel',
+ method: 'name_search',
+ args: ['', [['public', '=', 'public']]],
+ });
+ },
+});
+});