Refactor attachment saving for DRYness
// FREEBIE
This commit is contained in:
parent
a1345c52b4
commit
a069939f65
1 changed files with 35 additions and 49 deletions
|
@ -72,37 +72,41 @@
|
|||
'click': 'onclick'
|
||||
},
|
||||
onclick: function(e) {
|
||||
if (this.contentType === 'image') {
|
||||
var view = new Whisper.LightboxView({
|
||||
model: {
|
||||
url : this.objectUrl,
|
||||
blob : this.blob,
|
||||
fileType : this.fileType
|
||||
switch (this.contentType) {
|
||||
case 'audio':
|
||||
case 'video':
|
||||
return;
|
||||
case 'image':
|
||||
var view = new Whisper.LightboxView({ model: this });
|
||||
view.render();
|
||||
view.$el.appendTo(this.el);
|
||||
view.$el.trigger('show');
|
||||
break;
|
||||
|
||||
default:
|
||||
this.saveFile();
|
||||
}
|
||||
},
|
||||
saveFile: function() {
|
||||
var blob = this.blob;
|
||||
var suggestedName;
|
||||
if (this.fileType) {
|
||||
suggestedName = 'signal.' + this.fileType;
|
||||
}
|
||||
var w = extension.windows.getViews()[0];
|
||||
if (w && w.chrome && w.chrome.fileSystem) {
|
||||
w.chrome.fileSystem.chooseEntry({
|
||||
type: 'saveFile', suggestedName: suggestedName
|
||||
}, function(entry) {
|
||||
if (!entry) {
|
||||
return;
|
||||
}
|
||||
entry.createWriter(function(fileWriter) {
|
||||
fileWriter.write(blob);
|
||||
});
|
||||
});
|
||||
view.render();
|
||||
view.$el.appendTo(this.el);
|
||||
view.$el.trigger('show');
|
||||
} else if (this.contentType !== 'audio' && this.contentType !== 'video') {
|
||||
var suggestedName;
|
||||
if (this.fileType) {
|
||||
suggestedName = 'signal.' + this.fileType;
|
||||
}
|
||||
var w = extension.windows.getViews()[0];
|
||||
if (w && w.chrome && w.chrome.fileSystem) {
|
||||
w.chrome.fileSystem.chooseEntry({
|
||||
type: 'saveFile', suggestedName: suggestedName
|
||||
}, function(entry) {
|
||||
if (!entry) {
|
||||
return;
|
||||
}
|
||||
entry.createWriter(function(fileWriter) {
|
||||
fileWriter.write(this.blob);
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
} else {
|
||||
console.log('Failed to get window');
|
||||
}
|
||||
} else {
|
||||
console.log('Failed to get window');
|
||||
}
|
||||
},
|
||||
render: function() {
|
||||
|
@ -133,25 +137,7 @@
|
|||
'click': 'onclick'
|
||||
},
|
||||
save: function(e) {
|
||||
var suggestedName;
|
||||
if (this.model.fileType) {
|
||||
suggestedName = 'signal.' + this.model.fileType;
|
||||
}
|
||||
var w = extension.windows.getViews()[0];
|
||||
if (w && w.chrome && w.chrome.fileSystem) {
|
||||
w.chrome.fileSystem.chooseEntry({
|
||||
type: 'saveFile', suggestedName: suggestedName
|
||||
}, function(entry) {
|
||||
if (!entry) {
|
||||
return;
|
||||
}
|
||||
entry.createWriter(function(fileWriter) {
|
||||
fileWriter.write(this.model.blob);
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
} else {
|
||||
console.log('Failed to get window');
|
||||
}
|
||||
this.model.saveFile();
|
||||
},
|
||||
onclick: function(e) {
|
||||
var $el = this.$(e.target);
|
||||
|
@ -162,7 +148,7 @@
|
|||
}
|
||||
},
|
||||
render_attributes: function() {
|
||||
return { url: this.model.url };
|
||||
return { url: this.model.objectUrl };
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue