//Call component with model
{{upload.programs.image-input program=model.newDeveloperProgram}}
//Create a new array for files and add file to it
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
fileSelectionChanged: function(file) {
if(this.program.get('files')===null)
{
this.program.set('files',[]);
}
var filesProgram = this.program.get('files');
filesProgram.pushObject(file);
this.program.set('files',filesProgram);
this.set('files',filesProgram);
}
},
files: Ember.A([])
});
//For each file, show it with name
{{#each files as |file|}}
<img src="{{file.dataURL}}" width="200" height="200">
<ul>
<li>Titre: {{file.name}}</li>
</ul>
{{/each}}
<br>
{{upload/programs/file-input fileChanged="fileSelectionChanged" id='input-program'}}
{{yield}}
//Show file
import Ember from 'ember';
export default Ember.TextField.extend({
type: 'file',
change: function() {
let self = this;
var inputFiles = $('#input-program').prop('files');
if (inputFiles.length < 1) {
return;
}
let inputFile = inputFiles[0];
let fileInfo = {
name: inputFile.name
};
var fileReader = new FileReader();
fileReader.onloadend = function(e) {
//let fileReader = e.target;console.log(e.target);
fileInfo.dataURL = fileReader.result;
self.sendAction('fileChanged', fileInfo);
};
let firstFile = $('#input-program').prop('files')[0];
fileReader.readAsDataURL(firstFile);
}
});