|
|
|
@ -4,8 +4,24 @@
|
|
|
|
|
(function () {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
Whisper.FileTypeToast = Whisper.ToastView.extend({
|
|
|
|
|
template: $('#attachment-type-modal').html()
|
|
|
|
|
var FileView = Backbone.View.extend({
|
|
|
|
|
tagName: 'a',
|
|
|
|
|
initialize: function(dataUrl) {
|
|
|
|
|
this.dataUrl = dataUrl;
|
|
|
|
|
this.$el.text("Unsupported attachment type. Click to save.");
|
|
|
|
|
},
|
|
|
|
|
events: {
|
|
|
|
|
'click': 'open'
|
|
|
|
|
},
|
|
|
|
|
open: function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
window.open(this.dataUrl, '_blank');
|
|
|
|
|
},
|
|
|
|
|
render: function() {
|
|
|
|
|
this.$el.attr('href', this.dataUrl);
|
|
|
|
|
this.trigger('update');
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var ImageView = Backbone.View.extend({
|
|
|
|
@ -58,33 +74,18 @@
|
|
|
|
|
className: 'attachment',
|
|
|
|
|
render: function() {
|
|
|
|
|
var View;
|
|
|
|
|
var isUnsupportedType = false;
|
|
|
|
|
switch(this.model.contentType.split('/')[0]) {
|
|
|
|
|
case 'image': View = ImageView; break;
|
|
|
|
|
case 'audio': View = AudioView; break;
|
|
|
|
|
case 'video': View = VideoView; break;
|
|
|
|
|
default:
|
|
|
|
|
isUnsupportedType = true;
|
|
|
|
|
default : View = FileView; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isUnsupportedType) {
|
|
|
|
|
var toast = new Whisper.FileTypeToast({
|
|
|
|
|
model: {type: this.model.contentType.split('/')[0]}
|
|
|
|
|
});
|
|
|
|
|
toast.$el.insertAfter(this.$el);
|
|
|
|
|
toast.render();
|
|
|
|
|
return toast;
|
|
|
|
|
} else {
|
|
|
|
|
var blob = new Blob([this.model.data], {type: this.model.contentType});
|
|
|
|
|
var view = new View(window.URL.createObjectURL(blob), this.model.contentType);
|
|
|
|
|
view.$el.appendTo(this.$el);
|
|
|
|
|
view.render();
|
|
|
|
|
view.on('update', this.trigger.bind(this, 'update'));
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
deleteView: function(e) {
|
|
|
|
|
if (e) { e.stopPropagation(); }
|
|
|
|
|
var blob = new Blob([this.model.data], {type: this.model.contentType});
|
|
|
|
|
var view = new View(window.URL.createObjectURL(blob), this.model.contentType);
|
|
|
|
|
view.$el.appendTo(this.$el);
|
|
|
|
|
view.on('update', this.trigger.bind(this, 'update'));
|
|
|
|
|
view.render();
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|