<!--
Copyright 2014 Glyptodon LLC.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<div class="view" ng-class="{loading: !isLoaded()}">

    <!-- Main property editor -->
    <div class="header">
        <h2>{{'MANAGE_USER.SECTION_HEADER_EDIT_USER' | translate}}</h2>
        <guac-user-menu></guac-user-menu>
    </div>
    <div class="section">
        <table class="properties">
            <tr>
                <th>{{'MANAGE_USER.FIELD_HEADER_USERNAME' | translate}}</th>
                          
                <td>{{user.username}}</td>
            </tr>
            <tr>
                <th>{{'MANAGE_USER.FIELD_HEADER_PASSWORD' | translate}}</th>
                            
                <td><input ng-model="user.password" type="password" /></td>
            </tr>
            <tr>
                <th>{{'MANAGE_USER.FIELD_HEADER_PASSWORD_AGAIN' | translate}}</th>
                            
                <td><input ng-model="passwordMatch" type="password" /></td>
            </tr>
        </table>
    </div>

    <!-- System permissions section -->
    <h2 class="header">{{'MANAGE_USER.SECTION_HEADER_PERMISSIONS' | translate}}</h2>
    <div class="section">
        <table class="properties">
            <tr ng-repeat="systemPermissionType in systemPermissionTypes">
                <th>{{systemPermissionType.label | translate}}</th>
                <td><input type="checkbox" ng-model="permissionFlags.systemPermissions[systemPermissionType.value]"
                                           ng-change="systemPermissionChanged(systemPermissionType.value)"/></td>
            </tr>
            <tr>
                <th>{{'MANAGE_USER.FIELD_HEADER_CHANGE_OWN_PASSWORD' | translate}}</th>
                <td><input type="checkbox" ng-model="permissionFlags.userPermissions.UPDATE[user.username]"
                                           ng-change="userPermissionChanged('UPDATE', user.username)"/></td>
            </tr>
        </table>
    </div>
        
    <!-- Connection and connection group permission section -->
    <h2 class="header">{{'MANAGE_USER.SECTION_HEADER_CONNECTIONS' | translate}}</h2>
    <div class="section" ng-class="{loading: !rootGroup}">
        <guac-group-list
            context="groupListContext"
            connection-group="rootGroup"
            connection-template="'app/manage/templates/connectionPermission.html'"
            connection-group-template="'app/manage/templates/connectionGroupPermission.html'"
            page-size="20"/>
    </div>

    <!-- Form action buttons -->
    <div class="action-buttons">
        <button ng-show="canSaveUser" ng-click="saveUser()">{{'MANAGE_USER.ACTION_SAVE' | translate}}</button>
        <button ng-click="cancel()">{{'MANAGE_USER.ACTION_CANCEL' | translate}}</button>
        <button ng-show="canDeleteUser" ng-click="deleteUser()" class="danger">{{'MANAGE_USER.ACTION_DELETE' | translate}}</button>
    </div>

</div>
