{"version":3,"file":"uploadMenuView.js","sources":["../../../../src/io.ox/mail/compose/uploadMenuView.js"],"sourcesContent":["/**\n * @copyright Copyright (c) Open-Xchange GmbH, Germany \n * @license AGPL-3.0\n *\n * This code is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with OX App Suite. If not, see .\n *\n * Any use of the work other than as authorized under this license or copyright law is prohibited.\n */\n\nimport $ from '@/jquery'\nimport _ from '@/underscore'\nimport gt from 'gettext'\nimport Backbone from '@/backbone'\nimport DisposableView from '@/io.ox/backbone/views/disposable'\n\nimport Attachments from '@/io.ox/core/attachments/backbone'\nimport Dropdown from '@/io.ox/backbone/mini-views/dropdown'\nimport { ellipsis } from '@/io.ox/core/util'\nimport Picker from '@/io.ox/files/filepicker'\nimport capabilities from '@/io.ox/core/capabilities'\nimport strings from '@/io.ox/core/strings'\nimport mailAPI from '@/io.ox/mail/api'\nimport accountAPI from '@/io.ox/core/api/account'\nimport { createIcon } from '@/io.ox/core/components'\nimport { handleExceedingLimits, uploadAttachment, attachmentUploadHelper } from '@/io.ox/mail/compose/util'\n\nimport '@/io.ox/files/style.scss'\nimport AttachmentPreview from '@/io.ox/core/attachments/preview'\n\nfunction isValidAttachment (attachment) {\n return attachment.filename && !/\\.(pgp|asc)$/.test(attachment.filename)\n}\n\nfunction isAttached (attachment, model) {\n return !!model.get('attachments').models\n .find(a =>\n a.get('folderId') === attachment.get('folderId') &&\n a.get('mailId') === attachment.get('mailId') &&\n a.get('attachmentId') === attachment.get('attachmentId')\n )\n}\n\n// check if mail is encrypted by guard and there is no easy access to attachments\nfunction isEncrypted (mail) {\n return !!(mail && (mail.security_info?.encrypted || mail.security?.decrypted))\n}\n\nconst UploadMenuView = DisposableView.extend({\n\n initialize (options) {\n this.listView = options.listView\n this.createFromSelection = options.createFromSelection\n this.collection = new Backbone.Collection()\n this.currentSelection = []\n this.recentMails = []\n this.dropdownAttachments = $()\n },\n\n render () {\n const $toggle = $('')\n .attr('aria-label', gt('Add attachments'))\n .append(createIcon('bi/paperclip.svg'))\n .addActionTooltip(gt('Attachments'), { placement: 'top' })\n\n this.dropdown = new Dropdown({\n tagName: 'li',\n attributes: {\n role: 'presentation',\n 'data-extension-id': 'composetoolbar-menu'\n },\n dropup: true,\n $toggle\n })\n\n this.renderDropdownDefaults()\n this.listenTo(this.dropdown, 'open', () => this.updateDropdownAttachments(false))\n this.listenTo(this.model.get('attachments'), 'add remove', attachment => {\n // ignore attachment changes that do not affect the dropdown, as they are not comparable (e.g., forwarding an email with attachments).\n if (!(attachment.get('folderId') || attachment.get('mailId') || attachment.get('attachmentId'))) return\n this.updateDropdownAttachments(true)\n })\n\n if (this.createFromSelection) {\n this.currentSelection = this.listView.selection.get()\n this.getAttachmentsFromMail().then(() => this.addMailAttachment())\n }\n\n return this.dropdown.render().$el.addClass('attachments-dropdown')\n },\n\n renderDropdownDefaults () {\n const $el = $('')\n // render standard attachment option: local\n this.dropdown\n .divider()\n .header(gt('Attachments'))\n .link(\n 'local',\n gt('Add local file'),\n () => { this.addLocalAttachment() },\n { $el }\n )\n\n $el.parent().prepend(\n // multiple is off on smartphones in favor of camera roll/capture selection\n $(``)\n .on('change', attachmentUploadHelper.bind(this, this.model))\n )\n\n // render standard attachment option: drive\n if (capabilities.has('infostore')) {\n this.dropdown\n .link('drive', gt('Add from %1$s', gt.pgettext('app', 'Drive')), () => { this.addDriveAttachment() })\n }\n },\n\n updateDropdownAttachments (onAddOrRemove) {\n if (!this.listView) { return } // DOCS-5021\n\n const selection = this.listView.selection.get()\n\n const selected = selection.length > 0\n const selectedChanged = this.currentSelection.toString() !== selection.toString()\n const recent = selection.length === 0\n const recentChanges = this.listView.recentMails.filter(mail => this.recentMails.filter(recent => recent.id === mail.id && recent.folder_id === mail.folder_id).length === 0)\n const recentChanged = recentChanges.length > 0\n\n this.currentSelection = [].concat(selection)\n this.recentMails = [...this.listView.recentMails]\n\n if ((selected && selectedChanged) || (recent && (recentChanged || selectedChanged))) {\n this.resetDropdownAttachments()\n this.getAttachmentsFromMail().then(hasAttachments => {\n if (!hasAttachments) return\n this.renderDropdownAttachments()\n this.dropdown.resetDimensions().adjustBounds()\n })\n } else if (onAddOrRemove) {\n this.resetDropdownAttachments()\n this.renderDropdownAttachments()\n }\n },\n\n resetDropdownAttachments () {\n const $group = this.dropdown.$ul.find('.attachment-group')\n $group.prev().remove()\n $group.remove()\n },\n\n renderDropdownAttachments () {\n const mailSelected = this.currentSelection.length\n\n const attachments = this.collection.filter(attachment => !isAttached(attachment, this.model))\n if (attachments.length) {\n const text = mailSelected\n // #. Section title for a list of attachments of a selected mail\n ? gt('Files from selected email')\n // #. Section title for a list of attachments of most recently selected mails\n : gt('Most recent attachments')\n\n this.dropdown.$ul.prepend(\n $('
  • ').append(\n $('').text(text)\n ),\n $('