<commit_before>{% block cropper_stylesheets %}
    <link href="{{ asset('bundles/breithbarbotcropper/css/cropper.min.css') }}" rel="stylesheet">
    <link href="{{ asset('bundles/breithbarbotcropper/css/main.css') }}" rel="stylesheet">
{% endblock %}

{% block cropper_modals %}
    <div class="modal fade" id="avatar-modal" aria-hidden="true" aria-labelledby="avatar-modal-label" role="dialog">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <form class="avatar-form" action="{{ path('breithbarbot_cropper_crop') }}" enctype="multipart/form-data" method="post">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title" id="avatar-modal-label">Outil de cropping</h4>
                    </div>
                    <div class="modal-body">
                        <div class="avatar-body">
                            <!-- Upload image and data -->
                            <div class="avatar-upload">
                                <input type="hidden" class="avatar-src" name="avatar_src">
                                <input type="hidden" class="avatar-data" name="avatar_data">

                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="avatarInput">Selectionner une image</label>
                                            <input type="file" class="avatar-input form-control" onchange="previewCropper(this)" id="avatarInput" name="avatar_file" accept="image/x-png,image/gif,image/jpeg">
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="avatarInput">Nom de fichier</label>
                                            <input type="text" id="avatarInput" class="form-control" name="filename">
                                        </div>
                                    </div>
                                </div>

                                <input type="hidden" name="mapping" value="{{ mapping }}"> <input type="hidden" name="width" value="{{ width }}"> <input type="hidden" name="height" value="{{ height }}">
                            </div>

                            <!-- Crop and preview -->
                            <div class="row">
                                <div class="col-md-9">
                                    <div class="avatar-wrapper">
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="avatar-preview" style="height: auto !important;">
                                        <img src="" height="200" alt="Aperçu de l’image...">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
                        <button type="submit" class="btn btn-primary">Enregistrer</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
{% endblock %}

{% block cropper_javascripts %}
    <script src="{{ asset('bundles/breithbarbotcropper/js/cropper.min.js') }}"></script>
    <script>
        $(document).ready(function () {

            // Initializing Cropper
            $('#avatar-modal').on('shown.bs.modal', function () {
                var $image = $('.avatar-wrapper img');
                var $preview = $('.avatar-preview');
                var cropBoxData;
                var canvasData;

                $image.cropper({
                    aspectRatio   : {{ ratio }},
                    wheelZoomRatio: 0.03,
                    autoCropArea  : 1,
                    preview       : $preview,
                    crop          : function (e) {
                        var json = [
                            '{"x":' + e.x,
                            '"y":' + e.y,
                            '"height":' + e.height,
                            '"width":' + e.width,
                            '"rotate":' + e.rotate + '}'
                        ].join();

                        $('.avatar-data').val(json);
                    }
                });
            }).on('hidden.bs.modal', function () {
                // Destroy cropper
                $('.avatar-wrapper img').cropper('destroy');

                // Reset form
                $('.avatar-form')[0].reset();
            });
        });

        // Initializing elements
        function loadCropper(elem) {

            // Closure
            $elem = $(elem);

            // Set current image
            $('#avatar-modal .avatar-wrapper').empty().html('<img src="' + $elem.find('img').attr('src') + '" />');

            // Open the modal
            $('#avatar-modal').modal('show');

            // Processing the cropped image
            $('#avatar-modal').find('form').on('submit', function (e) {
                e.preventDefault();

                $.ajax({
                    contentType: false,
                    processData: false,
                    data       : new FormData(this),
                    dataType   : "json",
                    method     : "POST",
                    cache      : false,
                    url        : $('#avatar-modal').find('form').attr('action'),
                    success    : function (response) {
                        if (response.state === 200) {
                            $elem.find('[data-id="full_path"]').val(response.result.full_path);
                            $elem.find('[data-id="path"]').val(response.result.path);
                            $elem.find('[data-id="name"]').val(response.result.name);
                            $elem.find('[data-id="mime_type"]').val(response.result.mime_type);
                            $elem.find('[data-id="size"]').val(response.result.size);

                            // Set new image cropped
                            $elem.find('img').attr('src', response.result.path_image);

                            // Reset form
                            $('.avatar-form')[0].reset();

                            // Close the modal
                            $('#avatar-modal').modal('hide');
                        } else {
                            alert('Une erreur s\'est produite');
                        }
                    }, error   : function () {
                        console.log("Erreur lors de la lecture des données");
                    }
                });

            });

        }

        // Cropper preview image
        function previewCropper(fileInput) {

            var file = fileInput.files[0];
            var imageType = /image.*/;

            if (/\.(jpe?g|png|gif)$/i.test(file.name)) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $('.avatar-wrapper img').cropper('replace', reader.result);
                }

                reader.readAsDataURL(file);
            } else {
                alert('File not supported!');
            }
        }
    </script>
{% endblock %}<commit_msg>Update, improve for array mapping and identifier<commit_after>{% set current_mapping = breithbarbot_cropper_parameter('breithbarbot_cropper.mappings')[mapping] %}
{% set identifier = (id is defined and id is not empty) ? '-'~id : '' %}

{% block cropper_stylesheets %}
    <link href="{{ asset('bundles/breithbarbotcropper/css/cropper.min.css') }}" rel="stylesheet">
    <link href="{{ asset('bundles/breithbarbotcropper/css/main.css') }}" rel="stylesheet">
{% endblock %}

{% block cropper_modals %}
    <div class="modal fade" id="avatar-modal{{ identifier }}" aria-hidden="true" aria-labelledby="avatar-modal{{ identifier }}-label" role="dialog">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <form class="avatar-form" action="{{ path('breithbarbot_cropper_crop') }}" enctype="multipart/form-data" method="post">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title" id="avatar-modal{{ identifier }}-label">Outil de cropping</h4>
                    </div>
                    <div class="modal-body">
                        <div class="avatar-body">
                            <!-- Upload image and data -->
                            <div class="avatar-upload">
                                <input type="hidden" class="avatar-src" name="avatar_src">
                                <input type="hidden" class="avatar-data" name="avatar_data">

                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="avatarInput">Selectionner une image</label>
                                            <input type="file" class="avatar-input form-control" onchange="previewCropper(this)" id="avatarInput" name="avatar_file" accept="image/x-png,image/gif,image/jpeg">
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="avatarInput">Nom de fichier</label>
                                            <input type="text" id="avatarInput" class="form-control" name="filename">
                                        </div>
                                    </div>
                                </div>

                                <input type="hidden" name="mapping" value="{{ mapping }}">
                            </div>

                            <!-- Crop and preview -->
                            <div class="row">
                                <div class="col-md-9">
                                    <div class="avatar-wrapper">
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="avatar-preview" style="height: auto !important;">
                                        <img src="" height="200" alt="Aperçu de l’image...">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
                        <button type="submit" class="btn btn-primary">Enregistrer</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
{% endblock %}

{% block cropper_javascripts %}
    <script src="{{ asset('bundles/breithbarbotcropper/js/cropper.min.js') }}"></script>
    <script src="{{ asset('bundles/breithbarbotcropper/js/dummy_image.js') }}"></script>
    <script>
        $(document).ready(function () {

            // Initializing Cropper
            $('#avatar-modal{{ identifier }}').on('shown.bs.modal', function () {
                var $image = $('.avatar-wrapper img');
                var $preview = $('.avatar-preview');
                var cropBoxData;
                var canvasData;

                $image.cropper({
                    aspectRatio   : {{ current_mapping.ratio }},
                    wheelZoomRatio: 0.03,
                    autoCropArea  : 1,
                    preview       : $preview,
                    crop          : function (e) {
                        var json = [
                            '{"x":' + e.x,
                            '"y":' + e.y,
                            '"height":' + e.height,
                            '"width":' + e.width,
                            '"rotate":' + e.rotate + '}'
                        ].join();

                        $('.avatar-data').val(json);
                    }
                });
            }).on('hidden.bs.modal', function () {
                // Destroy cropper
                $('.avatar-wrapper img').cropper('destroy');

                // Reset form
                $('.avatar-form')[0].reset();
            });
        });

        // Initializing elements
        function loadCropper(elem) {

            // Variable
            $avatarModal = $('#avatar-modal{{ identifier }}');

            // Closure
            $elem = $(elem);

            // Set current image
            $avatarModal.find('.avatar-wrapper').empty().html('<img src="' + $elem.find('img').attr('src') + '" />');

            // Open the modal
            $avatarModal.modal('show');

            // Processing the cropped image
            $avatarModal.find('form').on('submit', function (e) {
                e.preventDefault();

                $.ajax({
                    contentType: false,
                    processData: false,
                    data       : new FormData(this),
                    dataType   : "json",
                    method     : "POST",
                    cache      : false,
                    url        : $avatarModal.find('form').attr('action'),
                    success    : function (response) {
                        if (response.state === 200) {
                            $elem.find('[data-id="full_path"]').val(response.result.full_path);
                            $elem.find('[data-id="path"]').val(response.result.path);
                            $elem.find('[data-id="name"]').val(response.result.name);
                            $elem.find('[data-id="mime_type"]').val(response.result.mime_type);
                            $elem.find('[data-id="size"]').val(response.result.size);

                            // Set new image cropped
                            $elem.find('img').attr('src', response.result.path_image);

                            // Reset form
                            $('.avatar-form')[0].reset();

                            // Close the modal
                            $avatarModal.modal('hide');
                        } else {
                            alert('Une erreur s\'est produite');
                        }
                    }, error   : function () {
                        console.log("Erreur lors de la lecture des données");
                    }
                });

            });

        }

        // Cropper preview image
        function previewCropper(fileInput) {

            var file = fileInput.files[0];
            var imageType = /image.*/;

            if (/\.(jpe?g|png|gif)$/i.test(file.name)) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    // Replace the image's src and rebuild the cropper.
                    $('.avatar-wrapper img').cropper('replace', reader.result);
                }

                if (file) {
                    reader.readAsDataURL(file);
                }
            } else {
                alert('File not supported!');
            }
        }
    </script>
{% endblock %}
{'fraction_non_alphanumeric': 0.14079171664877832, 'fraction_numerical': 0.0023991413599343393, 'mean_word_length': 1.069235793598955, 'pattern_counts': {'":': 10, '<': 137, '<?xml version=': 0, '>': 137, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 58, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3096549', 'n_tokens_mistral': 3986, 'n_tokens_neox': 3698, 'n_words': 690}