11Template . afFileUpload . onCreated ( function ( ) {
2+ var self = this ;
23 if ( ! this . data ) {
34 this . data = {
45 atts : { }
@@ -10,44 +11,47 @@ Template.afFileUpload.onCreated(function () {
1011 throw new Meteor . Error ( 404 , '[meteor-autoform-files] No such collection "' + this . data . atts . collection + '"' ) ;
1112 }
1213
13- this . collectionName = ( ) => this . data . atts . collection ;
14+ this . collectionName = function ( ) {
15+ return self . data . atts . collection ;
16+ } ;
17+
1418 this . currentUpload = new ReactiveVar ( false ) ;
1519 this . inputName = this . data . name ;
1620 this . fileId = new ReactiveVar ( this . data . value || false ) ;
1721 return ;
1822} ) ;
1923
2024Template . afFileUpload . helpers ( {
21- currentUpload ( ) {
25+ currentUpload : function ( ) {
2226 return Template . instance ( ) . currentUpload . get ( ) ;
2327 } ,
24- fileId ( ) {
28+ fileId : function ( ) {
2529 return Template . instance ( ) . fileId . get ( ) ;
2630 } ,
27- uploadedFile ( ) {
31+ uploadedFile : function ( ) {
2832 return global [ Template . instance ( ) . collectionName ( ) ] . findOne ( {
2933 _id : Template . instance ( ) . fileId . get ( )
3034 } ) ;
3135 }
3236} ) ;
3337
3438Template . afFileUpload . events ( {
35- 'click [data-reset-file]' ( e , template ) {
39+ 'click [data-reset-file]' : function ( e , template ) {
3640 e . preventDefault ( ) ;
3741 template . fileId . set ( false ) ;
3842 return false ;
3943 } ,
40- 'click [data-remove-file]' ( e , template ) {
44+ 'click [data-remove-file]' : function ( e , template ) {
4145 e . preventDefault ( ) ;
4246 template . fileId . set ( false ) ;
4347 try {
4448 this . remove ( ) ;
4549 } catch ( error ) { }
4650 return false ;
4751 } ,
48- 'change [data-files-collection-upload]' ( e , template ) {
52+ 'change [data-files-collection-upload]' : function ( e , template ) {
4953 if ( e . currentTarget . files && e . currentTarget . files [ 0 ] ) {
50- const upload = global [ template . collectionName ( ) ] . insert ( {
54+ var upload = global [ template . collectionName ( ) ] . insert ( {
5155 file : e . currentTarget . files [ 0 ] ,
5256 streams : 'dynamic' ,
5357 chunkSize : 'dynamic'
@@ -66,7 +70,7 @@ Template.afFileUpload.events({
6670 return ;
6771 } ) ;
6872
69- upload . on ( 'end' , ( error , fileObj ) => {
73+ upload . on ( 'end' , function ( error , fileObj ) {
7074 if ( ! error ) {
7175 if ( template ) {
7276 template . fileId . set ( fileObj . _id ) ;
0 commit comments