Browse Source

Make the FileUploader receive the callback

pull/758/head
Artur Arseniev 8 years ago
parent
commit
563a478b74
  1. 31
      src/asset_manager/view/FileUploader.js

31
src/asset_manager/view/FileUploader.js

@ -72,7 +72,7 @@ module.exports = Backbone.View.extend(
* @param {string} text Response text * @param {string} text Response text
* @private * @private
*/ */
onUploadResponse(text) { onUploadResponse(text, clb) {
const em = this.config.em; const em = this.config.em;
const config = this.config; const config = this.config;
const target = this.target; const target = this.target;
@ -84,6 +84,7 @@ module.exports = Backbone.View.extend(
} }
this.onUploadEnd(text); this.onUploadEnd(text);
clb && clb(json);
}, },
/** /**
@ -92,7 +93,7 @@ module.exports = Backbone.View.extend(
* @return {Promise} * @return {Promise}
* @private * @private
* */ * */
uploadFile(e) { uploadFile(e, clb) {
const files = e.dataTransfer ? e.dataTransfer.files : e.target.files; const files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
const body = new FormData(); const body = new FormData();
const config = this.config; const config = this.config;
@ -129,7 +130,7 @@ module.exports = Backbone.View.extend(
? res.text() ? res.text()
: res.text().then(text => Promise.reject(text)) : res.text().then(text => Promise.reject(text))
) )
.then(text => this.onUploadResponse(text)) .then(text => this.onUploadResponse(text, clb))
.catch(err => this.onUploadError(err)); .catch(err => this.onUploadError(err));
} }
}, },
@ -235,7 +236,7 @@ module.exports = Backbone.View.extend(
} }
}, },
{ {
embedAsBase64: function(e) { embedAsBase64: function(e, clb) {
// List files dropped // List files dropped
const files = e.dataTransfer ? e.dataTransfer.files : e.target.files; const files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
const response = { data: [] }; const response = { data: [] };
@ -268,6 +269,26 @@ module.exports = Backbone.View.extend(
type = file.type; type = file.type;
} }
/*
// Show local video files, http://jsfiddle.net/dsbonev/cCCZ2/embedded/result,js,html,css/
var URL = window.URL || window.webkitURL
var file = this.files[0]
var type = file.type
var videoNode = document.createElement('video');
var canPlay = videoNode.canPlayType(type) // can use also for 'audio' types
if (canPlay === '') canPlay = 'no'
var message = 'Can play type "' + type + '": ' + canPlay
var isError = canPlay === 'no'
displayMessage(message, isError)
if (isError) {
return
}
var fileURL = URL.createObjectURL(file)
videoNode.src = fileURL
*/
// If it's an image, try to find its size // If it's an image, try to find its size
if (type === 'image') { if (type === 'image') {
const data = { const data = {
@ -316,7 +337,7 @@ module.exports = Backbone.View.extend(
Promise.all(promises).then( Promise.all(promises).then(
data => { data => {
response.data = data; response.data = data;
this.onUploadResponse(response); this.onUploadResponse(response, clb);
}, },
error => { error => {
this.onUploadError(error); this.onUploadError(error);

Loading…
Cancel
Save