sopinet / upload-magic-bundle
Symfony2 Bundle - Easy integration for DropzoneJS and OneupUploaderBundle
Installs: 342
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 8
Forks: 0
Language:JavaScript
Type:symfony-bundle
Requires
- php: >=5.4.0
- oneup/uploader-bundle: 1.0.*@dev
This package is not auto-updated.
Last update: 2025-01-04 17:02:28 UTC
README
upload-magic-bundle
Symfony2 Bundle - Easy integration for DropzoneJS and OneupUploaderBundle
Prerequisites
This bundle is tested using Symfony2 versions 2.3+.
Installation:
Step 1: Add Bundle
- Add to composer:
"sopinet/upload-magic-bundle": "dev-master"
- Add to AppKernel:
new Oneup\UploaderBundle\OneupUploaderBundle(), new Sopinet\Bundle\UploadMagicBundle\SopinetUploadMagicBundle(),
- Add routing for delete
upload:
resource: "@SopinetUploadMagicBundle/Controller/UploadController.php"
type: annotation
Step 2: Configure OneupUploaderBundle
- Add configuration (config.yml) any like:
oneup_uploader: mappings: gallery: frontend: dropzone
- Configure routing
oneup_uploader: resource: . type: uploader
- More options from OneupUploaderBundle,https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md but upload-magic-bundle only support dropzone frontend method.
Step 3: Define your Entity
- You can use UploadMagic trait, so:
namespace yourBundle\BaseBundle\Entity; use ... /** * @ORM\Entity * @ORM\Table(name="file") * @DoctrineAssert\UniqueEntity("id") */ class File { use \Sopinet\Bundle\UploadMagicBundle\Model\UploadMagic; ... }
- You can add relation and another attributes to your entity:
... /** * @ORM\ManyToOne(targetEntity="Category", inversedBy="files") * @ORM\JoinColumn(name="category_id", referencedColumnName="id") */ protected $category; ...
Step 4: Add your form
- Add CSS
{% include 'SopinetUploadMagicBundle:Upload:simple_css.html.twig' %}
- Add form
{% include 'SopinetUploadMagicBundle:Upload:simple.html.twig' with { 'name': 'demo', 'type': 'gallery', 'id': 0, 'entity': 'myBundle_BaseBundle_File', 'param1': 'title', 'value1': 'A title for...', 'param2': 'myBundle_BaseBundle_Category', 'value2': guild.id, 'icon': 'fa fa-plus-circle' } %}
In param1 i use "title", and Listener will do "setTitle".
With param2 it use an entity, and it will do findbyoneid and "set" again.
More documentation about params form is coming... ;)
- Add js, one time
{% include 'SopinetUploadMagicBundle:Upload:simple_js.html.twig' %}
If you have errors about load time, you can use:
{% include 'SopinetUploadMagicBundle:Upload:simple_js.timeout.html.twig' %}
- Add blockjs, for each form
{% include 'SopinetUploadMagicBundle:Upload:simple_blockjs.html.twig'
with {
'name': 'demo',
'type': 'gallery',
'files': files_already_saved_array,
'limit': 1,
'entity': 'myBundle_BaseBundle_File'
# Optional
'preview': true
}
%}
More JS, trigger
What file is uploading or file is removed, you can capture this event in JQuery and do anything.
Events
$( "body" ).on( "removedFile", function( event, data) { // data, "ok" or "ko" }); $("body").on("uploadedFile", function(event, data) { // data, "ok" });
Sample
$( "body" ).on( "removedFile", function( event, data) { if (data == "ok") { $.gritter.add({ title: '<i class="fa fa-check-circle"></i> Acción realizada con éxito', text: 'Has eliminado un fichero', sticky: false, time: '', class_name: 'gritter-success' }); } else { $.gritter.add({ title: '<i class="fa fa-times-circle"></i> Ha ocurrido un error', text: 'No se ha podido eliminar el fichero', sticky: false, time: '', class_name: 'gritter-danger' }); } }); $("body").on("uploadedFile", function(event, data) { $.gritter.add({ title: '<i class="fa fa-check-circle"></i> Acción realizada con éxito', text: 'Has guardado un fichero', sticky: false, time: '', class_name: 'gritter-success' }); });
TODO
- Better documentation about params to Form
- More is coming...