Skip to content

Instantly share code, notes, and snippets.

@pzuraq
Created April 16, 2013 02:54
Show Gist options
  • Save pzuraq/5393002 to your computer and use it in GitHub Desktop.
Save pzuraq/5393002 to your computer and use it in GitHub Desktop.
Case.UploadFileView = Ember.TextField.extend({
type: 'file',
attributeBindings: ['name', 'multiple'],
change: function(evt) {
var self = this;
var input = evt.target;
if (input.files && input.files[0]) {
for(var i = 0; i < input.files.length; ++i) {
var reader = new FileReader();
var that = this;
reader.onload = function(e) {
var fileToUpload = e.srcElement.result,
fileArrayName = self.get('name'),
fileArray = self.get('controller').get(fileArrayName);
fileArray.pushObject(fileToUpload);
self.get('controller').set(fileArrayName, fileArray);
}
reader.readAsDataURL(input.files[i]);
}
}
}
});
{{view Case.UploadFileView name="photoQueue" multiple="multiple"}}
{{#each photo in photoQueue}}
<span>{{photo}}</span>
{{/each}}
Case.VehiclePhotosController = Ember.ObjectController.extend({
photoQueue: Ember.A(),
photoQueueSorted: function() {
console.log(this.get('photoQueue'));
return this.get('photoQueue').filter(function(photo) {return true;});
}.property('photoQueue.@each'),
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment