summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/models/suggested_recipient_info
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/mail/static/src/models/suggested_recipient_info
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/mail/static/src/models/suggested_recipient_info')
-rw-r--r--addons/mail/static/src/models/suggested_recipient_info/suggested_recipient_info.js116
1 files changed, 116 insertions, 0 deletions
diff --git a/addons/mail/static/src/models/suggested_recipient_info/suggested_recipient_info.js b/addons/mail/static/src/models/suggested_recipient_info/suggested_recipient_info.js
new file mode 100644
index 00000000..c8f12856
--- /dev/null
+++ b/addons/mail/static/src/models/suggested_recipient_info/suggested_recipient_info.js
@@ -0,0 +1,116 @@
+odoo.define('mail/static/src/models/suggested_recipient_info/suggested_recipient_info.js', function (require) {
+'use strict';
+
+const { registerNewModel } = require('mail/static/src/model/model_core.js');
+const { attr, many2one } = require('mail/static/src/model/model_field.js');
+
+function factory(dependencies) {
+
+ class SuggestedRecipientInfo extends dependencies['mail.model'] {
+
+ //----------------------------------------------------------------------
+ // private
+ //----------------------------------------------------------------------
+
+ /**
+ * @private
+ * @returns {string}
+ */
+ _computeEmail() {
+ return this.partner && this.partner.email || this.email;
+ }
+
+ /**
+ * Prevents selecting a recipient that does not have a partner.
+ *
+ * @private
+ * @returns {boolean}
+ */
+ _computeIsSelected() {
+ return this.partner ? this.isSelected : false;
+ }
+
+ /**
+ * @private
+ * @returns {string}
+ */
+ _computeName() {
+ return this.partner && this.partner.nameOrDisplayName || this.name;
+ }
+
+ }
+
+ SuggestedRecipientInfo.fields = {
+ /**
+ * Determines the email of `this`. It serves as visual clue when
+ * displaying `this`, and also serves as default partner email when
+ * creating a new partner from `this`.
+ */
+ email: attr({
+ compute: '_computeEmail',
+ dependencies: [
+ 'email',
+ 'partnerEmail',
+ ],
+ }),
+ /**
+ * Determines whether `this` will be added to recipients when posting a
+ * new message on `this.thread`.
+ */
+ isSelected: attr({
+ compute: '_computeIsSelected',
+ default: true,
+ dependencies: [
+ 'isSelected',
+ 'partner',
+ ],
+ }),
+ /**
+ * Determines the name of `this`. It serves as visual clue when
+ * displaying `this`, and also serves as default partner name when
+ * creating a new partner from `this`.
+ */
+ name: attr({
+ compute: '_computeName',
+ dependencies: [
+ 'name',
+ 'partnerNameOrDisplayName',
+ ],
+ }),
+ /**
+ * Determines the optional `mail.partner` associated to `this`.
+ */
+ partner: many2one('mail.partner'),
+ /**
+ * Serves as compute dependency.
+ */
+ partnerEmail: attr({
+ related: 'partner.email'
+ }),
+ /**
+ * Serves as compute dependency.
+ */
+ partnerNameOrDisplayName: attr({
+ related: 'partner.nameOrDisplayName'
+ }),
+ /**
+ * Determines why `this` is a suggestion for `this.thread`. It serves as
+ * visual clue when displaying `this`.
+ */
+ reason: attr(),
+ /**
+ * Determines the `mail.thread` concerned by `this.`
+ */
+ thread: many2one('mail.thread', {
+ inverse: 'suggestedRecipientInfoList',
+ }),
+ };
+
+ SuggestedRecipientInfo.modelName = 'mail.suggested_recipient_info';
+
+ return SuggestedRecipientInfo;
+}
+
+registerNewModel('mail.suggested_recipient_info', factory);
+
+});