Added error message for unsupported attachment type (issue #419)
This commit is contained in:
parent
04359c9184
commit
8251db6ae6
2 changed files with 30 additions and 9 deletions
|
@ -160,6 +160,9 @@
|
||||||
Sorry, the selected file exceeds message size
|
Sorry, the selected file exceeds message size
|
||||||
restrictions. ({{ limit }}{{ units }})
|
restrictions. ({{ limit }}{{ units }})
|
||||||
</script>
|
</script>
|
||||||
|
<script type='text/x-tmpl-mustache' id='attachment-type-modal'>
|
||||||
|
Sorry, your attachment has a type, {{type}}, that is not currently supported.
|
||||||
|
</script>
|
||||||
<script type='text/x-tmpl-mustache' id='message-detail'>
|
<script type='text/x-tmpl-mustache' id='message-detail'>
|
||||||
<div class='conversation-header'>
|
<div class='conversation-header'>
|
||||||
<button class='back'></button>
|
<button class='back'></button>
|
||||||
|
|
|
@ -4,6 +4,10 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
Whisper.FileTypeToast = Whisper.ToastView.extend({
|
||||||
|
template: $('#attachment-type-modal').html()
|
||||||
|
});
|
||||||
|
|
||||||
var ImageView = Backbone.View.extend({
|
var ImageView = Backbone.View.extend({
|
||||||
tagName: 'img',
|
tagName: 'img',
|
||||||
initialize: function(dataUrl) {
|
initialize: function(dataUrl) {
|
||||||
|
@ -20,8 +24,8 @@
|
||||||
window.open(this.dataUrl, '_blank');
|
window.open(this.dataUrl, '_blank');
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
this.$el.attr('src', this.dataUrl);
|
this.$el.attr('src', this.dataUrl);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -54,19 +58,33 @@
|
||||||
className: 'attachment',
|
className: 'attachment',
|
||||||
render: function() {
|
render: function() {
|
||||||
var View;
|
var View;
|
||||||
|
var isUnsupportedType = false;
|
||||||
switch(this.model.contentType.split('/')[0]) {
|
switch(this.model.contentType.split('/')[0]) {
|
||||||
case 'image': View = ImageView; break;
|
case 'image': View = ImageView; break;
|
||||||
case 'audio': View = AudioView; break;
|
case 'audio': View = AudioView; break;
|
||||||
case 'video': View = VideoView; break;
|
case 'video': View = VideoView; break;
|
||||||
default:
|
default:
|
||||||
throw 'Unsupported attachment type';
|
isUnsupportedType = true;
|
||||||
}
|
}
|
||||||
var blob = new Blob([this.model.data], {type: this.model.contentType});
|
|
||||||
var view = new View(window.URL.createObjectURL(blob), this.model.contentType);
|
if (isUnsupportedType) {
|
||||||
view.$el.appendTo(this.$el);
|
var toast = new Whisper.FileTypeToast({
|
||||||
view.render();
|
model: {type: this.model.contentType.split('/')[0]}
|
||||||
view.on('update', this.trigger.bind(this, 'update'));
|
});
|
||||||
return this;
|
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(); }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue