<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 User Groups <small>{{orgUser.email}}</small></h4>
</div>
<form name="form" ng-submit="form.$valid && submit()" api-form="submitPromise" autocomplete="off">
    <div class="modal-body">
        <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 ng-show="loading && !groups.length">
            Loading...
        </div>
        <div ng-show="!loading && !groups.length">
            <p>No groups for your organization.</p>
        </div>
        <p ng-show="groups.length">Edit the groups that this user belongs to.</p>
        <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>
                    </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)">
                        </td>
                        <td valign="middle">
                            {{group.name}}
                        </td>
                    </tr>
                </tbody>
            </table>
        </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>
