cfs-ui
Fork from CollectionFS to implement certain app-specific features. *****Do not use this in your project, this is for internal use only - please use the package from atmosphere ****** Provides additional UI helpers for CollectionFS. Requires Meteor 0.8.0 or higher.
Installation
Install using Meteorite. When in a Meteor app directory, enter:
$ meteor add cfs:ui
Helpers
The following components and helpers are available.
FS.GetFile
Allows you to get an FS.File
instance by knowing its _id
and the name of the collection it's in.
1{{#with FS.GetFile collectionName id}} 2 In here, we can use the FS.File instance methods that work as helpers, such as {{url}} or {{isImage}} 3{{/with}}
Example:
1{{#with FS.GetFile "images" selectedImageId}} 2 <img src="{{this.url store='thumbnails'}}" alt=""> 3{{/with}}
FS.DeleteButton
Renders a delete button. Must be used where the current context is the FS.File
instance that you want to delete.
1{{#each images}} 2 Delete {{this.name}}: {{> FS.DeleteButton class="btn btn-danger btn-xs"}} 3{{/each}}
By default, the button says "Delete". If you want to use different text or HTML within the button element, simply use the component as a block helper, like this:
1{{#each images}} 2 Delete {{this.name}}: {{#FS.DeleteButton class="btn btn-danger btn-xs"}}Delete Me{{/FS.DeleteButton}} 3{{/each}}
FS.UploadProgressBar
Renders a reactive progress bar, showing either the upload progress for a single file or the upload progress for all files currently being uploaded.
Use where the current context is the FS.File
instance for which you want progress:
1{{#each images}} 2 {{#unless this.isUploaded}} 3 {{> FS.UploadProgressBar}} 4 {{/unless}} 5{{/each}}
You can optionally add attributes such as class
.
By default, an HTML5 progress element is rendered. To render a bootstrap3 progress bar instead:
1{{> FS.UploadProgressBar bootstrap=true}}
Any HTML attributes you add, such as class, are added to the div.progress-bar
, so you could add the progress-bar-success
class, for instance, but you can't add progress-striped
or active
classes to div.progress
.
To render a semantic-ui progress bar instead:
1{{> FS.UploadProgressBar semantic=true}}
Any HTML attributes you add, such as class, are added to the outer div.
If you want the progress bar to reflect the combined progress of all files currently being uploaded, don't use it
with an FS.File
instance as the context.
Event Handler Creators
This package also provides one event handler creator.
FS.EventHandlers.insertFiles(collection, [options])
Simplifies some of the repetitive code for making an event handler that does a file insert.
- collection: An
FS.Collection
instance. - options:
- metadata: (Optional) A function that takes an
FS.File
instance as its argument and returns an object containing the metadata to be added to the file object. - after: (Optional) A callback function for the
FS.Collection.insert
call.
- metadata: (Optional) A function that takes an
Example:
1Template.files.events({ 2 'dropped .imageArea': FS.EventHandlers.insertFiles(Images, { 3 metadata: function (fileObj) { 4 return { 5 owner: Meteor.userId(), 6 foo: "bar" 7 }; 8 }, 9 after: function (error, fileObj) { 10 console.log("Inserted", fileObj.name); 11 } 12 }), 13 'change #imageInput': FS.EventHandlers.insertFiles(Images, { 14 metadata: function (fileObj) { 15 return { 16 owner: Meteor.userId(), 17 foo: "bar" 18 }; 19 }, 20 after: function (error, fileObj) { 21 console.log("Inserted", fileObj.name); 22 } 23 }), 24});
By using this function to create your event handlers for input change events and the dropped
event (provided by the ui-dropped-event
package), you don't have to write any of the code to loop over files, convert File
to FS.File
, attach metadata, or perform the insert.