{% extends 'base.html' %}

{% block head %}
<script type="text/javascript" src="{{theme_template('js/admin.js')}}"></script>
{% endblock %}


{% block title %}{{ _("Profile Permissions") }} - {{ super() }} {% endblock %}
{% block subtitle %}{{ _("Profile Permissions") }}{% endblock %}

{% block content %}

    <a href="#" id="quit-pyload" style="font-size: large; font-weight: bold;">{{_("Quit pyLoad")}}</a> |
    <a href="#" id="restart-pyload" style="font-size: large; font-weight: bold;">{{_("Restart pyLoad")}}</a>
    <br>
    <br>

    {{ _("To reset default admin login run:") }} <b>pyload -r</b><br>
    {{ _("Important: Admin user have always all permissions!") }}

    <form action="" method="POST">
        <table class="settable wide">
            <thead style="font-size: 11px">
            <tr>
            <th>
                {{ _("Name") }}
            </th>
            <th>
                {{ _("Change Password") }}
            </th>
            <th>
                {{ _("Admin") }}
            </th>
            <th>
                {{ _("Permissions") }}
            </th>
            <th>
                {{ _("Delete") }}
            </th></tr>
            </thead>

            {% for name, data in users.items() %}
                <tr>
                    <td>{{ name }}</td>
                    <td><a class="change_password" href="#" id="change_pw|{{name}}">{{ _("change") }}</a></td>
                    <td><input class="is_admin" name="{{ name }}|admin" type="checkbox" {% if data.perms.admin %}
                               checked="checked" {% endif %}/></td>
                    <td>
                        <select id="{{ name }}|perms" multiple="multiple" size="{{ permlist|length }}" name="{{ name }}|perms" {% if data.perms.admin %} disabled="disabled" {% endif %}>
                            {% for perm in permlist %}
                            {% if data.perms[perm] %}
                                <option selected="selected">{{ perm }}</option>
                            {% else %}
                                <option>{{ perm }}</option>
                            {% endif %}
                            {% endfor %}
                        </select>
                    </td>
                  {% if user.is_admin %}
                    <td>
                      {% if user.name != name %}
                        <input id="{{name}}|delete" name="{{name}}|delete" type="checkbox" value="True"/>
                      {% endif %}
                    </td>
                  {% endif %}
                </tr>
            {% endfor %}


        </table>

        <button id="user_submit" class="styled_button" type="submit">{{ _("Submit") }}</button>
        <button id="user_add" style="margin-left: 0" type="submit" class="styled_button">{{_("Add")}}</button>
    </form>
{% endblock %}
{% block hidden %}
    <div id="password_box" class="window_box" style="z-index: 2">
        <form id="password_form" action="{{url_for('json.change_password')}}" method="POST" enctype="multipart/form-data">
            <h1>{{ _("Change Password") }}</h1>

            <p>{{ _("Enter your current and desired Password.") }}</p>
            <label for="user_login">{{ _("User") }}
                <span class="small">{{ _("Your username.") }}</span>
            </label>
            <input id="user_login" name="user_login" type="text" size="20" readonly style="background-color: #eaeaea; cursor: not-allowed"/>

            <label for="login_current_password">{{ _("Current password") }}
                <span class="small">{{ _("The password for this account.") }}</span>
            </label>
            <input id="login_current_password" name="login_current_password" type="password" size="20"/>

            <label for="login_new_password">{{ _("New password") }}
                <span class="small">{{ _("The new password.") }}</span>
            </label>
            <input id="login_new_password" name="login_new_password" type="password" size="20"/>

            <label for="login_new_password2">{{ _("New password (repeat)") }}
                <span class="small">{{ _("Please repeat the new password.") }}</span>
            </label>
            <input id="login_new_password2" name="login_new_password2" type="password" size="20"/>


            <button id="login_password_button" type="submit">{{ _("Submit") }}</button>
            <button id="login_password_reset" style="margin-left: 0" type="reset">{{ _("Reset") }}</button>
            <div class="spacer"></div>

        </form>
    </div>

    <div id="user_box" class="window_box" style="z-index: 2">
        <form id="user_add_form" action="{{url_for('json.add_user')}}" method="POST" enctype="multipart/form-data">
            <h1>{{ _("Create new pyLoad login") }}</h1>

            <p>{{ _("Enter new user name and password.") }}</p>
            <label for="new_user">{{ _("Login") }}
                <span class="small">{{ _("New username.") }}</span>
            </label>
            <input id="new_user" name="new_user" type="text" size="20" autocomplete="off"/>

            <label for="new_password">{{ _("Password") }}
                <span class="small">{{ _("The password for the new login.") }}</span>
            </label>
            <input id="new_password" name="new_password" type="password" size="20"/>

            <label for="new_password2">{{ _("Password (repeat)") }}
                <span class="small">{{ _("Please repeat the password.") }}</span>
            </label>
            <input id="new_password2" name="new_password2" type="password" size="20"/>

            <label for="new_role">{{ _("Admin") }}
              <span class="small">{{ _("Shall the user be an admin?") }}</span>
            </label>
            <input id="new_role" name="new_role" type="checkbox" />

            <label for="new_perms">{{ _("Permissions") }}
              <span class="small">{{ _("Permmisions for the new user.") }}</span>
            </label>
            <select multiple="multiple" id="new_perms" size="{{permlist|length}}" name="new_perms">
              {% for perm in permlist %}
                <option>{{perm}}</option>
              {% endfor %}
            </select>

            <button id="new_user_button" type="submit">{{ _("Submit") }}</button>
            <button id="new_user_reset" style="margin-left: 0" type="reset">{{ _("Reset") }}</button>
            <div class="spacer"></div>

        </form>
    </div>
{% endblock %}
