<!--
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
    
<div ng-show="user" class="user-edit-panel">
  <div class="clearfix">
    <ol class="breadcrumb pull-left">
      <li><a href="#/users">Users</a></li>
      <li class="active"><span class="glyphicon glyphicon-flash" ng-show="user.admin"></span>{{user.user_name}}</li>
    </ol>
    <div class="pull-right top-margin-4">
      <div ng-switch="isCurrentUser || user.ldap_user">
        <button class="btn deleteuser-btn disabled btn-default" ng-switch-when="true" tooltip="Cannot Delete User">Delete User</button>
        <button class="btn deleteuser-btn btn-danger" ng-switch-when="false" ng-click="deleteUser()">Delete User</button>
      </div>
    </div>
  </div>
  <hr>
  <form class="form-horizontal" role="form" >
    <div class="form-group">
      <label for="" class="col-sm-2 control-label">Type</label>
      <div class="col-sm-10">
        <label for="" class="control-label">{{user.ldap_user ? 'LDAP' : 'Local'}}</label>
      </div>
    </div>
    <div class="form-group">
      <label for="" class="col-sm-2 control-label">Status</label>
      <div class="col-sm-10">
        <toggle-switch on-change="toggleUserActive()" disabled-tooltip="Cannot Change Status" ng-disabled="isCurrentUser" model="user.active" on-label="Active" off-label="Inactive" class="switch-primary userstatus {{user ? '' : 'no-animation'}}" data-off-color="danger"></toggle-switch>
      </div>
    </div>
    <div class="form-group">
      <label for="" class="col-sm-2 control-label"><span class="glyphicon glyphicon-flash"></span> Ambari Admin</label>
      <div class="col-sm-10">
        <toggle-switch on-change="toggleUserAdmin()" disabled-tooltip="Cannot Change Admin" ng-disabled="isCurrentUser" model="user.admin" on-label="Yes" off-label="No" class="switch-primary userstatus {{user ? '' : 'no-animation'}}" data-off-color="danger"></toggle-switch>
      </div>
    </div>
    <div class="form-group">
      <label for="password" class="col-sm-2 control-label">Password</label>
      <div class="col-sm-10">
        <div ng-switch="user.ldap_user">
          <button class="btn deleteuser-btn disabled btn-default" ng-switch-when="true" tooltip="Cannot Change Password">Change Password</button>
          <a href ng-click="openChangePwdDialog()" ng-switch-when="false" class="btn btn-default changepassword">Change Password</a>
        </div>
          
      </div>
    </div>
    <div class="form-group">
      <label for="groups" class="col-sm-2 control-label">{{user.ldap_user ? 'LDAP Group Membership' : 'Local Group Membership'}}</label>
      <div class="col-sm-10">
        <editable-list items-source="editingGroupsList" resource-type="Group" editable="!user.ldap_user"></editable-list>
      </div>
        
    </div>
    <div class="form-group" >
      <label for="" class="col-sm-2 control-label">Privileges</label>
      <div class="col-sm-10">
        <table class="table">
          <thead>
            <tr>
              <th>Resource</th>
              <th>Permissions</th>
            </tr>
          </thead>
          <tbody ng-hide="user.admin">
            <tr ng-repeat="(name, privilege) in privileges.clusters">
              <td>
                <span class="glyphicon glyphicon-cloud"></span> 
                <a href="#/clusters/{{name}}/manageAccess">{{name}}</a>
              </td>
              <td>
                <span tooltip="{{item}}" ng-repeat="item in privilege">{{item | translate}}{{$last ? '' : ', '}}</span>
              </td>
            </tr>
            <tr ng-repeat="(name, privilege) in privileges.views">
              <td>
                <span class="glyphicon glyphicon-th"></span> 
                <a href="#/views/{{privilege.view_name}}/versions/{{privilege.version}}/instances/{{name}}/edit">{{name}}</a>
              </td>
              <td>
                <span tooltip="{{item}}" ng-repeat="item in privilege.privileges">{{item | translate}}{{$last ? '' : ', '}}</span> 
              </td>
            </tr>
          </tbody>
        </table>
        <div class="alert alert-info" ng-show="!privileges && !user.admin">This user does not have any privileges.</div>
        <div class="alert alert-info" ng-show="user.admin">This user is an Ambari Admin and has all privileges.</div>
      </div>
    </div>
  </form>
</div>
  