Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2016-05-04 10:36:25 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2016-05-09 09:51:25 +0300
commitabf8ea1cf8715bfb6f28c4c0f2a924e5e5f8bae2 (patch)
tree225dd9c4c7fbc803744553a9cf1f037db1ab7833
parent8298bb4e6ce049ea04207583ba8b3c914700c952 (diff)
show import button if attachment is of type 'text/calendar'
-rwxr-xr-xcss/mail.css6
-rw-r--r--js/service/attachmentservice.js16
-rw-r--r--js/templates/message-attachment.html3
-rw-r--r--js/views/messageattachment.js31
-rwxr-xr-xlib/controller/messagescontroller.php19
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}}
<img class="attachment-icon" src="{{mimeUrl}}" />
<span class="attachment-name" title="{{fileName}} ({{humanFileSize size}})">{{fileName}} <span class="attachment-size">({{humanFileSize size}})</span></span>
+{{#if isCalendarEvent}}
+<button class="button icon-add attachment-import calendar" title="{{ t 'Import into calendar' }}"></button>
+{{/if}}
<button class="button icon-download attachment-download" title="{{ t 'Download attachment' }}"></button>
<button class="icon-folder attachment-save-to-cloud" title="{{ t 'Save to Files' }}"></button> \ 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';
}
/**