<!--
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_CONNECTION.SECTION_HEADER_EDIT_CONNECTION' | translate}}</h2>
        <guac-user-menu></guac-user-menu>
    </div>
    <div class="section">
        <table class="properties">
            
            <!-- Edit connection name -->
            <tr>
                <th>{{'MANAGE_CONNECTION.FIELD_HEADER_NAME' | translate}}</th>
              
                <td><input type="text" ng-model="connection.name" autocorrect="off" autocapitalize="off"/></td>
            </tr>
            
            <!-- Edit connection location -->
            <tr>
                <th>{{'MANAGE_CONNECTION.FIELD_HEADER_LOCATION' | translate}}</th>
              
                <td>
                    <location-chooser value="connection.parentIdentifier" root-group="rootGroup"></location-chooser>
                </td>
            </tr>
            
            
            <!-- Edit connection protocol -->
            <tr>
                <th>{{'MANAGE_CONNECTION.FIELD_HEADER_PROTOCOL' | translate}}</th>
                <td>
                    <select ng-model="connection.protocol" ng-options="name as getProtocolName(protocol.name) | translate for (name, protocol) in protocols | orderBy: name"></select>
                </td>
            </tr>
        </table>
    </div>

    <!-- Connection parameters -->
    <h2 class="header">{{'MANAGE_CONNECTION.SECTION_HEADER_PARAMETERS' | translate}}</h2>
    <div class="section connection-parameters" ng-class="{loading: !parameters}">
        <guac-form namespace="getNamespace(connection.protocol)"
                   content="protocols[connection.protocol].parameters"
                   model="parameters"></guac-form>
    </div>

    <!-- Form action buttons -->
    <div class="action-buttons">
        <button ng-show="canSaveConnection" ng-click="saveConnection()">{{'MANAGE_CONNECTION.ACTION_SAVE' | translate}}</button>
        <button ng-show="canCloneConnection" ng-click="cloneConnection()">{{'MANAGE_CONNECTION.ACTION_CLONE' | translate}}</button>
        <button ng-click="cancel()">{{'MANAGE_CONNECTION.ACTION_CANCEL' | translate}}</button>
        <button ng-show="canDeleteConnection" ng-click="deleteConnection()" class="danger">{{'MANAGE_CONNECTION.ACTION_DELETE' | translate}}</button>
    </div>

    <!-- Connection history -->
    <h2 class="header">{{'MANAGE_CONNECTION.SECTION_HEADER_HISTORY' | translate}}</h2>
    <div class="history section" ng-class="{loading: !historyEntryWrappers}">
        <p ng-hide="historyEntryWrappers.length">{{'MANAGE_CONNECTION.INFO_CONNECTION_NOT_USED' | translate}}</p>

        <!-- History list -->
        <table ng-show="historyEntryWrappers.length">
            <thead>
                <tr>
                    <th>{{'MANAGE_CONNECTION.TABLE_HEADER_HISTORY_USERNAME' | translate}}</th>
                    <th>{{'MANAGE_CONNECTION.TABLE_HEADER_HISTORY_START' | translate}}</th>
                    <th>{{'MANAGE_CONNECTION.TABLE_HEADER_HISTORY_DURATION' | translate}}</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="wrapper in wrapperPage">
                    <td class="username">{{wrapper.entry.username}}</td>
                    <td class="start">{{wrapper.entry.startDate | date:historyDateFormat}}</td>
                    <td class="duration">{{wrapper.durationText | translate:"{VALUE: wrapper.duration.value, UNIT: wrapper.duration.unit}"}}</td>
                </tr>
            </tbody>
        </table>

        <!-- Pager controls for history list -->
        <guac-pager page="wrapperPage" items="historyEntryWrappers"></guac-pager>

    </div>

</div>
