2019-09-16 18:41:06 +02:00
|
|
|
import { View } from 'view-engine/view';
|
2019-09-15 14:16:32 +02:00
|
|
|
import { Shortcuts } from 'comp/app/shortcuts';
|
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-09-16 18:41:06 +02:00
|
|
|
events = {};
|
2015-10-17 23:49:24 +02:00
|
|
|
|
2019-08-18 10:17:09 +02:00
|
|
|
render(complete) {
|
2019-09-16 18:41:06 +02:00
|
|
|
super.render();
|
2017-01-31 07:50:28 +01:00
|
|
|
const shortcut = this.$el.find('.details__attachment-preview-download-text-shortcut');
|
2019-09-14 16:36:30 +02:00
|
|
|
shortcut.html(Shortcuts.actionShortcutSymbol(false));
|
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', () => {
|
2019-08-16 23:05:39 +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);
|
|
|
|
return this;
|
2019-08-18 10:17:09 +02:00
|
|
|
}
|
2015-10-17 23:49:24 +02:00
|
|
|
case 'image':
|
2019-08-16 23:05:39 +02:00
|
|
|
$('<img/>')
|
|
|
|
.attr('src', URL.createObjectURL(blob))
|
|
|
|
.appendTo(dataEl);
|
2015-10-17 23:49:24 +02:00
|
|
|
complete();
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
this.$el.addClass('details__attachment-preview--empty');
|
|
|
|
this.$el.find('.details__attachment-preview-icon').addClass('fa-' + this.model.icon);
|
|
|
|
complete();
|
|
|
|
return this;
|
|
|
|
}
|
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 };
|