<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}}/clients">Clients</a></li>
        <li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}">{{client.clientId}}</a></li>
        <li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/roles">Roles</a></li>
        <li data-ng-show="create">Add role</li>
        <li data-ng-hide="create">{{role.name}}</li>
    </ol>

    <h1 data-ng-show="create">Add Role</h1>
    <h1 data-ng-hide="create">{{role.name|capitalize}}<i class="pficon pficon-delete clickable" data-ng-show="!create && access.manageClients" 
    	data-ng-hide="changed" data-ng-click="remove()"></i></h1>

    <form class="form-horizontal" name="realmForm" novalidate kc-read-only="!access.manageClients">

        <fieldset class="border-top">
            <div class="form-group">
                <label class="col-md-2 control-label" for="name">Role name <span class="required" data-ng-show="create">*</span></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>
                    <!-- Replaced by the textarea above <input type="text" id="description" name="description" data-ng-model="role.description" autofocus
                                                           required> -->
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label" for="scopeParamRequired">Scope Param Required </label>
                <kc-tooltip>This role will be granted just if scope parameter with role name is used during authorization/token request.</kc-tooltip>
                <div class="col-md-6">
                    <input ng-model="role.scopeParamRequired" name="scopeParamRequired" id="scopeParamRequired" onoffswitch />
                </div>
            </div>
            <div class="form-group clearfix block" 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 && access.manageClients">
                <button kc-save>Save</button>
                <button kc-cancel data-ng-click="cancel()">Cancel</button>
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-10 col-md-offset-2" data-ng-show="!create && access.manageClients">
                <button kc-save  data-ng-disabled="!changed">Save</button>
                <button kc-reset data-ng-disabled="!changed">Cancel</button>
            </div>
        </div>

        <fieldset data-ng-show="!create && (compositeSwitch || role.composite)">
            <legend uncollapsed><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" for="available">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 ng-disabled="selectedRealmRoles.length == 0" class="btn btn-default" type="submit" ng-click="addRealmRole()">
                                Add selected <i class="fa fa-angle-double-right"></i>
                            </button>
                        </div>
                        <div class="col-md-4">
                            <label class="control-label" for="assigned">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 ng-disabled="selectedRealmMappings.length == 0" class="btn btn-default" type="submit" ng-click="deleteRealmRole()">
                                <i class="fa fa-angle-double-left"></i> Remove selected
                            </button>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group" ng-show="clients.length > 0 && !create && (compositeSwitch || role.composite)">
                <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 ng-disabled="selectedClientRoles.length == 0" class="btn btn-default" type="submit" ng-click="addClientRole()">
                                Add selected <i class="fa fa-angle-double-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 ng-disabled="selectedClientMappings.length == 0" class="btn btn-default" type="submit" ng-click="deleteClientRole()">
                                <i class="fa fa-angle-double-left"></i> Remove selected
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </fieldset>
    </form>
</div>

<kc-menu></kc-menu>