<div class="form_wrapper">
    <form method="post">
    <div class="buttons">
        <a href="/admin/delete_coach/{$coach->get_ua_id()}" class="addbutton delete-big">Edző törlése</a>
    </div>
        <input type="hidden" name="action" value="coach_data_edit">
        <input type="hidden" name="ua_id" value="{$coach->get_ua_id()}">

        <div>
            <label class="desc" id="title1" for="ua_name">Név:</label>
            <div><input type="text" name="ua_name" id="ua_name" value="{$coach->get_ua_name()}" required></div>
        </div>


        <div>
            <label class="desc" id="title1" for="ua_can_login">Be tud lépni:</label>
            <div><input type="checkbox" name="ua_admin" id="ua_admin" {if $coach->get_ua_admin()}checked{/if}></div>
        </div>

        <div id="password">
            <label class="desc" id="title1" for="ua_password">Új jelszó:</label>
            <div><input type="text" name="ua_password" id="ua_password"></div>
        </div>

        <div class="admin_area">
            <label>Jogosultságok:</label>
            <table id="authorities">
                {foreach $a_array as $a}
                    <tr id="a_{$a->get_a_id()}">
                        <td><label for="authority_{$a->get_a_id()}">{$a->get_a_title()}</label></td>
                        <td><input class="authorities" value="{$a->get_a_id()}" type="checkbox" name="authorities[]" id="authority_{$a->get_a_id()}" {if $coach->has_authority($a->get_a_id())}checked{/if}></td>
                    </tr>
                {/foreach}
            </table>
        </div>

        <div>
            <div>
                <input class="button black" type="submit" value="Mentés">
            </div>
        </div>

    </form>
</div>

<script type="text/javascript">
    $('.authorities').on('change', function () {
        if ($('#authority_1').is(':checked')) {
            $('.authorities').each(function (k,v) {
                if ($(v).val() > 1) {
                    $(this).prop('checked', false);
                    $(this).prop('disabled', true);
                }
            });
        }
        else {
            $('.authorities').each(function (k,v) {
                if ($(v).val() > 1) {
                    $(this).removeAttr('disabled');
                }
            });
        }
    });

    $(document).ready(function() {
        $('.authorities').trigger('change');
    });
</script>
