2019-09-16 20:42:33 +02:00
|
|
|
import { View } from 'framework/views/view';
|
2019-09-15 14:16:32 +02:00
|
|
|
import { Shortcuts } from 'comp/app/shortcuts';
|
2019-10-06 12:56:44 +02:00
|
|
|
import { Features } from 'util/features';
|
2019-09-16 18:41:06 +02:00
|
|
|
import template from 'templates/details/details-attachment.hbs';
|
2015-10-17 23:49:24 +02:00
|
|
|
|
2019-09-16 18:41:06 +02:00
|
|
|
class DetailsAttachmentView extends View {
|
|
|
|
template = template;
|
2015-10-17 23:49:24 +02:00
|
|
|
|
2019-10-06 12:56:44 +02:00
|
|
|
events = {
|
2020-03-15 12:41:02 +01:00
|
|
|
'click .details__subview-close': 'closeAttachment',
|
2019-10-06 12:56:44 +02:00
|
|
|
'click .details__attachment-preview-download-btn': 'downloadAttachment'
|
|
|
|
};
|
2015-10-17 23:49:24 +02:00
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
render(complete) {
|
2019-10-06 12:56:44 +02:00
|
|
|
super.render({
|
|
|
|
isMobile: Features.isMobile
|
|
|
|
});
|
2017-01-31 07:50:28 +01:00
|
|
|
const shortcut = this.$el.find('.details__attachment-preview-download-text-shortcut');
|
2020-05-09 16:35:11 +02:00
|
|
|
shortcut.text(Shortcuts.actionShortcutSymbol());
|
2019-08-16 23:05:39 +02:00
|
|
|
const blob = new Blob([this.model.getBinary()], { type: this.model.mimeType });
|
2017-01-31 07:50:28 +01:00
|
|
|
const dataEl = this.$el.find('.details__attachment-preview-data');
|
2015-10-17 23:49:24 +02:00
|
|
|
switch ((this.model.mimeType || '').split('/')[0]) {
|
2019-08-18 10:17:09 +02:00
|
|
|
case 'text': {
|
2017-01-31 07:50:28 +01:00
|
|
|
const reader = new FileReader();
|
2016-07-17 13:30:38 +02:00
|
|
|
reader.addEventListener('loadend', () => {
|
2020-06-01 16:53:51 +02:00
|
|
|
$('<pre/>').text(reader.result).appendTo(dataEl);
|
2015-10-17 23:49:24 +02:00
|
|
|
complete();
|
2016-07-17 13:30:38 +02:00
|
|
|
});
|
2015-10-17 23:49:24 +02:00
|
|
|
reader.readAsText(blob);
|
2019-09-16 19:09:57 +02:00
|
|
|
return;
|
2019-08-18 10:17:09 +02:00
|
|
|
}
|
2015-10-17 23:49:24 +02:00
|
|
|
case 'image':
|
2020-06-01 16:53:51 +02:00
|
|
|
$('<img/>').attr('src', URL.createObjectURL(blob)).appendTo(dataEl);
|
2015-10-17 23:49:24 +02:00
|
|
|
complete();
|
2019-09-16 19:09:57 +02:00
|
|
|
return;
|
2015-10-17 23:49:24 +02:00
|
|
|
}
|
|
|
|
this.$el.addClass('details__attachment-preview--empty');
|
|
|
|
this.$el.find('.details__attachment-preview-icon').addClass('fa-' + this.model.icon);
|
|
|
|
complete();
|
|
|
|
}
|
2019-10-06 12:56:44 +02:00
|
|
|
|
|
|
|
downloadAttachment() {
|
|
|
|
this.emit('download');
|
|
|
|
}
|
2020-03-15 12:41:02 +01:00
|
|
|
|
|
|
|
closeAttachment() {
|
|
|
|
this.emit('close');
|
|
|
|
}
|
2019-09-16 18:41:06 +02:00
|
|
|
}
|
2015-10-17 23:49:24 +02:00
|
|
|
|
2019-09-15 14:16:32 +02:00
|
|
|
export { DetailsAttachmentView };
|