<div class="modal-header">
    <button type="button" class="close" ng-click="close()" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <h4 class="modal-title"><i class="fa fa-cubes"></i> Edit Collection</h4>
</div>
<form name="form" ng-submit="form.$valid && submit(collection)" api-form="submitPromise" autocomplete="off">
    <div class="modal-body">
        <div class="callout callout-default">
            <h4><i class="fa fa-info-circle"></i> Note</h4>
            <p>
                Select "Users" from the listing options to manage existing users for this collection. Associate new users by
                editing the user's access on the "People" page.
            </p>
            <p>
                You can associate new logins to the collection from your organization's "Vault" or by sharing an existing
                login from "My vault".
            </p>
        </div>
        <div class="callout callout-danger validation-errors" ng-show="form.$errors">
            <h4>Errors have occurred</h4>
            <ul>
                <li ng-repeat="e in form.$errors">{{e}}</li>
            </ul>
        </div>
        <div class="form-group" show-errors>
            <label for="email">Name</label>
            <input type="text" id="name" name="Name" ng-model="collection.name" class="form-control" required api-field />
        </div>
        <div ng-if="useGroups">
            <h4>Group Access</h4>
            <div ng-show="loading && !groups.length">
                Loading groups...
            </div>
            <div ng-show="!loading && !groups.length">
                <p>No groups for your organization.</p>
            </div>
            <div class="table-responsive" ng-show="groups.length" style="margin: 0;">
                <table class="table table-striped table-hover" style="margin: 0;">
                    <thead>
                        <tr>
                            <th style="width: 40px;">
                                <input type="checkbox"
                                       ng-checked="allSelected()"
                                       ng-click="toggleGroupSelectionAll($event)">
                            </th>
                            <th>Name</th>
                            <th style="width: 100px; text-align: center;">Read Only</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="group in groups | orderBy: ['name']">
                            <td valign="middle">
                                <input type="checkbox"
                                       name="selectedGroups[]"
                                       value="{{group.id}}"
                                       ng-checked="groupSelected(group)"
                                       ng-click="toggleGroupSelection(group.id)"
                                       ng-disabled="group.accessAll">
                            </td>
                            <td valign="middle">
                                {{group.name}}
                                <i class="fa fa-unlock text-muted fa-fw" ng-show="group.accessAll"
                                   title="This group can access all items"></i>
                            </td>
                            <td style="width: 100px; text-align: center;" valign="middle">
                                <input type="checkbox"
                                       name="selectedGroupsReadonly[]"
                                       value="{{group.id}}"
                                       ng-disabled="!groupSelected(group) || group.accessAll"
                                       ng-checked="groupSelected(group) && selectedGroups[group.id].readOnly"
                                       ng-click="toggleGroupReadOnlySelection(group)">
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button type="submit" class="btn btn-primary btn-flat" ng-disabled="form.$loading">
            <i class="fa fa-refresh fa-spin loading-icon" ng-show="form.$loading"></i>Submit
        </button>
        <button type="button" class="btn btn-default btn-flat" ng-click="close()">Close</button>
    </div>
</form>
