{% extends theme('base.html') %}

{% block head %}
<link rel="stylesheet" type="text/css" href="{{theme_static('css/admin.css')}}" />
{% endblock %}

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

{% block title %}pyLoad - {{_('Users')}}{% endblock %}
{#{% block subtitle %}{{_('Users')}}{% endblock %}#}

{% block content %}
<div class="row">
  <div class="col-sm-5 col-sm-offset-0">
    <div class="alert alert-danger" style="padding:8px;">
      <p class="align-middle">{{ _("To reset default admin login run:") }} <b>pyload -r</b></p>
      <br style="line-height: 2px;">
      <p class="align-middle"><b>{{_('Important:')}}</b> {{_('Admin user have always all permissions!')}}</p>
    </div>
  </div>
</div>

<br>
    <form action="" method="POST">
        <table class="settable table" style="width:50%;">
            <thead>
              <tr>
                <th>{{_('Name')}}</th>
                <th>{{_('Change Password')}}</th>
                <th>{{_('Admin')}}</th>
                <th>{{_('Permissions')}}</th>
                {% if user.is_admin %}
                <th>{{_('Delete?')}}</th>
                {% endif %}
              </tr>
            </thead>

            {% for name, data in users.items() %}
                <tr>
                    <td>{{name}}</td>
                    <td><div class="change_password btn btn-success btn-xs" data-toggle="modal" data-target="#password_box" id="change_pw|{{name}}"><span class="glyphicon glyphicon-pencil"></span> {{_('change')}}</div></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_add" type="button" data-toggle="modal" data-target="#user_box" style="margin-left: 5px;" class="btn btn-default">&nbsp;<span class="glyphicon glyphicon-plus"></span></button>
        <button class="btn btn-primary" type="submit">{{_('Submit')}}</button>
    </form>
{% endblock %}

{% block dialog %}
<div id="password_box" class="modal" role="dialog">
  <div class="modal-dialog modal-sm">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header bg-info text-center" style="padding: 5px" >{{_('Change Password')}}</div>
        <div class="modal-body" style="margin-bottom: 30px;">
        <form id="password_form" class="from-group" action="{{url_for("json.change_password")}}" method="POST" enctype="multipart/form-data" style="margin-bottom: 40px;">
          <p>{{_('Enter your current and desired Password.')}}</p>
          <div class="form-group">
            <label for="user_login">{{_('User')}}</label>
            <input class="form-control" id="user_login" name="user_login" type="text" readonly/>
            <p class="help-block">{{_('Your username.')}}</p>
          </div>
          <div class="form-group">
              <label for="login_current_password">{{_('Current password')}}</label>
              <input class="form-control reveal-pass" id="login_current_password" name="login_current_password" type="password"/>
              <p class="help-block">{{_('The password for this account.')}}</p>
          </div>
          <div class="form-group">
                <label for="login_new_password">{{_('New password')}}</label>
                <input class="form-control reveal-pass" id="login_new_password" name="login_new_password" type="password"/>
                <p class="help-block">{{_('The new password.')}}</p>
          </div>
          <div class="form-group">
                <label for="login_new_password2">{{_('New password (repeat)')}}</label>
                <input class="form-control reveal-pass" id="login_new_password2" name="login_new_password2" type="password" />
                <p class="help-block">{{_('Please repeat the new password.')}}</p>
          </div>
          <button class="btn btn-success" id="login_password_button" type="submit" style="float: right">{{_('Ok')}}</button>
          <button class="btn btn-warning" id="login_password_reset" data-dismiss="modal" style="margin-right: 5px; float: right" type="reset">{{_('Cancel')}}</button>
        </form>
      </div>
    </div>
  </div>
</div>
<div id="user_box" class="modal" role="dialog">
  <div class="modal-dialog modal-sm">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header bg-info text-center" style="padding: 5px;" >{{_('Create new pyLoad login')}}</div>
      <div class="modal-body" style="margin-bottom: 30px;">
        <form id="user_add_form" class="from-group" action="{{url_for('json.add_user')}}" method="POST" enctype="multipart/form-data" style="margin-bottom: 40px;">
          <p>{{_('Enter new user name and password.')}}</p>
          <div class="form-group">
            <label for="new_user">{{_('Login')}}</label>
            <input class="form-control" id="new_user" name="new_user" type="text" autocomplete="off"/>
            <p class="help-block">{{_("New username.")}}</p>
          </div>
          <div class="form-group">
            <label for="new_password">{{ _("Password") }}</label>
            <input class="form-control reveal-pass" id="new_password" name="new_password" type="password"/>
            <p class="help-block">{{ _("The password for the new login.") }}</p>
          </div>
      <div class="form-group">
        <label for="new_password2">{{_('Password (repeat)')}}</label>
        <input class="form-control reveal-pass" id="new_password2" name="new_password2" type="password"/>
        <p class="help-block">{{_('Please repeat the password.')}}</p>
      </div>
          <div class="form-group">
            <label for="new_role">{{ _("Admin") }}</label>
            <input class="form-control" id="new_role" name="new_role" type="checkbox" style="width: auto; height: auto; display: inline;" />
            <p class="help-block">{{ _("Shall the user be an admin?") }}</p>
          </div>
          <div class="form-group">
            <label for="new_perms">{{ _("Permissions") }}</label>
            <select multiple="multiple" id="new_perms" size="{{permlist|length}}" name="new_perms">
              {% for perm in permlist %}
                <option>{{perm}}</option>
              {% endfor %}
            </select>
            <p class="help-block">{{ _("Permmisions for the new user") }}</p>
          </div>
          <button class="btn btn-success" id="new_user_button" type="submit" style="float: right">{{ _("Add") }}</button>
          <button class="btn btn-warning" id="new_user_reset" data-dismiss="modal" style="margin-right: 5px; float: right" type="reset">{{ _("Cancel") }}</button>
        </form>
      </div>
    </div>
  </div>
</div>
{% endblock %}
