<!-- Modal subscription -->
<div class="modal fade" id="subscriptionRequiredModal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">{{ 'users.subscriptionDialog.title' | tr }}</h4>
      </div>
      <div class="modal-body">
        <p>To add more users, please setup a paid plain.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'main.dialog.cancel' | tr }}</button>
        <button type="button" class="btn btn-success" ng-click="openSubscriptionSetup()">{{ 'users.subscriptionDialog.setupAction' | tr }}</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal subscription group -->
<div class="modal fade" id="subscriptionRequiredGroupModal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">{{ 'users.subscriptionDialog.title' | tr }}</h4>
      </div>
      <div class="modal-body">
        <p>User groups are part of the business plan.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'main.dialog.cancel' | tr }}</button>
        <button type="button" class="btn btn-success" ng-click="openSubscriptionSetup()">{{ 'users.subscriptionDialog.setupAction' | tr }}</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal add user -->
<div class="modal fade" id="userAddModal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">{{ 'users.addUserDialog.title' | tr }}</h4>
      </div>
      <div class="modal-body">
        <form name="useradd_form" role="form" ng-submit="useradd.submit()" autocomplete="off">
          <div class="form-group" ng-class="{ 'has-error': (useradd_form.displayName.$dirty && useradd_form.displayName.$invalid) || (!useradd_form.displayName.$dirty && useradd.error.displayName) }">
            <label class="control-label">{{ 'users.user.fullName' | tr }}</label>
            <div class="control-label" ng-show="(!useradd_form.displayName.$dirty && useradd.error.displayName) || (useradd_form.displayName.$dirty && useradd_form.displayName.$invalid) || (!useradd_form.displayName.$dirty && useradd.error.displayName)">
              <small ng-show="useradd_form.displayName.$error.displayName">{{ 'users.user.errorNotValidFullName' | tr }}</small>
              <small ng-show="!useradd_form.displayName.$dirty && useradd.error.displayName">{{ useradd.error.displayName }}</small>
            </div>
            <input type="text" class="form-control" ng-model="useradd.displayName" name="displayName" id="inputUserAddDisplayName" ng-required autofocus autocomplete="off">
          </div>

          <input type="password" style="display: none;">
          <div class="form-group" ng-class="{ 'has-error': (useradd_form.email.$dirty && useradd_form.email.$invalid) || (!useradd_form.email.$dirty && useradd.error.email) }">
            <label class="control-label">{{ 'users.user.email' | tr }}</label>
            <div class="control-label" ng-show="(!useradd_form.email.$dirty && useradd.error.email) || (useradd_form.email.$dirty && useradd_form.email.$invalid) || (!useradd_form.email.$dirty && useradd.error.email)">
              <small ng-show="useradd_form.email.$error.required">{{ 'users.user.errorEmailRequired' | tr }}</small>
              <small ng-show="useradd_form.email.$error.email">{{ 'users.user.errorInvalidEmail' | tr }}</small>
              <small ng-show="!useradd_form.email.$dirty && useradd.error.email">{{ useradd.error.email }}</small>
            </div>
            <input type="email" class="form-control" ng-model="useradd.email" name="email" id="inputUserAddEmail" required>
          </div>

          <div class="form-group" ng-class="{ 'has-error': (useradd_form.username.$dirty && useradd_form.username.$invalid) || (!useradd_form.username.$dirty && useradd.error.username) }">
            <label class="control-label">{{ 'users.user.username' | tr }}</label>
            <div class="control-label" ng-show="(!useradd_form.username.$dirty && useradd.error.username) || (useradd_form.username.$dirty && useradd_form.username.$invalid) || (!useradd_form.username.$dirty && useradd.error.username)">
              <small ng-show="useradd_form.username.$error.username">{{ 'users.user.errorInvalidUsername' | tr }}</small>
              <small ng-show="!useradd_form.username.$dirty && useradd.error.username">{{ useradd.error.username }}</small>
            </div>
            <input type="text" class="form-control" ng-model="useradd.username" name="username" id="inputUserAddUsername" placeholder="{{ 'users.user.usernamePlaceholder' | tr }}">
          </div>

          <div class="form-group" ng-show="userInfo.isAtLeastAdmin">
            <label class="control-label">{{ 'users.user.role' | tr }} <sup><a ng-href="https://docs.cloudron.io/user-management/#roles" class="help" target="_blank"><i class="fa fa-question-circle"></i></a></sup></label>
            <div class="control-label">
              <select class="form-control" uib-tooltip="{{ config.features.userRoles ? '' : 'Only available in the business plan' }}" ng-disabled="!config.features.userRoles" ng-model="useradd.role" ng-options="role.id as role.name disable when role.disabled for role in roles"></select>
            </div>
          </div>

          <div class="form-group">
            <label class="control-label">{{ 'users.user.groups' | tr }}</label>
            <div class="control-label">
              <div ng-show="groups.length === 0">{{ 'users.user.noGroups' | tr }}</div>
              <multiselect ng-show="groups.length !== 0" ng-model="useradd.selectedGroups" options="group.name for group in groups" data-compare-by="name" data-multiple="true" filter-after-rows="5" scroll-after-rows="10"></multiselect>
            </div>
          </div>

          <div class="checkbox">
            <label>
              <input type="checkbox" ng-model="useradd.sendInvite" id="inputUserAddSendInvite"> {{ 'users.addUserDialog.sendInviteCheckbox' | tr }}
            </label>
          </div>
          <input class="ng-hide" type="submit" ng-disabled="useradd_form.$invalid || useradd.busy"/>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'main.dialog.cancel' | tr }}</button>
        <button type="button" class="btn btn-success" ng-click="useradd.submit()" ng-disabled="useradd_form.$invalid || useradd.busy"><i class="fa fa-circle-notch fa-spin" ng-show="useradd.busy"></i> {{ 'users.addUserDialog.addUserAction' | tr }}</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal transfer ownership -->
<div class="modal fade" id="transferOwnershipModal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">{{ 'users.transferOwnershipDialog.title' | tr }}</h4>
      </div>
      <div class="modal-body">
        <p class="text-bold text-danger" ng-show="transferOwnership.error">{{ transferOwnership.error }}</p>
        <p>{{ 'users.transferOwnershipDialog.description' | tr }}</p>
        <div class="form-group">
          <label class="control-label">{{ 'users.transferOwnershipDialog.newOwner' | tr }}</label>
          <div class="control-label">
            <multiselect ng-model="transferOwnership.selectedUser" options="user.username for user in users" data-compare-by="id" data-multiple="false" filter-after-rows="5" scroll-after-rows="10"></multiselect>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'main.dialog.cancel' | tr }}</button>
        <button type="button" class="btn btn-danger" ng-click="transferOwnership.submit()" ng-hide="transferOwnership.error" ng-disabled="!transferOwnership.selectedUser || transferOwnership.busy"><i class="fa fa-circle-notch fa-spin" ng-show="transferOwnership.busy"></i> {{ 'users.transferOwnershipDialog.transferAction' | tr }}</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal remove user -->
<div class="modal fade" id="userRemoveModal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">{{ 'users.deleteUserDialog.title' | tr:{ username: (userremove.userInfo.username || userremove.userInfo.email) } }}</h4>
      </div>
      <div class="modal-body">
        <p class="text-bold text-danger" ng-show="userremove.error">{{ userremove.error }}</p>
        <p ng-hide="userremove.error">{{ 'users.deleteUserDialog.description' | tr }}</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'main.dialog.cancel' | tr }}</button>
        <button type="button" class="btn btn-danger" ng-click="userremove.submit()" ng-hide="userremove.error" ng-disabled="userremove.busy"><i class="fa fa-circle-notch fa-spin" ng-show="userremove.busy"></i> {{ 'users.deleteUserDialog.deleteAction' | tr }}</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal edit user -->
<div class="modal fade" id="userEditModal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">{{ 'users.editUserDialog.title' | tr:{ username: (useredit.userInfo.username || useredit.userInfo.email) } }}</h4>
      </div>
      <div class="modal-body">
        <div ng-show="useredit.source">
          <p class="text-warning">{{ 'users.editUserDialog.externalLdapWarning' | tr }}</p>
          <p><label>{{ 'users.user.displayName' | tr }}</label><br/><input type="text" class="form-control" ng-disabled="true" ng-model="useredit.displayName">
          <p><label>{{ 'users.user.email' | tr }}</label><br/><input type="text" class="form-control" ng-disabled="true" ng-model="useredit.email"></p>
        </div>

        <form name="useredit_form" role="form" ng-submit="useredit.submit()" autocomplete="off">
          <p class="has-error text-center" ng-show="useredit.error.generic">{{ useredit.error.generic }}</p>

          <div class="form-group" ng-hide="useredit.source" ng-class="{ 'has-error': (useredit_form.displayName.$dirty && useredit_form.displayName.$invalid) || (!useredit_form.displayName.$dirty && useredit.error.displayName) }">
            <label class="control-label">{{ 'users.user.displayName' | tr }}</label>
            <div class="control-label" ng-show="(!useredit_form.displayName.$dirty && useredit.error.displayName) || (useredit_form.displayName.$dirty && useredit_form.displayName.$invalid) || (!useredit_form.displayName.$dirty && useredit.error.displayName)">
              <small ng-show="useredit_form.displayName.$error.required">{{ 'users.user.errorDisplayNameRequired' | tr }}</small>
              <small ng-show="!useredit_form.displayName.$dirty && useredit.error.displayName">{{ useredit.error.displayName }}</small>
            </div>
            <input type="text" class="form-control" ng-model="useredit.displayName" name="displayName" required autofocus autocomplete="off">
          </div>
          <div class="form-group" ng-hide="useredit.source" ng-class="{ 'has-error': (useredit_form.email.$dirty && useredit_form.email.$invalid) || (!useredit_form.email.$dirty && useredit.error.email) }">
            <label class="control-label">{{ 'users.user.primaryEmail' | tr }}</label>
            <div class="control-label" ng-show="(!useredit_form.email.$dirty && useredit.error.email) || (useredit_form.email.$dirty && useredit_form.email.$invalid) || (!useredit_form.email.$dirty && useredit.error.email)">
              <small ng-show="useredit_form.email.$error.required">{{ 'users.user.errorEmailRequired' | tr }}</small>
              <small ng-show="useredit_form.email.$error.email">{{ 'users.user.errorInvalidEmail' | tr }}</small>
              <small ng-show="!useredit_form.email.$dirty && useredit.error.email">{{ useredit.error.email }}</small>
            </div>
            <input type="email" class="form-control" ng-model="useredit.email" name="email" required>
          </div>
          <div class="form-group" ng-hide="useredit.source" ng-class="{ 'has-error': (useredit_form.fallbackEmail.$dirty && useredit_form.fallbackEmail.$invalid) || (!useredit_form.fallbackEmail.$dirty && useredit.error.fallbackEmail) }">
            <label class="control-label">{{ 'users.user.recoveryEmail' | tr }}</label>
            <div class="control-label" ng-show="(!useredit_form.fallbackEmail.$dirty && useredit.error.fallbackEmail) || (useredit_form.fallbackEmail.$dirty && useredit_form.fallbackEmail.$invalid) || (!useredit_form.fallbackEmail.$dirty && useredit.error.fallbackEmail)">
              <small ng-show="useredit_form.fallbackEmail.$error.required">{{ 'users.user.errorEmailRequired' | tr }}</small>
              <small ng-show="useredit_form.fallbackEmail.$error.fallbackEmail">{{ 'users.user.errorInvalidEmail' | tr }}</small>
              <small ng-show="!useredit_form.fallbackEmail.$dirty && useredit.error.fallbackEmail">{{ useredit.error.fallbackEmail }}</small>
            </div>
            <input type="fallbackEmail" class="form-control" ng-model="useredit.fallbackEmail" name="fallbackEmail" required>
          </div>
          <div class="form-group" ng-show="!isMe(useredit.userInfo) && userInfo.isAtLeastAdmin">
            <label class="control-label">{{ 'users.user.role' | tr }} <sup><a ng-href="https://docs.cloudron.io/user-management/#roles" class="help" target="_blank"><i class="fa fa-question-circle"></i></a></sup></label>
            <div class="control-label">
              <select class="form-control" uib-tooltip="{{ config.features.userRoles ? '' : 'Only available in the business plan' }}" ng-disabled="!config.features.userRoles" ng-model="useredit.role" ng-options="role.id as role.name disable when role.disabled for role in roles"></select>
            </div>
          </div>
          <div class="form-group">
            <label class="control-label">{{ 'users.user.groups' | tr }}</label>
            <div class="control-label">
              <div ng-show="groups.length === 0">{{ 'users.user.noGroups' | tr }}</div>
              <multiselect ng-show="groups.length !== 0" ng-model="useredit.selectedGroups" options="group.name for group in groups" data-compare-by="id" data-multiple="true" filter-after-rows="5" scroll-after-rows="10"></multiselect>
            </div>
          </div>
          <div class="form-group" ng-hide="isMe(useredit.userInfo)">
            <div class="checkbox">
              <label>
                <input type="checkbox" ng-model="useredit.active"> {{ 'users.user.activeCheckbox' | tr }} <sup><a ng-href="https://docs.cloudron.io/user-management/#disable-user" class="help" target="_blank"><i class="fa fa-question-circle"></i></a></sup>
              </label>
            </div>
          </div>
          <input class="hide" type="submit" ng-disabled="useredit_form.$invalid || useredit.busy"/>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'main.dialog.cancel' | tr }}</button>
        <button type="button" class="btn btn-success" ng-click="useredit.submit()" ng-disabled="useredit_form.$invalid || useredit.busy"><i class="fa fa-circle-notch fa-spin" ng-show="useredit.busy"></i> {{ 'main.dialog.save' | tr }}</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal add group -->
<div class="modal fade" id="groupAddModal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">{{ 'users.addGroupDialog.title' | tr }}</h4>
      </div>
      <div class="modal-body">
        <form name="groupAddForm" role="form" novalidate ng-submit="groupAdd.submit()" autocomplete="off">
          <div class="form-group" ng-class="{ 'has-error': (groupAddForm.name.$dirty && groupAddForm.name.$invalid) || (!groupAddForm.name.$dirty && groupAdd.error.name) }">
            <label class="control-label" for="groupAddName">{{ 'users.group.name' | tr }}</label>
            <div class="control-label" ng-show="(!groupAddForm.name.$dirty && groupAdd.error.name) || (groupAddForm.name.$dirty && groupAddForm.name.$invalid) || (!groupAddForm.name.$dirty && groupAdd.error.name)">
              <small ng-show="groupAddForm.name.$error.required">{{ 'users.group.errorNameRequired' | tr }}</small>
              <small ng-show="groupAddForm.name.$error.minlength">{{ 'users.group.errorNameTooShort' | tr }}</small>
              <small ng-show="groupAddForm.name.$error.maxlength">{{ 'users.group.errorNameTooLong' | tr }}</small>
              <small ng-show="!groupAddForm.name.$dirty && groupAdd.error.name">{{ groupAdd.error.name }}</small>
            </div>
            <input type="text" class="form-control" ng-model="groupAdd.name" id="groupAddName" name="name" ng-maxlength="200" ng-minlength="1" required autofocus>
          </div>
          <div class="form-group">
            <label class="control-label">{{ 'users.group.users' | tr }}</label>
            <div class="control-label">
              <multiselect ng-model="groupAdd.selectedUsers" options="(user.username || user.email) for user in allUsers" data-compare-by="email" data-multiple="true" filter-after-rows="5" scroll-after-rows="10"></multiselect>
            </div>
          </div>
          <input class="hide" type="submit" ng-disabled="groupAddForm.$invalid || groupAdd.busy"/>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'main.dialog.cancel' | tr }}</button>
        <button type="button" class="btn btn-success" ng-click="groupAdd.submit()" ng-disabled="groupAddForm.$invalid || groupAdd.busy"><i class="fa fa-circle-notch fa-spin" ng-show="groupAdd.busy"></i> {{ 'users.group.addGroupAction' | tr }}</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal edit group -->
<div class="modal fade" id="groupEditModal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">{{ 'users.editGroupDialog.title' | tr:{ name: groupEdit.groupInfo.name } }}</h4>
      </div>
      <div class="modal-body">
        <p class="text-warning" ng-show="groupEdit.source">{{ 'users.editGroupDialog.externalLdapWarning' | tr }}</p>

        <form name="groupEdit_form" role="form" ng-submit="groupEdit.submit()" autocomplete="off">
          <div class="form-group" ng-class="{ 'has-error': groupEditForm.groupName.$invalid }">
            <label class="control-label">{{ 'users.group.name' | tr }}</label>
            <input type="text" class="form-control" ng-model="groupEdit.name" name="groupName" ng-disabled="groupEdit.busy || groupEdit.source" autofocus>
          </div>
          <div class="form-group">
            <label class="control-label">{{ 'users.group.users' | tr }}</label>
            <div class="control-label">
              <multiselect ng-model="groupEdit.selectedUsers" options="(user.username || user.email) for user in allUsers" data-compare-by="email" data-multiple="true" filter-after-rows="5" scroll-after-rows="10"></multiselect>
            </div>
          </div>
          <div class="form-group">
            <label class="control-label">Access to Apps</label>
            <div class="control-label">
              <multiselect ng-model="groupEdit.selectedApps" options="(app.label || app.fqdn) for app in groupEdit.apps" data-compare-by="fqdn" data-multiple="true" filter-after-rows="5" scroll-after-rows="10"></multiselect>
            </div>
          </div>
          <input class="hide" type="submit" ng-disabled="groupEdit_form.$invalid || useredit.busy"/>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'main.dialog.cancel' | tr }}</button>
        <button type="button" class="btn btn-success" ng-click="groupEdit.submit()" ng-disabled="groupEdit_form.$invalid || groupEdit.busy"><i class="fa fa-circle-notch fa-spin" ng-show="groupEdit.busy"></i> {{ 'main.dialog.save' | tr }}</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal remove group -->
<div class="modal fade" id="groupRemoveModal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">{{ 'users.deleteGroupDialog.title' | tr:{ name: groupRemove.group.name } }}</h4>
      </div>
      <div class="modal-body">
        <div ng-show="groupRemove.memberCount" class="text-danger">
          <b>{{ 'users.deleteGroupDialog.description' | tr:{ memberCount: groupRemove.memberCount } }}</b>
          <br/>
          <br/>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'main.dialog.cancel' | tr }}</button>
        <button type="button" class="btn btn-danger" ng-click="groupRemove.submit()" ng-disabled="groupRemove.busy"><i class="fa fa-circle-notch fa-spin" ng-show="groupRemove.busy"></i> {{ 'users.deleteGroupDialog.deleteAction' | tr }}</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal invite -->
<div class="modal fade" id="invitationModal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">{{ 'users.passwordResetDialog.title' | tr:{ username: (invitation.user.username || invitation.user.email) } }}</h4>
      </div>
      <div class="modal-body">
        <p>{{ 'users.passwordResetDialog.description' | tr:{ username: (invitation.user.username || invitation.user.email) } }}</p>
        <div class="input-group">
          <input type="text" id="setupLinkInput" class="form-control" ng-value="invitation.setupLink" readonly/>
          <span class="input-group-btn">
            <button class="btn btn-default" id="setupLinkButton" type="button" data-clipboard-target="#setupLinkInput"><i class="fa fa-clipboard"></i></button>
          </span>
        </div>
        <br/>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'main.dialog.cancel' | tr }}</button>
        <button type="button" class="btn btn-success" ng-click="invitation.email()" ng-disabled="invitation.busy"><i class="fa fa-circle-notch fa-spin" ng-show="invitation.busy"></i> {{ 'users.passwordResetDialog.sendEmailLinkAction' | tr }}</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal external ldap -->
<div class="modal fade" id="externalLdapModal" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">{{ 'users.externalLdapDialog.title' | tr }}</h4>
      </div>
      <div class="modal-body">
        <p class="has-error text-center" ng-show="externalLdap.error.generic">{{ externalLdap.error.generic }}</p>

        <div class="form-group">
          <label class="control-label" for="ldapProvider">{{ 'users.externalLdap.provider' | tr }} <sup><a ng-href="https://docs.cloudron.io/user-management/#external-ldap" class="help" target="_blank"><i class="fa fa-question-circle"></i></a></sup></label>
          <select class="form-control" id="ldapProvider" ng-model="externalLdap.provider" ng-options="a.value as a.name for a in ldapProvider"></select>
        </div>

        <div uib-collapse="externalLdap.provider === 'noop'">
          <form name="externalLdapConfigForm" role="form" novalidate ng-submit="externalLdap.submit()" autocomplete="off">
            <fieldset>
              <!-- avoid browsers to attempt an autofill for bindDN/bindPassword -->
              <input type="password" style="display: none;">

              <div class="form-group" ng-class="{ 'has-error': externalLdap.error.url }">
                <label class="control-label" for="inputExternalLdapConfigUrl">{{ 'users.externalLdap.server' | tr }}</label>
                <input type="text" class="form-control" ng-model="externalLdap.url" id="inputExternalLdapConfigUrl" name="url" ng-disabled="externalLdap.busy" placeholder="ldaps://example.com:636" required>
              </div>

              <div class="form-group">
                <div class="checkbox">
                  <label>
                    <input type="checkbox" ng-model="externalLdap.acceptSelfSignedCerts"> {{ 'users.externalLdap.acceptSelfSignedCert' | tr }}
                  </label>
                </div>
                <p class="text-error" ng-show="externalLdap.error.acceptSelfSignedCerts">{{ 'users.externalLdap.errorSelfSignedCert' | tr }}</p>
              </div>

              <div class="form-group" ng-class="{ 'has-error': externalLdap.error.baseDn }">
                <label class="control-label" for="inputExternalLdapConfigBaseDn">{{ 'users.externalLdap.baseDn' | tr }}</label>
                <input type="text" class="form-control" ng-model="externalLdap.baseDn" id="inputExternalLdapConfigBaseDn" name="baseDn" ng-disabled="externalLdap.busy" placeholder="ou=users,dc=example,dc=com" required>
              </div>

              <div class="form-group" ng-class="{ 'has-error': externalLdap.error.filter }">
                <label class="control-label" for="inputExternalLdapConfigFilter">{{ 'users.externalLdap.filter' | tr }}</label>
                <input type="text" class="form-control" ng-model="externalLdap.filter" id="inputExternalLdapConfigFilter" name="filter" ng-disabled="externalLdap.busy" placeholder="(objectClass=inetOrgPerson)" required>
              </div>

              <div class="form-group" ng-class="{ 'has-error': externalLdap.error.usernameField }">
                <label class="control-label" for="inputExternalLdapConfigUsernameField">{{ 'users.externalLdap.usernameField' | tr }}</label>
                <input type="text" class="form-control" ng-model="externalLdap.usernameField" id="inputExternalLdapConfigUsernameField" name="usernameField" ng-disabled="externalLdap.busy" placeholder="uid or sAMAcountName">
              </div>

              <div class="form-group">
                <div class="checkbox">
                  <label>
                    <input type="checkbox" ng-model="externalLdap.syncGroups"> {{ 'users.externalLdap.syncGroups' | tr }}</sup>
                  </label>
                </div>
              </div>

              <div class="form-group" ng-class="{ 'has-error': externalLdap.error.groupBaseDn }" ng-show="externalLdap.syncGroups">
                <label class="control-label" for="inputExternalLdapConfigGroupBaseDn">{{ 'users.externalLdap.groupBaseDn' | tr }}</label>
                <input type="text" class="form-control" ng-model="externalLdap.groupBaseDn" id="inputExternalLdapConfigGroupBaseDn" name="groupBaseDn" ng-disabled="externalLdap.busy" placeholder="ou=groups,dc=example,dc=com" ng-required="externalLdap.syncGroups">
              </div>

              <div class="form-group" ng-class="{ 'has-error': externalLdap.error.groupFilter }" ng-show="externalLdap.syncGroups">
                <label class="control-label" for="inputExternalLdapConfigGroupFilter">{{ 'users.externalLdap.groupFilter' | tr }}</label>
                <input type="text" class="form-control" ng-model="externalLdap.groupFilter" id="inputExternalLdapConfigGroupFilter" name="groupFilter" ng-disabled="externalLdap.busy" placeholder="(objectClass=groupOfNames)" ng-required="externalLdap.syncGroups">
              </div>

              <div class="form-group" ng-class="{ 'has-error': externalLdap.error.groupnameField }" ng-show="externalLdap.syncGroups">
                <label class="control-label" for="inputExternalLdapConfigGroupnameField">{{ 'users.externalLdap.groupnameField' | tr }}</label>
                <input type="text" class="form-control" ng-model="externalLdap.groupnameField" id="inputExternalLdapConfigGroupnameField" name="groupnameField" ng-disabled="externalLdap.busy" placeholder="cn" ng-required="externalLdap.syncGroups">
              </div>

              <div class="form-group" ng-class="{ 'has-error': externalLdap.error.credentials }">
                <label class="control-label" for="inputExternalLdapConfigBindDn">{{ 'users.externalLdap.bindUsername' | tr }}</label>
                <input type="text" class="form-control" ng-model="externalLdap.bindDn" id="inputExternalLdapConfigBindDn" name="bindDn" ng-disabled="externalLdap.busy" placeholder="uid=admin,ou=Users,dc=example,dc=com">
              </div>

              <div class="form-group" ng-class="{ 'has-error': externalLdap.error.credentials }">
                <label class="control-label" for="inputExternalLdapConfigBindPassword">{{ 'users.externalLdap.bindPassword' | tr }}</label>
                <input type="password" class="form-control" ng-model="externalLdap.bindPassword" id="inputExternalLdapConfigBindPassword" name="bindPassword" ng-disabled="externalLdap.busy" placeholder="">
              </div>

              <div class="form-group">
                <div class="checkbox">
                  <label>
                    <input type="checkbox" ng-model="externalLdap.autoCreate"> {{ 'users.externalLdap.autocreateUsersOnLogin' | tr }}
                  </label>
                </div>
              </div>

              <input class="ng-hide" type="submit" ng-disabled="externalLdapConfigForm.$invalid"/>
            </fieldset>
          </form>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'main.dialog.cancel' | tr }}</button>
        <button type="button" class="btn btn-primary" ng-click="externalLdap.submit()" ng-disabled="externalLdapConfigForm.$invalid || externalLdap.busy"><i class="fa fa-circle-notch fa-spin" ng-show="externalLdap.busy"></i> {{ 'main.dialog.save' | tr }}</button>
      </div>
    </div>
  </div>
</div>

<div class="content content-large">

  <div class="text-left">
    <h2>
      {{ 'users.title' | tr }}
      <button class="btn btn-primary btn-outline pull-right" ng-click="useradd.show()">
        <i class="fa fa-user-plus"></i> {{ 'users.newUserAction' | tr }}
      </button>
    </h2>
  </div>

  <div class="row">
    <div class="col-lg-12">
      <div class="users-filter">
        <input type="text" class="form-control" style="min-width: 350px;" ng-model="userSearchString" ng-model-options="{ debounce: 1000 }" ng-change="updateFilter()" placeholder="{{ 'users.searchPlaceholder' | tr }}"/>
        <select class="form-control" ng-model="pageItems" ng-options="a.name for a in pageItemCount" ng-change="updateFilter(true)"></select>
      </div>
      <div class="pagination pull-right">
        <button class="btn btn-default btn-outline" ng-click="showPrevPage()" ng-disabled="userRefreshBusy || currentPage <= 1"><i class="fa fa-angle-double-left"></i> {{ 'main.pagination.prev' | tr }}</button>
        <button class="btn btn-default btn-outline" ng-click="showNextPage()" ng-disabled="userRefreshBusy || users.length < pageItems.value">{{ 'main.pagination.next' | tr }} <i class="fa fa-angle-double-right"></i></button>
      </div>
    </div>
  </div>

  <div>
    <div class="card card-large">
      <div class="grid-item-top">
        <div class="row ng-hide" ng-show="userRefreshBusy">
          <div class="col-lg-12 text-center">
            <h2><i class="fa fa-circle-notch fa-spin"></i></h2>
          </div>
        </div>
        <div class="row ng-hide" ng-hide="userRefreshBusy">
          <div class="col-lg-12">
            <table class="table table-hover" style="margin: 0;">
              <thead>
                <tr>
                  <th style="width: 0.5%;"></th>
                  <th style="width:45%">{{ 'users.users.user' | tr }}</th>
                  <th style="width:49.5%" class="hidden-xs hidden-sm">{{ 'users.users.groups' | tr }}</th>
                  <th style="width: 5%" class="text-right">{{ 'main.actions' | tr }}</th>
                </tr>
              </thead>
              <tbody>
                <tr ng-show="users.length === 0">
                  <td colspan="5" class="text-center text-muted">{{ 'users.users.empty' | tr }}</td>
                </tr>
                <tr ng-repeat="user in users" ng-class="{'text-muted': !user.active}">
                  <td>
                    <i class="fas fa-crown arrow" ng-show="user.active && user.role === 'owner'" uib-tooltip="{{ 'users.users.superadminTooltip' | tr }}" tooltip-class="long nowrap"></i>
                    <i class="fa fa-user-tie arrow" ng-show="user.active && user.role === 'admin'" uib-tooltip="{{ 'users.users.adminTooltip' | tr }}" tooltip-class="long nowrap"></i>
                    <i class="fas fa-users-cog arrow" ng-show="user.active && user.role === 'usermanager'" uib-tooltip="{{ 'users.users.usermanagerTooltip' | tr }}" tooltip-class="long nowrap"></i>
                    <i class="fa fa-ban" ng-show="!user.active" uib-tooltip="{{ 'users.users.inactiveTooltip' | tr }}"></i>
                  </td>
                  <td class="hand elide-table-cell" ng-click="canEdit(user) && useredit.show(user)" ng-show="user.username">
                    {{ user.displayName }} &nbsp; <span class="text-muted">{{ user.username }}</span> &nbsp; <i ng-show="user.source" class="far fa-address-book" uib-tooltip="{{ 'users.users.externalLdapTooltip' | tr }}"></i>
                  </td>
                  <td class="hand elide-table-cell" ng-click="canEdit(user) && useredit.show(user)" ng-hide="user.username">
                    <span class="text-muted" uib-tooltip="{{ 'users.users.notActivatedYetTooltip' | tr }}">{{ user.fallbackEmail }}</span>
                  </td>
                  <td class="text-left hand elide-table-cell hidden-xs hidden-sm" ng-click="canEdit(user) && useredit.show(user)">
                    <span class="group-badge" ng-repeat="groupId in user.groupIds">
                      {{ groupsById[groupId].name }}
                    </span>
                  </td>

                  <td class="text-right no-wrap" style="vertical-align: bottom">
                    <button ng-show="isMe(user) && userInfo.role === 'owner' && user.role === 'owner' && !config.features.userRoles" class="btn btn-xs btn-default" ng-click="transferOwnership.show()" uib-tooltip="{{ 'users.users.transferOwnershipTooltip' | tr }}"><i class="fas fa-random"></i></button>
                    <button ng-disabled="!canEdit(user) || isMe(user) || user.source" class="btn btn-xs btn-default" ng-click="invitation.show(user)" uib-tooltip="{{ 'users.users.resetPasswordTooltip' | tr }}"><i class="fa fa-redo"></i></button>
                    <button ng-disabled="!canEdit(user)" class="btn btn-xs btn-default" ng-click="useredit.show(user)" uib-tooltip="{{ 'users.users.editUserTooltip' | tr }}"><i class="fa fa-pencil-alt"></i></button>
                    <button ng-disabled="!canEdit(user) || isMe(user)" class="btn btn-xs btn-danger" ng-click="userremove.show(user)" uib-tooltip="{{ 'users.users.removeUserTooltip' | tr }}"><i class="far fa-trash-alt"></i></button>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>

  <br/>

  <div class="text-left">
    <h2>
      {{ 'users.groups.title' | tr }}
      <button class="btn btn-primary btn-outline pull-right" ng-click="groupAdd.show()">
        <i class="fa fa-plus"></i> {{ 'users.groups.newGroupAction' | tr }}
      </button>
    </h2>
  </div>

  <div class="card card-large">
    <div class="grid-item-top">
      <div class="row ng-hide" ng-show="!ready">
        <div class="col-lg-12 text-center">
          <h2><i class="fa fa-circle-notch fa-spin"></i></h2>
        </div>
      </div>
      <div class="row animateMeOpacity ng-hide" ng-show="ready">
        <div class="col-lg-12">
          <table class="table table-hover" style="margin: 0;">
            <thead>
              <tr>
                <th style="width: 45%">{{ 'users.groups.name' | tr }}</th>
                <th style="width: 49.5%" class="hidden-xs hidden-sm">{{ 'users.groups.users' | tr }}</th>
                <th style="width: 5%" class="text-right">{{ 'main.actions' | tr }}</th>
              </tr>
            </thead>
            <tbody>
              <tr ng-repeat="group in groups">
                <td class="hand elide-table-cell" style="text-overflow: ellipsis; white-space: nowrap;" ng-click="groupEdit.show(group)">
                  {{ group.name }} &nbsp; <i ng-show="group.source" class="far fa-address-book" uib-tooltip="{{ 'users.groups.externalLdapTooltip' | tr }}"></i>
                </td>
                <td class="hand elide-table-cell" style="text-overflow: ellipsis; white-space: nowrap;" ng-click="groupEdit.show(group)">
                  {{ groupMembers(group) }}
                </td>
                <td class="text-right no-wrap" style="vertical-align: bottom">
                  <button class="btn btn-xs btn-default" ng-click="groupEdit.show(group)" uib-tooltip="Edit Group"><i class="fa fa-pencil-alt"></i></button>
                  <button class="btn btn-xs btn-danger" ng-click="groupRemove.show(group)" uib-tooltip="Remove Group"><i class="far fa-trash-alt"></i></button>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>

  <div class="text-left" style="margin-top: 50px;" ng-show="user.isAtLeastAdmin">
    <h2>{{ 'users.settings.title' | tr }}</h2>
  </div>

  <div class="card card-large" ng-show="user.isAtLeastAdmin">
    <form name="directoryConfigForm" role="form" novalidate ng-submit="directoryConfig.submit()" autocomplete="off">
      <fieldset ng-disabled="directoryConfig.busy || !config.features.directoryConfig">
        <div class="checkbox">
          <label>
            <input type="checkbox" ng-model="directoryConfig.editableUserProfiles"> {{ 'users.settings.allowProfileEditCheckbox' | tr }} <sup><a ng-href="https://docs.cloudron.io/user-management/#lock-profile" class="help" target="_blank"><i class="fa fa-question-circle"></i></a></sup>
          </label>
        </div>
        <div class="checkbox">
          <label>
            <input type="checkbox" ng-model="directoryConfig.mandatory2FA"> {{ 'users.settings.require2FACheckbox' | tr }}
          </label>
        </div>
      </fieldset>
    </form>

    <br/>

    <div class="row" ng-hide="config.features.directoryConfig">
      <div class="col-md-12">
        <span>{{ 'users.settings.subscriptionRequired' | tr }} <a href="" class="pull-right" ng-click="openSubscriptionSetup()">{{ 'users.settings.subscriptionRequiredAction' | tr }}</a></span>
      </div>
    </div>

    <div class="row" ng-show="config.features.directoryConfig">
      <div class="col-md-12">
        <span class="has-error" ng-show="directoryConfig.errorMessage">{{ directoryConfig.errorMessage }}</span>

        <button class="btn btn-outline btn-primary pull-right" ng-click="directoryConfig.submit()" ng-disabled="!directoryConfigForm.$dirty || directoryConfig.busy">
          <i class="fa fa-circle-notch fa-spin" ng-show="directoryConfig.busy"></i> {{ 'users.settings.saveAction' | tr }}
        </button>
      </div>
    </div>

  </div>

  <div class="text-left" style="margin-top: 50px;" ng-show="user.isAtLeastAdmin">
    <h2>{{ 'users.externalLdap.title' | tr }}</h2>
  </div>

  <div class="card card-large" ng-show="user.isAtLeastAdmin">
    <div class="row">
      <div class="col-md-12">{{ 'users.externalLdap.description' | tr }}</div>
    </div>

    <br/>

    <div class="row" ng-hide="config.features.externalLdap">
      <div class="col-md-12">
        {{ 'users.externalLdap.subscriptionRequired' | tr }} <a href="" class="pull-right" ng-click="openSubscriptionSetup()">{{ 'users.externalLdap.subscriptionRequiredAction' | tr }}</a>
      </div>
    </div>

    <div ng-show="config.features.externalLdap">

      <div class="row" ng-show="externalLdap.currentConfig.provider === 'noop'">
        <div class="col-xs-12">
          <span class="text-muted">{{ 'users.externalLdap.noopInfo' | tr }}</span>
        </div>
      </div>

      <div class="row" ng-show="externalLdap.currentConfig.provider !== 'noop'">
        <div class="col-xs-6">
          <span class="text-muted">{{ 'users.externalLdap.provider' | tr }}</span>
        </div>
        <div class="col-xs-6 text-right">
          <span>{{ externalLdap.currentConfig.provider }}</span>
        </div>
      </div>

      <div class="row" ng-show="externalLdap.currentConfig.provider !== 'noop'">
        <div class="col-xs-6">
          <span class="text-muted">{{ 'users.externalLdap.server' | tr }}</span>
        </div>
        <div class="col-xs-6 text-right">
          <span>{{ externalLdap.currentConfig.url }}</span>
        </div>
      </div>

      <div class="row" ng-show="externalLdap.currentConfig.provider !== 'noop'">
        <div class="col-xs-6">
          <span class="text-muted">{{ 'users.externalLdap.acceptSelfSignedCert' | tr }}</span>
        </div>
        <div class="col-xs-6 text-right">
          <span>{{ externalLdap.currentConfig.acceptSelfSignedCerts ? 'Yes' : 'No' }}</span>
        </div>
      </div>

      <div class="row" ng-show="externalLdap.currentConfig.provider !== 'noop'">
        <div class="col-xs-6">
          <span class="text-muted">{{ 'users.externalLdap.baseDn' | tr }}</span>
        </div>
        <div class="col-xs-6 text-right">
          <span>{{ externalLdap.currentConfig.baseDn }}</span>
        </div>
      </div>

      <div class="row" ng-show="externalLdap.currentConfig.provider !== 'noop'">
        <div class="col-xs-6">
          <span class="text-muted">{{ 'users.externalLdap.filter' | tr }}</span>
        </div>
        <div class="col-xs-6 text-right">
          <span>{{ externalLdap.currentConfig.filter }}</span>
        </div>
      </div>

      <div class="row" ng-show="externalLdap.currentConfig.provider !== 'noop'">
        <div class="col-xs-6">
          <span class="text-muted">{{ 'users.externalLdap.usernameField' | tr }}</span>
        </div>
        <div class="col-xs-6 text-right">
          <span>{{ externalLdap.currentConfig.usernameField || 'uid' }}</span>
        </div>
      </div>

      <div class="row" ng-show="externalLdap.currentConfig.provider !== 'noop'">
        <div class="col-xs-6">
          <span class="text-muted">{{ 'users.externalLdap.syncGroups' | tr }}</span>
        </div>
        <div class="col-xs-6 text-right">
          <span>{{ externalLdap.currentConfig.syncGroups ? 'Yes' : 'No' }}</span>
        </div>
      </div>

      <div class="row" ng-show="externalLdap.currentConfig.provider !== 'noop' && externalLdap.currentConfig.syncGroups">
        <div class="col-xs-6">
          <span class="text-muted">{{ 'users.externalLdap.groupBaseDn' | tr }}</span>
        </div>
        <div class="col-xs-6 text-right">
          <span>{{ externalLdap.currentConfig.groupBaseDn }}</span>
        </div>
      </div>

      <div class="row" ng-show="externalLdap.currentConfig.provider !== 'noop' && externalLdap.currentConfig.syncGroups">
        <div class="col-xs-6">
          <span class="text-muted">{{ 'users.externalLdap.groupFilter' | tr }}</span>
        </div>
        <div class="col-xs-6 text-right">
          <span>{{ externalLdap.currentConfig.groupFilter }}</span>
        </div>
      </div>

      <div class="row" ng-show="externalLdap.currentConfig.provider !== 'noop' && externalLdap.currentConfig.syncGroups">
        <div class="col-xs-6">
          <span class="text-muted">{{ 'users.externalLdap.groupnameField' | tr }}</span>
        </div>
        <div class="col-xs-6 text-right">
          <span>{{ externalLdap.currentConfig.groupnameField }}</span>
        </div>
      </div>

      <div class="row" ng-show="externalLdap.currentConfig.provider !== 'noop'">
        <div class="col-xs-6">
          <span class="text-muted">{{ 'users.externalLdap.auth' | tr }}</span>
        </div>
        <div class="col-xs-6 text-right">
          <span>{{ externalLdap.currentConfig.bindDn ? 'Yes' : 'No' }}</span>
        </div>
      </div>

      <div class="row" ng-show="externalLdap.currentConfig.provider !== 'noop'">
        <div class="col-xs-6">
          <span class="text-muted">{{ 'users.externalLdap.autocreateUsersOnLogin' | tr }}</span>
        </div>
        <div class="col-xs-6 text-right">
          <span>{{ externalLdap.currentConfig.autoCreate ? 'Yes' : 'No' }}</span>
        </div>
      </div>

      <div class="row">
        <br/>
        <div class="col-md-12" style="margin-bottom: 10px;">
          <div ng-show="externalLdap.syncBusy" class="progress progress-striped active animateMe">
            <div class="progress-bar progress-bar-success" role="progressbar" style="width: {{ externalLdap.percent }}%"></div>
          </div>
        </div>
      </div>

      <div class="row">
        <div class="col-md-6">
          <p ng-show="externalLdap.syncBusy">{{ externalLdap.message }}</p>
          <p ng-hide="externalLdap.syncBusy">
            <div class="has-error" ng-show="!externalLdap.active">{{ externalLdap.errorMessage }}</div>
          </p>
        </div>

        <div class="col-md-6 text-right">
          <button class="btn btn-primary pull-right" ng-click="externalLdap.show()">{{ 'users.externalLdap.configureAction' | tr }}</button>
          <button class="btn btn-success pull-right" ng-disabled="externalLdap.currentConfig.provider === 'noop'" ng-click="externalLdap.sync()"><i class="fa fa-circle-notch fa-spin" ng-show="externalLdap.syncBusy"></i> {{ 'users.externalLdap.syncAction' | tr }}</button>
          <a class="btn btn-primary pull-right" ng-show="externalLdap.taskId" ng-href="/logs.html?taskId={{ externalLdap.taskId }}" target="_blank">{{ 'users.externalLdap.showLogsAction' | tr }}</a>
        </div>
      </div>
    </div>

  </div>
</div>
