<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="{{ app['locale'] }}">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title>{{ 'thesaurus:: Lier la branche de thesaurus au champ' | trans }}</title>

        <link type="text/css" rel="stylesheet" href="/assets/thesaurus/css/thesaurus{% if not app.debug %}.min{% endif %}.css" />

        <script type="text/javascript">
            function ckField()
            {
                fields = document.getElementsByName("field[]");
                changed = false;
                for(i=0; i<fields.length && !changed; i++)
                {
                    if( (fields[i].checked?"1":"0") != fields[i].ck0)
                        changed = true;
                }
                document.getElementById("submit_button").disabled = !changed;

                return(true);
            }
            function clkBut(button)
            {
                switch(button)
                {
                    case "submit":
                        $('.link-field-1').submit(
                                $.ajax({
                                    url     : 'linkfield2.php',
                                    type    : 'POST',
                                    data    : $('.link-field-1').serialize(),
                                    success : function( data ) {
                                        $("#DLG_LINK_FIELD_1").html('');
                                        $("#DLG_LINK_FIELD_1").append(data);
                                    },
                                    error   : function( xhr, err ) {
                                        alert('Error');
                                    }
                                })
                        );
                        break;
                    case "cancel":
                        $('.close-dialog').trigger('click');
                        break;
                }
            }
            function loaded()
            {
                ckField();
            }
            $( document ).ready(function() {
                loaded();
            });
        </script>
    </head>
    <body class="dialog">

            <form class="link-field-1" action="linkfield2.php" method="post" target="LINKFIELD" style="padding: 5px 15px">
                    <input type="hidden" name="piv" value="{{ piv }}">
                    <input type="hidden" name="bid" value="{{ bid }}">
                    <input type="hidden" name="tid" value="{{ tid }}">

                    {% set branch = "<br/><b>" ~ fullBranch ~ "</b><br/>" %}
                    {% trans with {'%branch%' : branch} %}thesaurus:: Lier la branche de thesaurus au champ %branch%{% endtrans %}

                    <div style="width:100%; height:270px; overflow:scroll;" class="x3Dbox">
                    {% for fieldname, checked in fieldnames %}
                        <input type="checkbox" name="field[]" value="{{ fieldname }}" {% if checked %}checked{% endif %} ck0="{% if checked %}1{% else %}0{% endif %}" onclick="return(ckField());">{{ fieldname }}<br/>
                    {% endfor %}
                    </div>
                <div class="thesaurus_confirm_bottom_block">
                    <input type="button" id="cancel_button"  class="cancel_btn" value="{{ 'boutton::annuler' | trans }}" onclick="clkBut('cancel');">
                    <input type="button" id="submit_button" class="validate_btn" value="{{ 'boutton::valider' | trans }}" onclick="clkBut('submit');">
                </div>
            </form>

    </body>
</html>
