<commit_before>{% extends bap.layout is defined ? bap.layout : 'AcmeDemoFlexibleEntityBundle::layout.html.twig' %}

{% set title = form.vars.value.id ? 'Edit attribute' : 'Add attribute' %}

{% block title %}{{ parent() }} - {{ title }}{% endblock %}

{% block content %}
<form action="{{ form.vars.value.id ? path('acme_demoflexibleentity_customerattribute_edit', { id: form.vars.value.id }) : path('acme_demoflexibleentity_customerattribute_create') }}" method="POST" class="form-register">
    <fieldset>
        <legend>{{ title }} <a class="btn btn-primary pull-right" href="{{ path('acme_demoflexibleentity_customerattribute_index') }}">{{ "Back to list" | trans }}</a></legend>

        {{ form_row(form.id) }}
        
        {{ form_row(form.code) }}
        
        {{ form_row(form.attributeType) }}
        
        {{ form_row(form.required) }}
        
        {{ form_row(form.unique) }}
        
        {{ form_row(form.default_value) }}
        
        {{ form_row(form.searchable) }}
        
        {{ form_row(form.translatable) }}
        
        {{ form_row(form.scopable) }}
        
        {{ form_row(form._token) }}
        
            <legend>Options</legend>
            
            <ul id="sortable_options" class="options" data-prototype="{% filter escape %}
                {% include 'AcmeDemoFlexibleEntityBundle:CustomerAttribute:_prototype-option.html.twig' with {'form': form.options.get('prototype')} %}
            {% endfilter %}">
            {% for option in form.options %}
                <li class="att-option">
                    {{ form_row(option.id) }}
                    {{ form_row(option.sort_order) }}
                    {% for value in option.optionValues %}
                        {{ form_row(value.id) }}
                        {{ form_row(value.value) }}
                        {{ form_row(value.locale) }}
                    {% endfor %}
                </li>
            {% endfor %}
            </ul>

        <div class="form-row">
            <button class="btn btn-large btn-primary" type="submit">Save</button>
        </div>
    </fieldset>
</form>
{% endblock %}


{% block javascripts %}
<script type="text/javascript">
    // Get the div that holds the collection of options
    var collectionHolder = $('ul.options');

    // setup an "add an option" link
    var $addOptionLink = $('<a href="#" class="add_option_link">Add an option</a>');
    var $newOptionLinkLi = $('<li class="not-sortable"></li>').append($addOptionLink);

    jQuery(document).ready(function() {
        console.info('jquery is ready');
        // add a delete link to all of the existing option form li elements
        collectionHolder.find('li.att-option').each(function() {
            addOptionFormDeleteLink($(this));
        });

        // add the "add a option" anchor and li to the options ul
        collectionHolder.append($newOptionLinkLi);

        $addOptionLink.on('click', function(e) {
            // prevent the link from creating a "#" on the URL
            e.preventDefault();

            // add a new tag form (see next code block)
            addOptionForm(collectionHolder, $newOptionLinkLi);
        });
        console.log('end of jquery is ready');
    });

    function addOptionForm(collectionHolder, $newOptionLinkLi) {
        console.info('add option form function');
        // Get the data-prototype we explained earlier
        var prototype = collectionHolder.attr('data-prototype');

        // Replace '__name__' in the prototype's HTML to
        // instead be a number based on the current collection's length.
        // the second '__name__' must be replace by 0 because we worked without locales
        // and so only one value each time
        var optionsLength = collectionHolder.children().length;
        prototype = prototype.replace(/\[options\]\[__name__\]/g, "[options]["+optionsLength+"]");
        prototype = prototype.replace(/_options___name__/g, "_options_"+ optionsLength);
        prototype = prototype.replace(/__name__/g, 0);
        var newForm = prototype;

        // Display the form in the page in an li, before the "Add an option" link li
        var $newFormLi = $('<li class="att-option"></li>').append(newForm);
        $newOptionLinkLi.before($newFormLi);

        // add a delete link to the new form
        addOptionFormDeleteLink($newFormLi);
        
        console.info('end of add option form function');
    }

    function addOptionFormDeleteLink($optFormLi) {
        console.info('add option form delete link function');
        
        var $moveFormA = $('<span class="action-drag-inline"></span>');
        $optFormLi.append($moveFormA);

        var $removeFormA = $('<a class="action-delete-inline" href="#">Delete option</a>');
        $optFormLi.append($removeFormA);
        $removeFormA.on('click', function(e) {
            // prevent the link from creating a "#" on the URL
            e.preventDefault();

            // remove the li for the tag form
            $optFormLi.remove();
        });
        
        console.info('end of add option form delete link function');
    }
</script>
{% endblock %}
<commit_msg>BAP-46 : Change edit view if options mustn't be rendered<commit_after>{% extends bap.layout is defined ? bap.layout : 'AcmeDemoFlexibleEntityBundle::layout.html.twig' %}

{% set title = form.vars.value.id ? 'Edit attribute' : 'Add attribute' %}

{% block title %}{{ parent() }} - {{ title }}{% endblock %}

{% block content %}
<form action="{{ form.vars.value.id ? path('acme_demoflexibleentity_customerattribute_edit', { id: form.vars.value.id }) : path('acme_demoflexibleentity_customerattribute_create') }}" method="POST" class="form-register">
    <fieldset>
        <legend>{{ title }} <a class="btn btn-primary pull-right" href="{{ path('acme_demoflexibleentity_customerattribute_index') }}">{{ "Back to list" | trans }}</a></legend>

        {{ form_row(form.id) }}
        
        {{ form_row(form.code) }}
        
        {{ form_row(form.attributeType) }}
        
        {{ form_row(form.required) }}
        
        {{ form_row(form.unique) }}
        
        {{ form_row(form.default_value) }}
        
        {{ form_row(form.searchable) }}
        
        {{ form_row(form.translatable) }}
        
        {{ form_row(form.scopable) }}
        
        {{ form_row(form._token) }}
        
        {% if form.options is defined %}
            <legend>Options</legend>
            
            <ul id="sortable_options" class="options" data-prototype="{% filter escape %}
                {% include 'AcmeDemoFlexibleEntityBundle:CustomerAttribute:_prototype-option.html.twig' with {'form': form.options.get('prototype')} %}
            {% endfilter %}">
            {% for option in form.options %}
                <li class="att-option">
                    {{ form_row(option.id) }}
                    {{ form_row(option.sort_order) }}
                    {% for value in option.optionValues %}
                        {{ form_row(value.id) }}
                        {{ form_row(value.value) }}
                        {{ form_row(value.locale) }}
                    {% endfor %}
                </li>
            {% endfor %}
            </ul>
        {% endif %}

        <div class="form-row">
            <button class="btn btn-large btn-primary" type="submit">Save</button>
        </div>
    </fieldset>
</form>
{% endblock %}


{% block javascripts %}
<script type="text/javascript">
    // Get the div that holds the collection of options
    var collectionHolder = $('ul.options');

    // setup an "add an option" link
    var $addOptionLink = $('<a href="#" class="add_option_link">Add an option</a>');
    var $newOptionLinkLi = $('<li class="not-sortable"></li>').append($addOptionLink);

    jQuery(document).ready(function() {
        console.info('jquery is ready');
        // add a delete link to all of the existing option form li elements
        collectionHolder.find('li.att-option').each(function() {
            addOptionFormDeleteLink($(this));
        });

        // add the "add a option" anchor and li to the options ul
        collectionHolder.append($newOptionLinkLi);

        $addOptionLink.on('click', function(e) {
            // prevent the link from creating a "#" on the URL
            e.preventDefault();

            // add a new tag form (see next code block)
            addOptionForm(collectionHolder, $newOptionLinkLi);
        });
        console.log('end of jquery is ready');
    });

    function addOptionForm(collectionHolder, $newOptionLinkLi) {
        console.info('add option form function');
        // Get the data-prototype we explained earlier
        var prototype = collectionHolder.attr('data-prototype');

        // Replace '__name__' in the prototype's HTML to
        // instead be a number based on the current collection's length.
        // the second '__name__' must be replace by 0 because we worked without locales
        // and so only one value each time
        var optionsLength = collectionHolder.children().length;
        prototype = prototype.replace(/\[options\]\[__name__\]/g, "[options]["+optionsLength+"]");
        prototype = prototype.replace(/_options___name__/g, "_options_"+ optionsLength);
        prototype = prototype.replace(/__name__/g, 0);
        var newForm = prototype;

        // Display the form in the page in an li, before the "Add an option" link li
        var $newFormLi = $('<li class="att-option"></li>').append(newForm);
        $newOptionLinkLi.before($newFormLi);

        // add a delete link to the new form
        addOptionFormDeleteLink($newFormLi);
        
        console.info('end of add option form function');
    }

    function addOptionFormDeleteLink($optFormLi) {
        console.info('add option form delete link function');
        
        var $moveFormA = $('<span class="action-drag-inline"></span>');
        $optFormLi.append($moveFormA);

        var $removeFormA = $('<a class="action-delete-inline" href="#">Delete option</a>');
        $optFormLi.append($removeFormA);
        $removeFormA.on('click', function(e) {
            // prevent the link from creating a "#" on the URL
            e.preventDefault();

            // remove the li for the tag form
            $optFormLi.remove();
        });
        
        console.info('end of add option form delete link function');
    }
</script>
{% endblock %}

{'fraction_non_alphanumeric': 0.14083429008802142, 'fraction_numerical': 0.000574052812858783, 'mean_word_length': 2.279887041104487, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 63, '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': '6545657', 'n_tokens_mistral': 2977, 'n_tokens_neox': 2823, 'n_words': 703}