<div class="col-sm-9 col-md-10 col-sm-push-3 col-md-push-2">

    <ol class="breadcrumb">
        <li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
        <li data-ng-hide="create">{{role.name}}</li>
        <li data-ng-show="create">Add Role</li>
    </ol>

    <h1 data-ng-hide="create"><strong>Role</strong> {{role.name}}</h1>
    <h1 data-ng-show="create"><strong>Add Role</strong></h1>

    <form class="form-horizontal clearfix" name="realmForm" novalidate kc-read-only="!access.manageRealm">
        <fieldset>
            <legend><span class="text">Role</span></legend>
            <div class="form-group">
                <label class="col-md-2 control-label" for="name"><span class="required" data-ng-show="create">*</span> Role name</label>

                <div class="col-md-6">
                    <input class="form-control" type="text" id="name" name="name" data-ng-model="role.name" autofocus
                           required data-ng-readonly="!create">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label" for="description">Description </label>

                <div class="col-md-6">
                    <textarea class="form-control" rows="5" cols="50" id="description" name="description" data-ng-model="role.description"></textarea>
                </div>
            </div>
            <div class="form-group" data-ng-hide="create">
                <label class="col-md-2 control-label" for="compositeSwitch" class="control-label">Composite Roles</label>
                <div class="col-md-6">
                    <input ng-model="compositeSwitch" name="compositeSwitch" id="compositeSwitch" ng-disabled="compositeSwitchDisabled" onoffswitch />
                </div>
                <kc-tooltip>When this role is (un)assigned to a user any role associated with it will be (un)assigned implicitly.</kc-tooltip>
            </div>
        </fieldset>

        <div class="form-group">
            <div class="col-md-10 col-md-offset-2" data-ng-show="create">
                <button kc-save data-ng-show="changed">Save</button>
                <button kc-cancel data-ng-click="cancel()" data-ng-show="changed">Cancel</button>
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-10 col-md-offset-2" data-ng-show="!create && access.manageRealm">
                <button kc-save data-ng-show="changed">Save</button>
                <button kc-reset data-ng-show="changed">Cancel</button>
                <button kc-delete data-ng-click="remove()" data-ng-hide="changed">Delete</button>
            </div>
        </div>

        <fieldset data-ng-show="!create && (compositeSwitch || role.composite)">
            <legend uncollapsed class="collapsible"><span class="text">Composite Roles</span> </legend>
            <div class="form-group">
                <label class="col-md-2 control-label" class="control-label">Realm Roles</label>

                <div class="col-md-10">
                    <div class="row">
                        <div class="col-md-4">
                            <label class="control-label">Available Roles</label>
                            <kc-tooltip>Realm level roles associated with this composite role.</kc-tooltip>
                            <select id="available" class="form-control" multiple size="5"
                                    ng-multiple="true"
                                    ng-model="selectedRealmRoles"
                                    ng-options="r.name for r in realmRoles">
                            </select>
                            <button class="btn btn-default" type="submit" ng-click="addRealmRole()" tooltip="Associate role" tooltip-placement="right">
                                Add selected <i class="fa fa-angle-double-right"></i>
                            </button>
                        </div>
                        <div class="col-md-4">
                            <label class="control-label">Associated Roles</label>
                            <kc-tooltip>Realm level roles associated with this composite role.</kc-tooltip>
                            <select id="assigned" class="form-control" multiple size=5
                                    ng-multiple="true"
                                    ng-model="selectedRealmMappings"
                                    ng-options="r.name for r in realmMappings">
                            </select>
                            <button class="btn btn-default" type="submit" ng-click="deleteRealmRole()" tooltip="Disassociate role" tooltip-placement="left">
                                <i class="fa fa-angle-double-left"></i> Remove selected
                            </button>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-md-2 control-label" class="control-label">
                    <span>Client Roles</span>
                    <select class="form-control" id="clients" name="clients" ng-change="changeClient()" ng-model="compositeClient" ng-options="a.clientId for a in clients" ng-disabled="false"></select>
                </label>

                <div class="col-md-10">
                    <div class="row" data-ng-hide="compositeClient">
                        <div class="col-md-4"><span class="text-muted">Select client to view roles for client</span></div>
                    </div>
                    <div class="row" data-ng-show="compositeClient">
                        <div class="col-md-4">
                            <label class="control-label" for="available-client">Available Roles</label>
                            <kc-tooltip>Roles from this client that you can associate to this composite role.</kc-tooltip>
                            <select id="available-client" class="form-control" multiple size="5"
                                    ng-multiple="true"
                                    ng-model="selectedClientRoles"
                                    ng-options="r.name for r in clientRoles">
                            </select>
                            <button class="btn btn-default" type="submit" ng-click="addClientRole()" tooltip="Associate role" tooltip-placement="right">
                                Add selected <i class="fa fa-angle-right"></i>
                            </button>
                        </div>
                        <div class="col-md-4">
                            <label class="control-label" for="assigned-client">Associated Roles</label>
                            <kc-tooltip>Client roles associated with this composite role.</kc-tooltip>
                            <select id="assigned-client" class="form-control" multiple size=5
                                    ng-multiple="true"
                                    ng-model="selectedClientMappings"
                                    ng-options="r.name for r in clientMappings">
                            </select>
                            <button class="btn btn-default" type="submit" ng-click="deleteClientRole()" tooltip="Disassociate role" tooltip-placement="left">
                                <i class="fa fa-angle-left"></i> Remove selected
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </fieldset>
    </form>
</div>

<kc-menu></kc-menu>