{% extends 'base.html.twig' %}

{% block localstyle %}
    {%if access!="config" %}
    .page-header {
        padding: 0px 30px 100px 30px !important;
    }    
    {%endif%}
{% endblock %}

{% block pagewrapper %}
{{ form_start(form) }}
    <h1 class="page-title">
    {% if mode=="update" %}
    Modification Groupe = {{ group.label }}
    {% elseif mode=="submit" %}
    Création Groupe
    {% elseif mode=="delete" %}
    Suppression Groupe = {{ group.label }}
    {% endif %}
    </h1>

    <p>
        {{ form_widget(form.submit) }} <a class="btn btn-secondary" href={{ path('app_core_'~access~'_group') }}>Annuler</a>
    </p>

    {% if app.session.flashbag.has('error') %}
        <div class='alert alert-danger' style='margin: 5px 0px'>
            <strong>Erreur</strong><br>
            {% for flashMessage in app.session.flashbag.get('error') %}
                {{ flashMessage }}<br>
            {% endfor %}
        </div>
    {% endif %}

    {% if app.session.flashbag.has('notice') %}
        <div class='alert alert-info' style='margin: 5px 0px'>
            <strong>Information</strong><br>
            {% for flashMessage in app.session.flashbag.get('notice') %}
                {{ flashMessage }}<br>
            {% endfor %}
        </div>
    {% endif %}

    <div class="row">
        <div class="col-sm-6">
            <div class="card">
                <div class="card-header">
                    <i class="fa fa-pencil-alt fa-fw"></i> Informations
                </div>

                <div class="card-body">
                    {% if form.label is defined %}
                        {{ form_row(form.label) }}
                        <div class='alert alert-info' style='font-size: 80%;padding: 5px;margin-top: -10px;'>
                            Caractères interdits = caractères spéciaux sauf ' @ . - _<br>
                        </div>

                        {% if form.fgassoc is defined %}
                            {% if masteridentity=="LDAP" %}
                                {{ form_row(form.fgassoc) }}
                                {{ form_row(form.ldapfilter) }}
                            {% endif %}    

                            {% if masteridentity=="SSO" %}
                                {{ form_row(form.fgassoc) }}
                                {{ form_row(form.attributes) }}
                            {% endif %}                       
                        {% endif %}
                    {% endif %}
                    
                    {{ form_row(form.description) }}
                    {% if form.email is defined %} {{ form_row(form.email) }} {% endif %}
                    {{ form_row(form.color) }}
                </div>
            </div>

            {% if form.fgcanshare is defined or form.fgopen is defined %}
                <div class="card">
                    <div class="card-header">
                        <i class="fa fa-pencil-alt fa-fw"></i> Configuration du Groupe
                    </div>

                    <div class="card-body">
                        {% if form.owner is defined %}
                            {{ form_row(form.owner) }}
                        {% endif %}

                        {% if form.fgopen is defined %}
                            {{ form_row(form.fgopen) }}
                        {% endif %}

                        {% if form.fgcanshare is defined %}
                            {{ form_row(form.fgcanshare) }}
                            <div id="pagetemplate">{{ form_row(form.pagetemplate) }}</div>
                        {% endif %}
                    </div>
                </div>
            {% endif %} 

            {% if form.fgcancreatepage is defined %}
                <div class="card">
                    <div class="card-header">
                        <i class="fa fa-pencil-alt fa-fw"></i> Permissions Portail
                    </div>

                    <div class="card-body">
                        {{ form_row(form.fgcancreatepage) }}
                        {{ form_row(form.fgcancreatecalendar) }}
                        {{ form_row(form.fgcancreateblog) }}
                        {{ form_row(form.fgcancreateproject) }}
                    </div>
                </div>
            {% endif %}
        </div>

        <div class="col-sm-6">
            <div id="diviconsel" class="col-md-12 text-left" style="height:140px; padding:20px; text-align:center; background-color: {{ group.color ? "#"~group.color : '#000000' }};">
                {% if group.icon %}
                    <img src="{{ asset(group.icon.label) }}" height="100" />
                {% endif %}
            </div>

            <div style="text-align:center;padding:0px">
                {{ form_row(form.idicon) }}
                <a class="btn btn-success" onClick="selectIcon()" title='Ajouter' style="width:100%">Selectionner une Icône</a>
                <a class="btn btn-danger" onClick="delIcon()" title='Détacher' style="width:100%">Détacher l'Icône</a>
            </div>
            <br>       

            {% if form.fgcancreatepage is defined %}                         
                <div class="card">
                    <div class="card-header">
                        <i class="fa fa-pencil-alt fa-fw"></i> Elements du Portail
                    </div>

                    <div class="card-body">
                        {{ form_row(form.pages) }}
                        {{ form_row(form.items) }}
                        {{ form_row(form.alerts) }}
                        {{ form_row(form.calendars) }}
                        {{ form_row(form.blogs) }}
                        {{ form_row(form.projects) }}
                        {{ form_row(form.fluxs) }}
                        {{ form_row(form.notices) }}
                    </div>
                </div>
            {% endif %}  
        </div>
    </div>
{{ form_end(form) }}
{% endblock %}

{% block localjavascript %}
    $('document').ready(function(){
     
        {% if masteridentity=="LDAP" %}
            fgaff=($("#group_ldapfilter").val()!="");
            if(!fgaff) {
                $("#group_ldapfilter").hide();
                $("#label_group_ldapfilter").hide();
                $("#group_fgassoc").val(0);
            }
        {% endif %}

        {% if masteridentity=="LDAP" %}
            $( "#group_fgassoc").change(function() {

                if($("#group_fgassoc").val()==0) {
                    $("#group_ldapfilter").hide();
                    $("#label_group_ldapfilter").hide();    
                    $("#group_ldapfilter").val("");
                }
                else {
                    $("#group_ldapfilter").show();
                    $("#label_group_ldapfilter").show();                
                }
            });    
        {% endif %}


        {% if masteridentity=="SSO" %}
            fgaff=($("#group_attributes").val()!="");
            if(!fgaff) {
                $("#group_attributes").hide();
                $("#label_group_attributes").hide();
                $("#group_fgassoc").val(0);
            }
        {% endif %}

        {% if masteridentity=="SSO" %}
            $( "#group_fgassoc").change(function() {

                if($("#group_fgassoc").val()==0) {
                    $("#group_attributes").hide();
                    $("#label_group_attributes").hide();    
                    $("#group_attributes").val("");
                }
                else {
                    $("#group_attributes").show();
                    $("#label_group_attributes").show();                
                }
            });    
        {% endif %}

        hideshow();
    });

    $(document.body).on("change","#group_fgcanshare",function(){
        hideshow();
    });

    function selIcon(idicon,label) {
        $("#group_idicon").val(idicon);
        $("#diviconsel img").remove();

        url="{{ asset("xxxxx") }}";
        url=url.replace("xxxxx",label);
        $("#diviconsel").append("<img src='"+url+"'>");
        $("#diviconsel img").attr("height","100px");
        $("#mymodal").modal("hide");
    }

    function selectIcon() {
        $("#mymodal").find(".modal-title").html("SELECTIONNER UNE ICONE");
        var url="{{ path('app_portal_user_icon_select') }}";
        $("#mymodal").find("#framemodal").attr("src",url);
        $("#mymodal").modal("show");
    }

    function delIcon() {
        $("#diviconsel img").remove();
        $("#group_idicon").val(null);
    }

    function hideshow() {
        if($("#group_fgcanshare").val()==1)
            $("#pagetemplate").show();
        else {
            $("#pagetemplate").hide();
        }
    }       

{% endblock %}
