-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from bitbag-commerce/dev
[Block] Add image preview && validation not blank image
- Loading branch information
Showing
13 changed files
with
177 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
BitBag\CmsPlugin\Entity\Image: | ||
properties: | ||
file: | ||
- NotBlank: | ||
message: 'bitbag.cms.block.image.not_blank' | ||
groups: ['bitbag'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
(function ( $ ) { | ||
'use strict'; | ||
|
||
$.fn.extend({ | ||
previewUploadedImage: function (root) { | ||
$(root + ' input[type="file"]').each(function() { | ||
$(this).change(function() { | ||
displayUploadedImage(this); | ||
}); | ||
}); | ||
|
||
$(root + ' [data-form-collection="add"]').on('click', function() { | ||
var self = $(this); | ||
|
||
setTimeout(function() { | ||
self.parent().find('.column:last-child input[type="file"]').on('change', function() { | ||
displayUploadedImage(this); | ||
}); | ||
}, 500); | ||
}); | ||
} | ||
}); | ||
|
||
function displayUploadedImage(input) { | ||
if (input.files && input.files[0]) { | ||
var reader = new FileReader(); | ||
|
||
reader.onload = function (e) { | ||
var image = $(input).parent().siblings('.image'); | ||
|
||
if (image.length > 0) { | ||
image.attr('src', e.target.result); | ||
} else { | ||
var img = $('<img class="ui small bordered image"/>'); | ||
img.attr('src', e.target.result); | ||
$(input).parent().before(img); | ||
} | ||
}; | ||
|
||
reader.readAsDataURL(input.files[0]); | ||
} | ||
} | ||
})( jQuery ); | ||
|
||
(function($) { | ||
$(document).ready(function () { | ||
$(document).previewUploadedImage('#bitbag-block-image') | ||
}); | ||
})(jQuery); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{% extends 'SyliusAdminBundle::layout.html.twig' %} | ||
|
||
{% import 'SyliusUiBundle:Macro:headers.html.twig' as headers %} | ||
|
||
{% set header = configuration.vars.header|default(metadata.applicationName~'.ui.new_'~metadata.name) %} | ||
{% set event_prefix = metadata.applicationName ~ '.admin.' ~ metadata.name ~ '.create' %} | ||
|
||
{% block title %}{{ parent() }} {{ header|trans }}{% endblock %} | ||
|
||
{% form_theme form '@SyliusAdmin/Form/theme.html.twig' %} | ||
|
||
{% block content %} | ||
{{ sonata_block_render_event(event_prefix ~ '.before_header', {'resource': resource}) }} | ||
|
||
{% include '@SyliusAdmin/Crud/Create/_header.html.twig' %} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.after_header', {'resource': resource}) }} | ||
|
||
{% include '@SyliusAdmin/Crud/Create/_content.html.twig' %} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.after_content', {'resource': resource}) }} | ||
{% endblock %} | ||
|
||
{% block stylesheets %} | ||
{{ parent() }} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.stylesheets') }} | ||
{% endblock %} | ||
|
||
{% block javascripts %} | ||
{{ parent() }} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.javascripts') }} | ||
|
||
<script src="{{ asset('bundles/bitbagcmsplugin/js/bitbag-block-image-preview.js') }}"></script> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{% extends 'SyliusAdminBundle::layout.html.twig' %} | ||
|
||
{% import 'SyliusUiBundle:Macro:headers.html.twig' as headers %} | ||
|
||
{% set definition = resources.definition %} | ||
{% set data = resources.data %} | ||
{% set event_prefix = metadata.applicationName ~ '.admin.' ~ metadata.name ~ '.index' %} | ||
|
||
{% set header = configuration.vars.header|default(metadata.applicationName~'.ui.'~metadata.pluralName) %} | ||
|
||
{% block title %}{{ parent() }} {{ header|trans }}{% endblock %} | ||
|
||
{% block content %} | ||
{{ sonata_block_render_event(event_prefix ~ '.before_header', {'resources': resources}) }} | ||
|
||
{% include '@SyliusAdmin/Crud/Index/_header.html.twig' %} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.after_header', {'resources': resources}) }} | ||
|
||
{% include '@SyliusAdmin/Crud/Index/_content.html.twig' %} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.after_content', {'resources': resources}) }} | ||
{% endblock %} | ||
|
||
{% block stylesheets %} | ||
{{ parent() }} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.stylesheets') }} | ||
{% endblock %} | ||
|
||
{% block javascripts %} | ||
{{ parent() }} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.javascripts') }} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{% extends 'SyliusAdminBundle::layout.html.twig' %} | ||
|
||
{% import 'SyliusUiBundle:Macro:headers.html.twig' as headers %} | ||
{% import 'SyliusUiBundle:Macro:buttons.html.twig' as buttons %} | ||
|
||
{% set header = configuration.vars.header|default(metadata.applicationName~'.ui.edit_'~metadata.name) %} | ||
{% set event_prefix = metadata.applicationName ~ '.admin.' ~ metadata.name ~ '.update' %} | ||
|
||
{% block title %}{{ parent() }} {{ header|trans }}{% endblock %} | ||
|
||
{% form_theme form '@SyliusAdmin/Form/theme.html.twig' %} | ||
|
||
{% block content %} | ||
{{ sonata_block_render_event(event_prefix ~ '.before_header', {'resource': resource}) }} | ||
|
||
{% include '@SyliusAdmin/Crud/Update/_header.html.twig' %} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.after_header', {'resource': resource}) }} | ||
|
||
{% include '@SyliusAdmin/Crud/Update/_content.html.twig' %} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.after_content', {'resource': resource}) }} | ||
{% endblock %} | ||
|
||
{% block stylesheets %} | ||
{{ parent() }} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.stylesheets') }} | ||
{% endblock %} | ||
|
||
{% block javascripts %} | ||
{{ parent() }} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.javascripts') }} | ||
|
||
<script src="{{ asset('bundles/bitbagcmsplugin/js/bitbag-block-image-preview.js') }}"></script> | ||
|
||
{% endblock %} |