<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-sitemap"></i> Edit Group</h4>
</div>
<form name="form" ng-submit="form.$valid && submit()" 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 group. Associate new users by
                selecting "Groups" the "People" page for a specific user.
            </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="name">Name</label>
            <input type="text" id="name" name="Name" ng-model="group.name" class="form-control" required api-field />
        </div>
        <div class="form-group" show-errors>
            <label for="externalId">External Id</label>
            <input type="text" id="externalId" name="ExternalId" ng-model="group.externalId" class="form-control" api-field />
        </div>
        <h4>Access</h4>
        <div class="radio">
            <label>
                <input type="radio" ng-model="group.accessAll" name="AccessAll"
                       ng-value="true" ng-checked="group.accessAll">
                This group can access and modify <u>all items</u>.
            </label>
        </div>
        <div class="radio">
            <label>
                <input type="radio" ng-model="group.accessAll" name="AccessAll"
                       ng-value="false" ng-checked="!group.accessAll">
                This group can access only the selected collections.
            </label>
        </div>
        <div ng-show="!group.accessAll">
            <div ng-show="loading && !collections.length">
                Loading collections...
            </div>
            <div ng-show="!loading && !collections.length">
                <p>No collections for your organization.</p>
            </div>
            <div class="table-responsive" ng-show="collections.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="toggleCollectionSelectionAll($event)">
                            </th>
                            <th>Name</th>
                            <th style="width: 100px; text-align: center;">Read Only</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="collection in collections | orderBy: ['name']">
                            <td valign="middle">
                                <input type="checkbox"
                                       name="selectedCollections[]"
                                       value="{{collection.id}}"
                                       ng-checked="collectionSelected(collection)"
                                       ng-click="toggleCollectionSelection(collection.id)">
                            </td>
                            <td valign="middle">
                                {{collection.name}}
                            </td>
                            <td style="width: 100px; text-align: center;" valign="middle">
                                <input type="checkbox"
                                       name="selectedCollectionsReadonly[]"
                                       value="{{collection.id}}"
                                       ng-disabled="!collectionSelected(collection)"
                                       ng-checked="collectionSelected(collection) && selectedCollections[collection.id].readOnly"
                                       ng-click="toggleCollectionReadOnlySelection(collection.id)">
                            </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>
