From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- .../models/attachment_viewer/attachment_viewer.js | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 addons/mail/static/src/models/attachment_viewer/attachment_viewer.js (limited to 'addons/mail/static/src/models/attachment_viewer') diff --git a/addons/mail/static/src/models/attachment_viewer/attachment_viewer.js b/addons/mail/static/src/models/attachment_viewer/attachment_viewer.js new file mode 100644 index 00000000..8a96946c --- /dev/null +++ b/addons/mail/static/src/models/attachment_viewer/attachment_viewer.js @@ -0,0 +1,59 @@ +odoo.define('mail/static/src/models/attachment_viewer/attachment_viewer.js', function (require) { +'use strict'; + +const { registerNewModel } = require('mail/static/src/model/model_core.js'); +const { attr, many2many, many2one } = require('mail/static/src/model/model_field.js'); + +function factory(dependencies) { + + class AttachmentViewer extends dependencies['mail.model'] { + + //---------------------------------------------------------------------- + // Public + //---------------------------------------------------------------------- + + /** + * Close the attachment viewer by closing its linked dialog. + */ + close() { + const dialog = this.env.models['mail.dialog'].find(dialog => dialog.record === this); + if (dialog) { + dialog.delete(); + } + } + } + + AttachmentViewer.fields = { + /** + * Angle of the image. Changes when the user rotates it. + */ + angle: attr({ + default: 0, + }), + attachment: many2one('mail.attachment'), + attachments: many2many('mail.attachment', { + inverse: 'attachmentViewer', + }), + /** + * Determine whether the image is loading or not. Useful to diplay + * a spinner when loading image initially. + */ + isImageLoading: attr({ + default: false, + }), + /** + * Scale size of the image. Changes when user zooms in/out. + */ + scale: attr({ + default: 1, + }), + }; + + AttachmentViewer.modelName = 'mail.attachment_viewer'; + + return AttachmentViewer; +} + +registerNewModel('mail.attachment_viewer', factory); + +}); -- cgit v1.2.3