From abf8ea1cf8715bfb6f28c4c0f2a924e5e5f8bae2 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 4 May 2016 09:36:25 +0200 Subject: show import button if attachment is of type 'text/calendar' --- css/mail.css | 6 +++++- js/service/attachmentservice.js | 16 ++++++++++++++++ js/templates/message-attachment.html | 3 +++ js/views/messageattachment.js | 31 +++++++++++++++++++++++++++++-- lib/controller/messagescontroller.php | 19 +++++++++++++++++-- 5 files changed, 70 insertions(+), 5 deletions(-) diff --git a/css/mail.css b/css/mail.css index f6aa0b746..8a5172a1c 100755 --- a/css/mail.css +++ b/css/mail.css @@ -663,7 +663,8 @@ input.submit-message, max-height: 120px; } .attachment-save-to-cloud, -.attachment-download { +.attachment-download, +.attachment-import { position: absolute; height: 32px; width: 32px; @@ -675,6 +676,9 @@ input.submit-message, .attachment-download { right: 41px; } +.attachment-import { + right: 79px; +} /* show icon + text for Download all button as well as when there is only one attachment */ .attachments-save-to-cloud, diff --git a/js/service/attachmentservice.js b/js/service/attachmentservice.js index a231e9289..0d21bdfa3 100644 --- a/js/service/attachmentservice.js +++ b/js/service/attachmentservice.js @@ -25,6 +25,7 @@ define(function(require) { var Radio = require('radio'); Radio.message.reply('save:cloud', saveToFiles); + Radio.message.reply('attachment:download', downloadAttachment); /** * @param {Account} account @@ -63,4 +64,19 @@ define(function(require) { return defer.promise(); } + function downloadAttachment(url) { + var defer = $.Deferred(); + + $.ajax(url, { + success: function(data) { + defer.resolve(data); + }, + error: function() { + defer.reject(); + } + }); + + return defer.promise(); + } + }); diff --git a/js/templates/message-attachment.html b/js/templates/message-attachment.html index 9f902ca28..7fab1c1f1 100644 --- a/js/templates/message-attachment.html +++ b/js/templates/message-attachment.html @@ -4,5 +4,8 @@ {{/if}} {{fileName}} ({{humanFileSize size}}) +{{#if isCalendarEvent}} + +{{/if}} \ No newline at end of file diff --git a/js/views/messageattachment.js b/js/views/messageattachment.js index 7746b02d0..4cb80998a 100644 --- a/js/views/messageattachment.js +++ b/js/views/messageattachment.js @@ -23,6 +23,7 @@ define(function(require) { var $ = require('jquery'); var Handlebars = require('handlebars'); var Marionette = require('marionette'); + var Radio = require('radio'); var MessageController = require('controller/messagecontroller'); var MessageAttachmentTemplate = require('text!templates/message-attachment.html'); @@ -33,11 +34,13 @@ define(function(require) { template: Handlebars.compile(MessageAttachmentTemplate), ui: { 'downloadButton': '.attachment-download', - 'saveToCloudButton': '.attachment-save-to-cloud' + 'saveToCloudButton': '.attachment-save-to-cloud', + 'importCalendarEventButton': '.attachment-import.calendar' }, events: { 'click': '_onDownload', - 'click @ui.saveToCloudButton': '_onSaveToCloud' + 'click @ui.saveToCloudButton': '_onSaveToCloud', + 'click @ui.importCalendarEventButton': '_onImportCalendarEvent' }, _onDownload: function(e) { if (!e.isDefaultPrevented()) { @@ -67,6 +70,30 @@ define(function(require) { .removeClass('icon-loading-small') .prop('disabled', false); }); + }, + _onImportCalendarEvent: function(e) { + e.preventDefault(); + + this.ui.importCalendarEventButton + .removeClass('icon-add') + .addClass('icon-loading-small'); + + var url = this.model.get('downloadUrl'); + var downloading = Radio.message.request('attachment:download', url); + + var _this = this; + $.when(downloading).done(function(data) { + console.log(data); + }); + $.when(downloading.fail(function() { + Radio.ui.trigger('error:show', t('Error while downloading calendar event')); + })); + $.when(downloading).always(function() { + _this.ui.importCalendarEventButton + .removeClass('icon-loading-small') + .addClass('icon-add'); + }); + } }); diff --git a/lib/controller/messagescontroller.php b/lib/controller/messagescontroller.php index 1b3ddb168..6bc689b15 100755 --- a/lib/controller/messagescontroller.php +++ b/lib/controller/messagescontroller.php @@ -397,6 +397,8 @@ class MessagesController extends Controller { if ($this->attachmentIsImage($attachment)) { $attachment['isImage'] = true; + } else if ($this->attachmentIsCalendarEvent($attachment)) { + $attachment['isCalendarEvent'] = true; } return $attachment; } @@ -405,11 +407,24 @@ class MessagesController extends Controller { * @param $attachment * * Determines if the content of this attachment is an image + * + * @return boolean */ private function attachmentIsImage($attachment) { - return in_array($attachment['mime'], array('image/jpeg', + return in_array( + $attachment['mime'], [ + 'image/jpeg', 'image/png', - 'image/gif')); + 'image/gif' + ]); + } + + /** + * @param type $attachment + * @return boolean + */ + private function attachmentIsCalendarEvent($attachment) { + return $attachment['mime'] === 'text/calendar'; } /** -- cgit v1.2.3