<commit_before>{% extends "BabdelauraBlogBundle:Admin:layout.html.twig" %}

{% block content %}
    <h1>Ajout d'un article</h1>
    <form method="post" {{ form_enctype(form) }}>
        <div class="form-group">
            {{ form_label(form.titre, "Titre") }}
            {{ form_errors(form.titre)}}
            {{ form_widget(form.titre) }}
        </div>

        <div class="form-group">
            {{ form_label(form.contenu, "Contenu de l'article") }}
            {{ form_errors(form.contenu)}}
            {{ form_widget(form.contenu) }}
        </div>

        <div class="row">
            <div class="form-group six columns">
                {#<div>
                    <input type="file" id="main-image-file" name="mainImageFile" data-action="{{url('babdelaurablog_admin_uploaderImage', {'addWatermark': 'false'})}}" />
                    <button class="button" id="button-upload-main-image" type="submit">
                        <i class="fa fa-upload"></i> Ajouter une image principale
                    </button>
                </div>#}
                <button class="bab-Button" id="button-choose-image" type="button">
                    <i class="fa fa-camera"></i> Choisir une image principale
                </button>

                {% if article.image %}
                    {% set src = asset(article.image.webPath) %}
                {% else %}
                    {% set src = asset('images/no-photo.png') %}
                {% endif %}

                <img class="image-preview" id="image-preview" src="{{ src }}" />
                {{ form_widget(form.imageTemp) }}
            </div>

            <div class="form-group six columns">
                {{ form_label(form.categories, "Catégories") }}
                {{ form_errors(form.categories)}}
                {{ form_widget(form.categories) }}
            </div>
        </div>

        <div class="form-group">
            {{ form_label(form.datePublication, "Date de publication") }}
            {{ form_errors(form.datePublication)}}
            {{ form_widget(form.datePublication) }}
        </div>

        <div class="checkbox">
            {{ form_widget(form.publication) }}
            {{ form_label(form.publication, "Publier l'article") }}
            {{ form_errors(form.publication)}}
        </div>

        {{ form_rest(form) }}

        <button class="bab-Button" id="submit-btn" type="submit">Enregistrer l'article</button>
    </form>

    <div class="bab-Modal" id="modal-choose-image">
        <div class="bab-Modal-shadow"></div>
        <div class="bab-Modal-container">
            <button class="bab-Modal-close"><i class="fa fa-times"></i>
            </button>
            <div class="bab-Modal-content">
                <h1>Ajouter une image</h1>
                <form id="upload-main-image" method="post" action="{{url('babdelaurablog_admin_uploaderImage', {'addWatermark': 'false'})}}" enctype="multipart/form-data">
                    <input type="file" name="mainImageFile" />
                    <button class="bab-Button" type="submit"><i class="fa fa-upload"></i> Envoyer l'image</button>
                </form>
                <h1>Sélectionner une image dans la gallerie</h1>
                <div id="gallery"></div>
            </div>
        </div>
    </div>
{% endblock %}


{% block javascripts %}
    {{parent()}}
    <script src="{{asset('bundles/babdelaurablog/js/ckeditor/ckeditor.js')}}"></script>
    <script>
        CKEDITOR.config.entities = false;
        CKEDITOR.config.entities_latin = false;

        CKEDITOR.replace('babdelaura_blogbundle_article_contenu', {
            filebrowserBrowseUrl: '{{path('babdelaurablog_admin_listerImages')}}',
            filebrowserUploadUrl: '{{path('babdelaurablog_admin_uploaderImage')}}',
            contentsCss: '{{asset('css/contents.css')}}'
        });

        (function($) {
            var $chooseImageButton = $('#button-choose-image');
            var $chooseImageModal = $('#modal-choose-image');
            var $chooseImageCloseButton = $chooseImageModal.find('.bab-Modal-close');
            var $chooseImageInput = $('#babdelaura_blogbundle_article_imageTemp');
            var $chooseImagePreview = $('#image-preview');
            var modalContentAlreadyFilled = false;
            var clickedSave = false;

            function openModal() {
                $chooseImageModal.addClass('bab-Modal--open');
                getGallery();
            }

            function closeModal() {
                $chooseImageModal.removeClass('bab-Modal--open');
            }

            function getGallery(url) {
                var ajaxUrl = url || '{{path('babdelaurablog_admin_listerImages')}}?CKEditor=true';
                $.ajax({
                    url: ajaxUrl,
                    type: 'get',
                    beforeSend: showLoader,
                    error: function(jqXHR, textStatus, errorThrown) {
                        console.error(textStatus, errorThrown);
                    },
                    success: fillGallery
                });
            }

            function showLoader() {
                $chooseImageModal.find('#gallery').html('<p>Chargement</p>');
            }

            function fillGallery(data) {
                $chooseImageModal.find('#gallery').html(data);
                modalContentAlreadyFilled = true;
            }

            function selectImage(event) {
                var $image = $(event.target);

                $chooseImageInput.val($image.attr('id'));
                previewImage($image.attr('src'));

                closeModal();
            }

            function previewImage(src) {
                $chooseImagePreview.attr('src', src);
            }

            $chooseImageButton.on('click', openModal);
            $chooseImageCloseButton.on('click', closeModal);
            $chooseImageModal.on('click', '.bab-ImageGallery-item', selectImage);
            $chooseImageModal.on('click', '.bab-Pagination-page:not(.bab-Paginatin-page--current)', function(event) {
                event.preventDefault();
                var url = $(event.target).attr('href');

                getGallery(url);
            });

            $('#upload-main-image').on('submit', function(event) {
                event.preventDefault();

                var data = new FormData($(this)[0]);

                $.ajax({
                    type: 'POST',
                    url: $(this).attr('action'),
                    data: data,
                    cache: false,
                    contentType: false,
                    processData: false
                }).done(function(data) {<commit_msg>Fix nom de classe<commit_after>{% extends "BabdelauraBlogBundle:Admin:layout.html.twig" %}

{% block content %}
    <h1>Ajout d'un article</h1>
    <form method="post" {{ form_enctype(form) }}>
        <div class="form-group">
            {{ form_label(form.titre, "Titre") }}
            {{ form_errors(form.titre)}}
            {{ form_widget(form.titre) }}
        </div>

        <div class="form-group">
            {{ form_label(form.contenu, "Contenu de l'article") }}
            {{ form_errors(form.contenu)}}
            {{ form_widget(form.contenu) }}
        </div>

        <div class="row">
            <div class="form-group six columns">
                {#<div>
                    <input type="file" id="main-image-file" name="mainImageFile" data-action="{{url('babdelaurablog_admin_uploaderImage', {'addWatermark': 'false'})}}" />
                    <button class="button" id="button-upload-main-image" type="submit">
                        <i class="fa fa-upload"></i> Ajouter une image principale
                    </button>
                </div>#}
                <button class="bab-Button" id="button-choose-image" type="button">
                    <i class="fa fa-camera"></i> Choisir une image principale
                </button>

                {% if article.image %}
                    {% set src = asset(article.image.webPath) %}
                {% else %}
                    {% set src = asset('images/no-photo.png') %}
                {% endif %}

                <img class="image-preview" id="image-preview" src="{{ src }}" />
                {{ form_widget(form.imageTemp) }}
            </div>

            <div class="form-group six columns">
                {{ form_label(form.categories, "Catégories") }}
                {{ form_errors(form.categories)}}
                {{ form_widget(form.categories) }}
            </div>
        </div>

        <div class="form-group">
            {{ form_label(form.datePublication, "Date de publication") }}
            {{ form_errors(form.datePublication)}}
            {{ form_widget(form.datePublication) }}
        </div>

        <div class="checkbox">
            {{ form_widget(form.publication) }}
            {{ form_label(form.publication, "Publier l'article") }}
            {{ form_errors(form.publication)}}
        </div>

        {{ form_rest(form) }}

        <button class="bab-Button" id="submit-btn" type="submit">Enregistrer l'article</button>
    </form>

    <div class="bab-Modal" id="modal-choose-image">
        <div class="bab-Modal-shadow"></div>
        <div class="bab-Modal-container">
            <button class="bab-Modal-close"><i class="fa fa-times"></i>
            </button>
            <div class="bab-Modal-content">
                <h1>Ajouter une image</h1>
                <form id="upload-main-image" method="post" action="{{url('babdelaurablog_admin_uploaderImage', {'addWatermark': 'false'})}}" enctype="multipart/form-data">
                    <input type="file" name="mainImageFile" />
                    <button class="bab-Button" type="submit"><i class="fa fa-upload"></i> Envoyer l'image</button>
                </form>
                <h1>Sélectionner une image dans la gallerie</h1>
                <div id="gallery"></div>
            </div>
        </div>
    </div>
{% endblock %}


{% block javascripts %}
    {{parent()}}
    <script src="{{asset('bundles/babdelaurablog/js/ckeditor/ckeditor.js')}}"></script>
    <script>
        CKEDITOR.config.entities = false;
        CKEDITOR.config.entities_latin = false;

        CKEDITOR.replace('babdelaura_blogbundle_article_contenu', {
            filebrowserBrowseUrl: '{{path('babdelaurablog_admin_listerImages')}}',
            filebrowserUploadUrl: '{{path('babdelaurablog_admin_uploaderImage')}}',
            contentsCss: '{{asset('css/contents.css')}}'
        });

        (function($) {
            var $chooseImageButton = $('#button-choose-image');
            var $chooseImageModal = $('#modal-choose-image');
            var $chooseImageCloseButton = $chooseImageModal.find('.bab-Modal-close');
            var $chooseImageInput = $('#babdelaura_blogbundle_article_imageTemp');
            var $chooseImagePreview = $('#image-preview');
            var modalContentAlreadyFilled = false;
            var clickedSave = false;

            function openModal() {
                $chooseImageModal.addClass('bab-Modal--open');
                getGallery();
            }

            function closeModal() {
                $chooseImageModal.removeClass('bab-Modal--open');
            }

            function getGallery(url) {
                var ajaxUrl = url || '{{path('babdelaurablog_admin_listerImages')}}?CKEditor=true';
                $.ajax({
                    url: ajaxUrl,
                    type: 'get',
                    beforeSend: showLoader,
                    error: function(jqXHR, textStatus, errorThrown) {
                        console.error(textStatus, errorThrown);
                    },
                    success: fillGallery
                });
            }

            function showLoader() {
                $chooseImageModal.find('#gallery').html('<p>Chargement</p>');
            }

            function fillGallery(data) {
                $chooseImageModal.find('#gallery').html(data);
                modalContentAlreadyFilled = true;
            }

            function selectImage(event) {
                var $image = $(event.target);

                $chooseImageInput.val($image.attr('id'));
                previewImage($image.attr('src'));

                closeModal();
            }

            function previewImage(src) {
                $chooseImagePreview.attr('src', src);
            }

            $chooseImageButton.on('click', openModal);
            $chooseImageCloseButton.on('click', closeModal);
            $chooseImageModal.on('click', '.bab-ImageGallery-item', selectImage);
            $chooseImageModal.on('click', '.bab-Pagination-page:not(.bab-Pagination-page--current)', function(event) {
                event.preventDefault();
                var url = $(event.target).attr('href');

                getGallery(url);
            });

            $('#upload-main-image').on('submit', function(event) {
                event.preventDefault();

                var data = new FormData($(this)[0]);

                $.ajax({
                    type: 'POST',
                    url: $(this).attr('action'),
                    data: data,
                    cache: false,
                    contentType: false,
                    processData: false
                }).done(function(data) {
{'fraction_non_alphanumeric': 0.149898717083052, 'fraction_numerical': 0.0010503413609423062, 'mean_word_length': 1.75755068266446, 'pattern_counts': {'":': 0, '<': 127, '<?xml version=': 0, '>': 127, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1894860', 'n_tokens_mistral': 3857, 'n_tokens_neox': 3534, 'n_words': 577}