Skip to content

Commit

Permalink
Merge branch 'cutomize_templates'
Browse files Browse the repository at this point in the history
Conflicts:
	Form/Type/DropzoneType.php
	Resources/views/Form/fields.html.twig
  • Loading branch information
nilov committed Jul 17, 2016
2 parents bec9bb1 + f69824a commit e6d7785
Show file tree
Hide file tree
Showing 20 changed files with 955 additions and 863 deletions.
149 changes: 117 additions & 32 deletions Form/Type/DropzoneType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Glavweb\UploaderBundle\Helper\MediaHelper;
use Symfony\Component\Translation\DataCollectorTranslator;

/**
* Class DropzoneType
Expand Down Expand Up @@ -38,18 +39,25 @@ class DropzoneType extends AbstractType
*/
protected $driverAnnotation;

/**
* @var DataCollectorTranslator
*/
protected $translator;


/**
* @param Router $router
* @param MediaHelper $mediaHelper
* @param array $config
* @param AnnotationDriver $driverAnnotation
*/
public function __construct(Router $router, MediaHelper $mediaHelper, array $config, AnnotationDriver $driverAnnotation)
public function __construct(Router $router, MediaHelper $mediaHelper, array $config, AnnotationDriver $driverAnnotation, DataCollectorTranslator $translator)
{
$this->router = $router;
$this->mediaHelper = $mediaHelper;
$this->config = $config;
$this->driverAnnotation = $driverAnnotation;
$this->translator = $translator;
}

/**
Expand Down Expand Up @@ -84,54 +92,131 @@ public function buildView(FormView $view, FormInterface $form, array $options)
}

$config = $this->getConfigByContext($context);
$maxFiles = $config['max_files'];

$view->vars['uploadedFilesTpl'] = $options['uploadedFilesTpl'];
$view->vars['uploadItemTpl'] = $options['uploadItemTpl'];
$view->vars['viewFormTpl'] = $options['viewFormTpl'];
$view->vars['viewLinkTpl'] = $options['viewLinkTpl'];
$view->vars['type'] = $context;
$view->vars['previewImg'] = $options['previewImg'];
$view->vars['useLink'] = $options['useLink'];
$view->vars['useForm'] = $options['useForm'];
$view->vars['showMark'] = $options['showMark'];
$view->vars['thumbnailWidth'] = $options['thumbnailWidth' ];
$view->vars['thumbnailHeight'] = $options['thumbnailHeight'];
$view->vars['showUploadButton'] = $options['showUploadButton'];
$view->vars['uploaderClass'] = $options['uploaderClass'];
$view->vars['isShowErrorPopup'] = $options['isShowErrorPopup'];
$view->vars['files'] = $files ? $files : [];
$view->vars['countFiles'] = $files ? $files->count() : 0;
$view->vars['showLabel'] = $options['showLabel'];
$router = $this->router;
$uploadDir = $this->mediaHelper->getUploadDirectoryUrl($context);
$urls = array(
'upload' => $router->generate('glavweb_uploader_upload', array('context' => $context)),
'rename' => $router->generate('glavweb_uploader_rename', array('context' => $context)),
'delete' => $router->generate('glavweb_uploader_delete', array('context' => $context)),
);

$view->vars['requestId'] = $options['requestId'];
$view->vars['uploadDir'] = $this->mediaHelper->getUploadDirectoryUrl($context);
$view->vars['deleteUrl'] = $this->router->generate('glavweb_uploader_delete', array('context' => $context));
$view->vars['renameUrl'] = $this->router->generate('glavweb_uploader_rename', array('context' => $context));
$view->vars['maxFiles'] = $maxFiles;
$view->vars['maxSize'] = $config['max_size'];
$view->vars['views'] = $options['views' ];
$view->vars['type'] = $context;
$view->vars['files'] = $files;
// $view->vars['previewImg'] = $options['previewImg'];
$view->vars['previewShow'] = array_merge($options['previewShowDefault'],$options['previewShow']);

// Dropzone
$view->vars['dropzoneOptions'] = array_merge($options['dropzoneOptionsDefault'], array(
'url' => $urls['upload'],
'uploadDir' => $uploadDir,
'previewTemplate' => '#js-gwu-template_' . $options['requestId'],
'previewsContainer' => '#js-gwu-previews_' . $options['requestId'],
'form' => '.js-gwu-from_' . $options['requestId'],
'link' => '.js-gwu-link_' . $options['requestId'],
'maxFilesize' => $config['max_size'],
'clickable' => '.js-gwu-clickable_' . $options['requestId'],
),$options['dropzoneOptions']);

// Uploader
$view->vars['uploaderOptions'] = array_merge($options['uploaderOptionsDefault'], array(
'urls' => $urls,
'requestId' => $options['requestId'],
'dropzoneContainer' => '#js-gwu-dropzone_' . $options['requestId'],
'previewShow' => $view->vars['previewShow'],
'uploadDir' => $uploadDir,
'countFiles' => $files->count(),
'maxFiles' => $view->vars['dropzoneOptions']['maxFiles'],
'type' => $context,
'clickable' => '.js-gwu-clickable_' . $options['requestId'],
), $options['uploaderOptions']);
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$translator = $this->translator;

$resolver->setDefaults(array(
'previewImg' => null,
'requestId' => null,
'useLink' => true,
'useForm' => true,
'showMark' => true,
'showUploadButton' => true,
'uploadedFilesTpl' => 'GlavwebUploaderBundle:Form:base_upload_item_tpl.html.twig',
'uploadItemTpl' => 'GlavwebUploaderBundle:Form:base_uploaded_files.html.twig',
'viewFormTpl' => 'GlavwebUploaderBundle:Form:view-form.html.twig',
'viewLinkTpl' => 'GlavwebUploaderBundle:Form:view-link.html.twig',
'showLabel' => true,
'thumbnailWidth' => 200,
'thumbnailHeight' => 150,
'uploaderClass' => '',
'isShowErrorPopup' => true,
'thumbnailOptions' => array(
'width' => 200,
'height' => 200,
),
'views' => array(
// 'form' => 'path/to/view',
// 'link' => 'path/to/view',
// 'preview' => 'path/to/view',
),
'previewShow' => array(),
'previewShowDefault' => array(
'isDetails' => true,
'isSize' => true,
'isFilename' => true,
'isProgress' => true,
'isError' => true,
'isShowMark' => true
),
'uploaderOptions' => array(),
'uploaderOptionsDefault' => array(
'type' => null,
'uploaderClass' => '',
'formViewType' => 'form',
'previewViewType' => 'image',
'preloader' => '.js-gwu-preloader',
'upoloaderError' => '.js-gwu-error',
'previewContainer' => '.js-gwu-preview',
'rename' => '.js-gwu-rename',
'filename' => '.js-gwu-filename',
'description' => '.js-gwu-description',
'form' => '.js-gwu-form',
'link' => '.js-gwu-link',
'popup' => '.js-gwu-popup',
'isPopup' => true,
'isName' => true,
'isDescription' => false,
'isSort' => false,
'isShowErrorPopup' => false,
'isThumbnail' => true,
'isUploadButton' => true,
'thumbnailOptions' => array(),
'countFiles' => 0
),
'dropzoneOptions' => array(),
'dropzoneOptionsDefault' => array(
'url' => null,
'previewTemplate' => null,
'previewsContainer' => null,
'clickable' => null,
'maxFilesize' => 2,
'maxFiles' => 20,
'thumbnailWidth' => 350,
'thumbnailHeight' => 350,
'parallelUploads' => 20,
'autoQueue' => true,
'autoProcessQueue' => true,
'acceptedFiles' => '.png, .jpg',
'dictDefaultMessage' => $translator->trans('dropzone.files_uploaded'),
'dictFallbackMessage' => $translator->trans('dropzone.browser_not_support_drag_n_drop'),
'dictFileTooBig' => $translator->trans('dropzone.file_size_too_large'),
'dictInvalidFileType' => $translator->trans('dropzone.wrong_format'),
'dictResponseError' => $translator->trans('dropzone.disable_adblocker'),
'dictCancelUpload' => $translator->trans( 'dropzone.cancel_upload'),
'dictCancelUploadConfirmation' => $translator->trans('dropzone.cancel_upload_confirmation'),
'dictRemoveFile' => $translator->trans('dropzone.remove_file'),
'dictRemoveFileConfirmation' => null,
'dictMaxFilesExceeded' => $translator->trans('dropzone.max_files_exceeded')
),
));
}

Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<argument type="service" id="glavweb_uploader.media_helper" />
<argument>%glavweb_uploader.config%</argument>
<argument type="service" id="glavweb_uploader.data_driver.annotation" />
<argument type="service" id="translator" />
<tag name="form.type" alias="glavweb_uploader_dropzone" />
</service>

Expand Down
64 changes: 64 additions & 0 deletions Resources/public/css/gwu.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
.gwu.gwu-dropzone .gwu-previews {
min-height: inherit;
overflow: hidden;
border: none;
-webkit-border-radius: 0;
-webkit-background-clip: padding-box;
-moz-border-radius: 0;
-moz-background-clip: padding;
border-radius: 0;
background-clip: padding-box;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
margin: 30px -15px 0 -15px;
padding: 0;
}
.gwu.gwu-dropzone .gwu-preview {
display: block;
float: left;
margin: 0 0 30px 0;
width: 100%;
padding: 0 15px;
}
.gwu.gwu-dropzone .gwu-preview__image {
width: 100%;
height: 100%;
-webkit-border-radius: 8px;
-webkit-background-clip: padding-box;
-moz-border-radius: 8px;
-moz-background-clip: padding;
border-radius: 8px;
background-clip: padding-box;
}
.gwu.gwu-dropzone .gwu-preview__details {
padding: 30px;
}
.gwu.gwu-dropzone .gwu-preview-img {
max-width: 100%;
}
@media (min-width: 480px) {
.gwu.gwu-dropzone .gwu-preview {
width: 50%;
}
}
@media (min-width: 768px) {
.gwu.gwu-dropzone .gwu-preview {
width: 33.3%;
}
}
@media (min-width: 992px) {
.gwu.gwu-dropzone .gwu-preview {
width: 25%;
}
}
@media (min-width: 1200px) {
.gwu.gwu-dropzone .gwu-preview {
width: 20%;
}
}
@media (min-width: 1600px) {
.gwu.gwu-dropzone .gwu-preview {
width: 16.6%;
}
}
Loading

0 comments on commit e6d7785

Please sign in to comment.