{% trans_default_domain 'SDUserBundle' %}
<script>
    $(document).ready(function(){
        var arr = $('#' + '{{ form.vars.name }}' + '_claimtype option');
        var gSiteIDs = [];
        $.each(arr, function(key, value){
            gSiteIDs.push($(value).val());
            $(value).prop('selected', true);
        });
            
        SD.select2('#' + '{{ form.vars.name }}' + '_stuff', {
            multiple: true
        });
        $('#' + '{{ form.vars.name }}' + '_claimtype').select2({
            minimumInputLength: 0,
            width: 200
        });
        $('#' + '{{ form.vars.name }}' + '_userkey').select2({
            minimumInputLength: 0,
            width: 200
        });
        $('#select-all-claimtype').die('click');
        $('#select-all-claimtype').live('click', function () {
            $('#' + '{{ form.vars.name }}' + '_claimtype').select2("val", []);      
        });

    });
</script>
<div class="row">
    <div class="col-md-12">
        <div class="portlet box yellow">
            <div class="portlet-title">
                <div class="caption"><i class="fa fa-edit"></i>
                    {% trans %}Add new resposible{% endtrans %}
                </div>
            </div>
            <div class="portlet-body">
                <div class="portlet-body">
                    {% form_theme form 'ITDoorsCommonBundle:Form:form_errors.html.twig' %}
                    {% if form.vars.valid is sameas(false) %}
                        <div class="alert alert-danger">
                            <button class="close" data-close="alert"></button>
                            {% trans from 'messages' %}You have some form errors. Please check below.{% endtrans %}
                            {{ form_errors(form) }}
                        </div>
                    {% endif %}
                    {{ form_start(form, {
                            'action' : path('sd_common_ajax_form'),
                            'attr' : {
                            'method' : 'POST',
                            'class' : 'ajax-form-entity',
                            'data-post_function': postFunction,
                            'data-post_target_id': postTargetId,
                            'data-target_id': targetId,
                            'enctype': 'multipart/form-data'
                        }
                    }) }}
                    <div class="form-body row">
                        {% if form.dopDogovor is defined %}
                            <div class="form-group col-md-12">
                                {{ form_label(form.dopDogovor, 'Dop Dogovor Number', {'attr': {'class': 'control-label'}}) }}
                                {{ form_widget(form.dopDogovor, {'attr' : {'class' : 'form-control', 'placeholder': "Dop Dogovor Number"}}) }}
                                {{ form_errors(form.dopDogovor) }}
                            </div>
                        {% endif %}
                    </div>
                    <div class="form-body row">
                        <div class="form-group col-md-3">
                            {{ form_label(form.stuff, 'Stuff', {'attr': {'class': 'control-label'}}) }}
                            <div class="input-group input-medium">
                                {{ form_widget(form.stuff, {'attr' : {'class' : 'itdoors-select2 can-be-reseted submit-field'}}) }}
                            </div>
                        </div>
                        <div class="form-group col-md-3">
                            {{ form_label(form.userkey, 'Role', {'attr': {'class': 'control-label'}}) }}
                            <div class="input-group input-medium">
                                {{ form_widget(form.userkey) }}
                            </div>
                        </div>
                        <div class="form-group col-md-3">
                            {{ form_label(form.claimtype, 'Organization type', {'attr': {'class': 'control-label'}}) }}
                            <div class="input-group input-medium">
                                {{ form_widget(form.claimtype) }}
                                <a id="select-all-claimtype" class="btn green">
                                        {% trans %}Clear{% endtrans %}
                                </a>
                            </div>
                        </div>
                    </div>
                    <div class="form-actions">
                        {{ form_widget(form.submit, { 'label': 'Save', 'attr': {'class': 'btn blue'} } ) }}
                        {{ form_widget(form.cancel, { 'label': 'Cancel'|trans({}, 'messages'), 'attr':
                            {
                                'class': 'btn default sd-cancel-btn',
                                'data-dismiss': "modal"
                            }
                        } ) }}
                    </div>
                    <input type="hidden" name="formName" value="{{ formName }}">
                    <input type="hidden" name="postFunction" value="{{ postFunction }}">
                    <input type="hidden" name="postTargetId" value="{{ postTargetId }}">
                    <input type="hidden" name="targetId" value="{{ targetId }}">
                    <input type="hidden" name="model" value="{{ model }}">
                    <input type="hidden" name="modelId" value="{{ modelId }}">
                    {{ form_end(form) }}
                </div>
            </div>
        </div>
    </div>
</div>
