-
\ No newline at end of file
+
diff --git a/cfs-autoform.js b/cfs-autoform.js
index b12226a..1133c5e 100644
--- a/cfs-autoform.js
+++ b/cfs-autoform.js
@@ -17,7 +17,7 @@ if (Meteor.isClient) {
AutoForm.addInputType("cfs-file", {
template:"cfsFileField",
valueOut: function () {
- return "dummyId";
+ return 'dummyId';
},
contextAdjust: function (context) {
context.atts.placeholder = context.atts.placeholder || "Click to upload a file or drop it here";
@@ -54,7 +54,45 @@ if (Meteor.isClient) {
Template.cfsFileField_bootstrap3.helpers({
textInputAtts: textInputAtts,
- fileInputAtts: fileInputAtts
+ fileInputAtts: fileInputAtts,
+ value: function() {
+ var id = Template.currentData().value
+ if(id) {
+ return id
+ } else {
+ return null
+ }
+ },
+ available: function() {
+ // If there's a file attached
+ var id = Template.currentData().value
+
+ return id
+ },
+ url: function () {
+ // Get the id of the file
+ var id = Template.currentData().value
+
+ // If there's a file...
+ if (id) {
+ // Get the file and the file data
+ var collection = FS._collections[this.atts.collection]
+
+ var file = collection.findOne({ _id: id })
+ var fileType = file.type()
+
+ // If the file is a image return the url
+ if(fileType.match(/image/g)) {
+ return file.url()
+ } else {
+ return false
+ }
+ } else {
+ return false
+ }
+
+
+ },
});
Template.cfsFilesField_bootstrap3.helpers({
@@ -98,7 +136,19 @@ if (Meteor.isClient) {
template.$('.cfsaf-hidden').click();
},
'change .cfsaf-hidden': singleHandler,
- 'dropped .cfsaf-field': singleHandler
+ 'dropped .cfsaf-field': singleHandler,
+ 'click .af-remove-file': function(event, template) {
+ // When the remove link is clicked...
+ event.preventDefault();
+
+ // Set the data attributes marking it for removal upon save
+ // Actual removing will happen only if saved through hooks
+ template.$('.cfsaf-hidden').data('remove', 'true');
+
+ // Remove the file preview and the remove link
+ template.$('.af-file-preview').fadeOut();
+ template.$(event.target).fadeOut();
+ }
});
var multipleHandler = function (event, template) {