Skip to content

Commit 89bbd4a

Browse files
committed
v1.0.7
- Support for `previewTemplate` (Fix: #4) - Support for `uploadTemplate` (Fix: #4) - Dependencies update
1 parent 276d96f commit 89bbd4a

File tree

4 files changed

+64
-23
lines changed

4 files changed

+64
-23
lines changed

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ Schemas.Posts = new SimpleSchema({
4949
autoform: {
5050
afFieldInput: {
5151
type: 'fileUpload',
52-
collection: 'Images'
52+
collection: 'Images',
53+
uploadTemplate: 'uploadField' // <- Optional
54+
previewTemplate: 'uploadPreview' // <- Optional
5355
}
5456
}
5557
}
@@ -96,12 +98,11 @@ Schemas.Posts = new SimpleSchema({
9698
})
9799
```
98100

99-
### Custom file preview /// need to work on this
101+
### Custom file preview
100102

101103
Your custom file preview template data context will be:
102104

103-
- *file* - FS.File instance
104-
- *atts* - autoform atts
105+
- *file* - fileObj instance
105106

106107
```javascript
107108
picture: {
@@ -116,6 +117,28 @@ picture: {
116117
}
117118
```
118119

120+
### Custom upload template
121+
122+
Your custom file upload template data context will be:
123+
124+
- *file* - FS.File instance
125+
- *progress*
126+
- *status*
127+
- Other fields from [`FileUpload` instance](https://github.com/VeliovGroup/Meteor-Files/wiki/Insert-(Upload)#fileupload-methods-and-properties)
128+
129+
```javascript
130+
picture: {
131+
type: String,
132+
autoform: {
133+
afFieldInput: {
134+
type: 'fileUpload',
135+
collection: 'Images',
136+
uploadTemplate: 'myFileUpload'
137+
}
138+
}
139+
}
140+
```
141+
119142
```html
120143
<template name="myFilePreview">
121144
<a href="{{fileURL file}}">{{file.original.name}}</a>

lib/client/fileUpload.html

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
<template name="afFileUpload">
22
<input value="{{fileId}}" type="hidden" {{this.atts}}>
33
{{#with uploadedFile}}
4-
<div>
5-
{{#if isImage}}
6-
{{> uploadImageDemo}}
7-
{{else}}
8-
{{> uploadFileDemo}}
9-
{{/if}}
10-
</div>
11-
<a data-reset-file href="#" style="display:none">Reset</a>
12-
<a data-remove-file href="#">Remove</a>
4+
{{#if previewTemplate}}
5+
{{>Template.dynamic template=previewTemplate}}
6+
{{else}}
7+
<div>
8+
{{#if isImage}}
9+
{{> uploadImageDemo}}
10+
{{else}}
11+
{{> uploadFileDemo}}
12+
{{/if}}
13+
</div>
14+
<a data-reset-file href="#" style="display:none">Reset</a>
15+
<a data-remove-file href="#">Remove</a>
16+
{{/if}}
1317
{{else}}
14-
{{#with currentUpload}}
15-
Uploading <b>{{file.name}}</b>:
16-
<progress value="{{progress.get}}" max="100"></progress>
17-
&nbsp;
18-
<span class="progress">{{progress.get}}%</span>
18+
{{#if uploadTemplate}}
19+
{{>Template.dynamic template=uploadTemplate data=currentUpload}}
1920
{{else}}
20-
<input data-files-collection-upload class="form-control af-file-upload-capture" type="file" />
21-
{{/with}}
21+
{{#with currentUpload}}
22+
Uploading <b>{{file.name}}</b>:
23+
<progress value="{{progress.get}}" max="100"></progress>
24+
&nbsp;
25+
<span class="progress">{{progress.get}}%</span>
26+
{{else}}
27+
<input data-files-collection-upload class="form-control af-file-upload-capture" type="file" />
28+
{{/with}}
29+
{{/if}}
2230
{{/with}}
2331
</template>

lib/client/fileUpload.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
Template.afFileUpload.onCreated(function () {
22
var self = this;
3+
34
if (!this.data) {
45
this.data = {
56
atts: {}
67
};
78
}
89

9-
this.collection = Meteor.connection._mongo_livedata_collections[this.data.atts.collection];
10+
this.collection = Meteor.connection._mongo_livedata_collections[this.data.atts.collection];
11+
this.uploadTemplate = this.data.atts.uploadTemplate || null;
12+
this.previewTemplate = this.data.atts.previewTemplate || null;
13+
1014
if (!this.collection) {
1115
throw new Meteor.Error(404, '[meteor-autoform-files] No such collection "' + this.data.atts.collection + '"');
1216
}
@@ -22,6 +26,12 @@ Template.afFileUpload.onCreated(function () {
2226
});
2327

2428
Template.afFileUpload.helpers({
29+
previewTemplate: function () {
30+
return Template.instance().previewTemplate;
31+
},
32+
uploadTemplate: function () {
33+
return Template.instance().uploadTemplate;
34+
},
2535
currentUpload: function () {
2636
return Template.instance().currentUpload.get();
2737
},

package.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Package.describe({
22
name: "ostrio:autoform-files",
33
summary: "File upload for AutoForm using ostrio:files",
44
description: "File upload for AutoForm using ostrio:files",
5-
version: "1.0.6",
5+
version: "1.0.7",
66
git: "https://github.com/VeliovGroup/meteor-autoform-file.git"
77
});
88

@@ -15,7 +15,7 @@ Package.onUse(function(api) {
1515
'reactive-var',
1616
'templating',
1717
'aldeed:autoform@5.8.1',
18-
'ostrio:files@1.7.1'
18+
'ostrio:files@1.7.3'
1919
]);
2020

2121
api.addFiles([

0 commit comments

Comments
 (0)