summaryrefslogtreecommitdiff
path: root/addons/snailmail/static/src/js/thread_widget.js
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2020-06-15 18:12:21 +0000
committerSébastien Theys <seb@odoo.com>2020-06-15 18:12:21 +0000
commit3fea5b2136627c1d7e83b2a5e111952fe3eb10a1 (patch)
tree5eefad07972a87ce4689b83260f981bc87aadad4 /addons/snailmail/static/src/js/thread_widget.js
parent0a82848606151ef60eb6523e9c4c161171f214e7 (diff)
[REF] mail, *: refactor messaging with OWL
This commit is a significant rewriting of client-side discuss, chatter, chat window, and messaging menu using OWL. The behavior should be broadly the same, with some slight functional changes here and there. From a technical standpoint, the code of messaging is mainly organized in 2 main groups of modules: - models, which are logical entities that depict the client-side state of messaging as a whole. - components, which are in charge of displaying information from models. This refactoring also introduces new JS guidelines regarding folder structure (/static) and naming rules for JS modules. Community PR: https://github.com/odoo/odoo/pull/39023 Enterprise PR: https://github.com/odoo/enterprise/pull/6249 Task-1914207 This PR is a collaborative work by Alexandre, Julien, Sébastien and Xavier, with the precious help of Lucas to speed it up towards the end. closes odoo/odoo#39023 Related: odoo/enterprise#6249 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com> Co-authored-by: Alexandre Kühn <aku@odoo.com> Co-authored-by: Julien Giannone <jgi@odoo.com> Co-authored-by: Lucas Perais <lpe@odoo.com> Co-authored-by: Sébastien Theys <seb@odoo.com> Co-authored-by: Xavier Dubuc <xdu@odoo.com>
Diffstat (limited to 'addons/snailmail/static/src/js/thread_widget.js')
-rw-r--r--addons/snailmail/static/src/js/thread_widget.js215
1 files changed, 0 insertions, 215 deletions
diff --git a/addons/snailmail/static/src/js/thread_widget.js b/addons/snailmail/static/src/js/thread_widget.js
deleted file mode 100644
index 84ab7f9a877..00000000000
--- a/addons/snailmail/static/src/js/thread_widget.js
+++ /dev/null
@@ -1,215 +0,0 @@
-odoo.define('snailmail.widget.Thread', function (require) {
-"use strict";
-
-var ThreadWidget = require('mail.widget.Thread');
-var Dialog = require('web.Dialog');
-
-var core = require('web.core');
-var _t = core._t;
-
-ThreadWidget.include({
-
- /**
- * @override
- */
- render: function (thread, options) {
- this._super.apply(this, arguments);
- var messages = _.clone(thread.getMessages({ domain: options.domain || [] }));
- this._messages = messages;
- },
-
- //--------------------------------------------------------------------------
- // Private
- //--------------------------------------------------------------------------
-
- /**
- * @private
- * @param {integer} messageID
- * @param {string} content
- */
- _openCreditErrorDialog: function (messageID, content) {
- var message = _.find(this._messages, function (message) {
- return message.getID() === messageID;
- });
- new Dialog(this, {
- size: 'medium',
- title: _t("Failed letter"),
- $content: $('<div>').html(content),
- buttons: [{
- text: _t("Re-send letter"),
- classes: 'btn-primary',
- close: true,
- click: (...args) => message.resendLetter(...args),
- }, {
- text: _t("Cancel letter"),
- close: true,
- click: (...args) => message.cancelLetter(...args),
- }, {
- text: _t("Close"),
- close: true,
- }],
- }).open();
- },
- /**
- * @private
- * @param {integer} messageID
- * @param {string} content
- */
- _openGenericErrorDialog: function (messageID, content) {
- var message = _.find(this._messages, function (message) {
- return message.getID() === messageID;
- });
- new Dialog(this, {
- size: 'medium',
- title: _t("Failed letter"),
- $content: $('<div>').html(content),
- buttons: [{
- text: _t("Cancel letter"),
- classes: 'btn-primary',
- close: true,
- click: (...args) => message.cancelLetter(...args),
- }, {
- text: _t("Close"),
- close: true,
- }],
- }).open();
- },
-
- //--------------------------------------------------------------------------
- // Handlers
- //--------------------------------------------------------------------------
-
- /**
- * @private
- * @param {MouseEvent} event
- */
- _onClickCreditError: function (ev) {
- var self = this;
- var messageID = $(ev.currentTarget).data('message-id');
- this._rpc({
- model: 'iap.account',
- method: 'get_credits_url',
- args: ['snailmail'],
- }).then(function (link) {
- var content = _.str.sprintf(_t(
- '<p>The letter could not be sent due to insufficient credits on your IAP account.</p>' +
- '<div class= "text-right">' +
- '<a class="btn btn-link buy_credits" href=%s target="_blank">' +
- '<i class= "fa fa-arrow-right"/> Buy credits' +
- '</a>' +
- '</div>'
- ), link);
- self._openCreditErrorDialog(messageID, content);
- });
- },
- /**
- * @private
- * @param {MouseEvent} event
- */
- _onClickFormatError: function (ev) {
- var messageID = $(ev.currentTarget).data('message-id');
- this.do_action('snailmail.snailmail_letter_format_error_action', {
- additional_context: {
- message_id: messageID,
- }
- });
- },
- /**
- * Discards the generic error handler since more specific handlers are
- * defined here.
- *
- * @override
- */
- _onClickMessageNotificationError(ev) {
- const $target = $(ev.currentTarget);
- if ($target.data('message-type') === 'snailmail') {
- if ($target.data('failure-type') === 'sn_fields') {
- this._onClickMissingRequiredFields(ev);
- }
- if ($target.data('failure-type') === 'sn_credit') {
- this._onClickCreditError(ev);
- }
- if ($target.data('failure-type') === 'sn_trial') {
- this._onClickTrialError(ev);
- }
- if ($target.data('failure-type') === 'sn_price') {
- this._onClickNoPriceAvailable(ev);
- }
- if ($target.data('failure-type') === 'sn_format') {
- this._onClickFormatError(ev);
- }
- if ($target.data('failure-type') === 'sn_error') {
- this._onClickUnknownError(ev);
- }
- } else {
- this._super(...arguments);
- }
- },
- /**
- * @private
- * @param {MouseEvent} event
- */
- _onClickMissingRequiredFields: function (ev) {
- var self = this;
-
- var messageID = $(ev.currentTarget).data('message-id');
- var domain = [['message_id', '=', messageID]];
- this._rpc({
- model: 'snailmail.letter',
- method: 'search',
- args: [domain],
- }).then(function (letterIds) {
- self.do_action('snailmail.snailmail_letter_missing_required_fields_action', {
- additional_context: {
- letter_id: letterIds[0]
- },
- on_close: function () {
- self.trigger_up('reload');
- }
- });
- });
- },
- /**
- * @private
- * @param {MouseEvent} event
- */
- _onClickNoPriceAvailable: function (ev) {
- var messageID = $(ev.currentTarget).data('message-id');
- var content = _t('<p>The country to which you want to send the letter is not supported by our service.</p>');
- this._openGenericErrorDialog(messageID, content);
- },
- /**
- * @private
- * @param {MouseEvent} event
- */
- _onClickTrialError: function (ev) {
- var self = this;
- var messageID = $(ev.currentTarget).data('message-id');
- this._rpc({
- model: 'iap.account',
- method: 'get_credits_url',
- args: ['snailmail', '', 0, true],
- }).then(function (link) {
- var content = _.str.sprintf(_t(
- '<p>You need credits on your IAP account to send a letter.</p>' +
- '<div class= "text-right">' +
- '<a class="btn btn-link buy_credits" href=%s>' +
- '<i class= "fa fa-arrow-right"/> Buy credits' +
- '</a>' +
- '</div>'
- ), link);
- self._openCreditErrorDialog(messageID, content);
- });
- },
- /**
- * @private
- * @param {MouseEvent} event
- */
- _onClickUnknownError: function (ev) {
- var messageID = $(ev.currentTarget).data('message-id');
- var content = _t('<p>An unknown error occured. Please contact our <a href="https://www.odoo.com/help" target="new">support</a> for further assistance.</p>');
- this._openGenericErrorDialog(messageID, content);
- },
-});
-
-});