<div class="bs-sidebar col-sm-3 " data-ng-include data-src="'partials/realm-menu.html'"></div>
<div id="content-area" class="col-sm-9" role="main">
    <ul class="nav nav-tabs nav-tabs-pf">
        <li><a href="#/realms/{{realm.realm}}/users">User List</a></li>
        <li><a href="#/realms/{{realm.realm}}/user-federation">Federation</a></li>
    </ul>
    <h2></h2>
    <div id="content">
        <h2 class="pull-left"><span>{{realm.realm}}</span> Ldap Server Settings</h2>
        <p class="subtitle"><span class="required">*</span> Required fields</p>
        <form class="form-horizontal" name="realmForm" novalidate kc-read-only="!access.manageRealm">
            
            <fieldset>
                <legend><span class="text">Required Settings</span></legend>
                <div class="form-group clearfix" data-ng-show="!create">
                    <label class="col-sm-2 control-label" for="providerId">Provider ID </label>
                    <div class="col-sm-4">
                        <input class="form-control" id="providerId" type="text" ng-model="instance.id" readonly>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="consoleDisplayName">Console display name </label>
                    <div class="col-sm-4">
                        <input class="form-control" id="consoleDisplayName" type="text" ng-model="instance.displayName" placeholder="defaults to id">
                    </div>
                    <span tooltip-placement="right" tooltip="Display name of provider when linked in admin console." class="fa fa-info-circle"></span>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="priority">Priority </label>
                    <div class="col-sm-4">
                        <input class="form-control" id="priority" type="text" ng-model="instance.priority">
                    </div>
                    <span tooltip-placement="right" tooltip="Priority of provider when doing a user lookup.  Lowest first." class="fa fa-info-circle"></span>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="editMode">Edit mode</label>
                    <div class="col-sm-4">
                        <div class="select-kc">
                            <select id="editMode"
                                    ng-model="instance.config.editMode">
                                <option>READ_ONLY</option>
                                <option>WRITABLE</option>
                                <option>UNSYNCED</option>
                            </select>
                        </div>
                    </div>
                    <span tooltip-placement="right" tooltip="READ_ONLY is a read only LDAP store.  WRITABLE means data will be synced back to LDAP on demand.  UNSYNCED means user data will be imported, but not synced back to LDAP." class="fa fa-info-circle"></span>
                </div>
                <div class="form-group clearfix block">
                    <label class="col-sm-2 control-label" for="syncRegistrations">Sync Registrations</label>
                    <div class="col-sm-4">
                        <input ng-model="syncRegistrations" name="syncRegistrations" id="syncRegistrations" onoffswitch />
                    </div>
                    <span tooltip-placement="right" tooltip="Should newly created users be created within LDAP store?  Priority effects which provider is chose to sync the new user." class="fa fa-info-circle"></span>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="vendor">Vendor</label>
                    <div class="col-sm-4">
                        <div class="select-kc">
                            <select id="vendor"
                                    ng-model="instance.config.vendor"
                                    ng-options="vendor.id as vendor.name for vendor in ldapVendors">
                            </select>
                        </div>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="usernameLDAPAttribute">Username LDAP attribute </label>
                    <div class="col-sm-4">
                        <div class="select-kc">
                            <select id="usernameLDAPAttribute"
                                    ng-model="instance.config.usernameLDAPAttribute"
                                    ng-options="usernameLDAPAttribute for usernameLDAPAttribute in usernameLDAPAttributes">
                            </select>
                        </div>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="userObjectClasses">User Object Classes </label>
                    <div class="col-sm-4">
                        <input class="form-control" id="userObjectClasses" type="text" ng-model="instance.config.userObjectClasses" placeholder="LDAP User Object Classes (div. by comma)">
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="ldapConnectionUrl">Connection URL<span class="required">*</span></label>
                    <div class="col-sm-4">
                        <input class="form-control" id="ldapConnectionUrl" type="text" ng-model="instance.config.connectionUrl" placeholder="LDAP connection URL" required>
                    </div>
                    <div class="col-sm-4" data-ng-show="access.manageRealm">
                        <a class="btn btn-primary" data-ng-click="testConnection()">Test connection</a>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="ldapBaseDn">Base DN <span class="required">*</span></label>
                    <div class="col-sm-4">
                        <input class="form-control" id="ldapBaseDn" type="text" ng-model="instance.config.baseDn" placeholder="LDAP Base DN" required>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="ldapUserDnSuffix">User DN Suffix <span class="required">*</span></label>
                    <div class="col-sm-4">
                        <input class="form-control" id="ldapUserDnSuffix" type="text" ng-model="instance.config.userDnSuffix" placeholder="LDAP User DN Suffix" required>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="ldapBindDn">Bind DN <span class="required">*</span></label>
                    <div class="col-sm-4">
                        <input class="form-control" id="ldapBindDn" type="text" ng-model="instance.config.bindDn" placeholder="LDAP Bind DN" required>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="ldapBindCredential">Bind Credential <span class="required">*</span></label>
                    <div class="col-sm-4">
                        <input class="form-control" id="ldapBindCredential" type="text" ng-model="instance.config.bindCredential" placeholder="LDAP Bind Credentials" required>
                    </div>
                    <div class="col-sm-4" data-ng-show="access.manageRealm">
                        <a class="btn btn-primary" data-ng-click="testAuthentication()">Test authentication</a>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="connectionPooling">Connection pooling</label>
                    <div class="col-sm-4">
                        <input ng-model="connectionPooling" name="connectionPooling" id="connectionPooling" onoffswitch />
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="pagination">Pagination</label>
                    <div class="col-sm-4">
                        <input ng-model="pagination" name="pagination" id="pagination" onoffswitch />
                    </div>
                    <span tooltip-placement="right" tooltip="Does the LDAP server support pagination." class="fa fa-info-circle"></span>
                </div>
                <div class="form-group clearfix" data-ng-show="instance.config.vendor === 'ad' ">
                    <label class="col-sm-2 control-label" for="userAccountControlsAfterPasswordUpdate">Enable Account After Password Update</label>
                    <div class="col-sm-4">
                        <input ng-model="userAccountControlsAfterPasswordUpdate" name="userAccountControlsAfterPasswordUpdate" id="userAccountControlsAfterPasswordUpdate" onoffswitch />
                    </div>
                </div>
            </fieldset>

            <fieldset>
                <legend><span class="text">Sync settings</span></legend>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="batchSizeForSync">Batch size</label>
                    <div class="col-sm-4">
                        <input class="form-control" type="text" ng-model="instance.config.batchSizeForSync" id="batchSizeForSync" />
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="fullSyncEnabled">Periodic full sync</label>
                    <div class="col-sm-4">
                        <input ng-model="fullSyncEnabled" name="fullSyncEnabled" id="fullSyncEnabled" onoffswitch />
                    </div>
                </div>
                <div class="form-group clearfix" data-ng-show="fullSyncEnabled">
                    <label class="col-sm-2 control-label" for="fullSyncPeriod">Full sync period</label>
                    <div class="col-sm-4">
                        <input class="form-control" type="number" ng-model="instance.fullSyncPeriod" id="fullSyncPeriod" />
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="changedSyncEnabled">Periodic changed users sync</label>
                    <div class="col-sm-4">
                        <input ng-model="changedSyncEnabled" name="changedSyncEnabled" id="changedSyncEnabled" onoffswitch />
                    </div>
                </div>
                <div class="form-group clearfix" data-ng-show="changedSyncEnabled">
                    <label class="col-sm-2 control-label" for="changedSyncPeriod">Changed users sync period</label>
                    <div class="col-sm-4">
                        <input class="form-control" type="number" ng-model="instance.changedSyncPeriod" id="changedSyncPeriod" />
                    </div>
                </div>
            </fieldset>

            <div class="pull-right form-actions" data-ng-show="create && access.manageUsers">
                <button kc-cancel data-ng-click="cancel()">Cancel</button>
                <button kc-save data-ng-show="changed">Save</button>
            </div>

            <div class="pull-right form-actions" data-ng-show="!create && access.manageUsers">
                <button kc-reset data-ng-show="changed">Clear changes</button>
                <button kc-save  data-ng-show="changed">Save</button>
                <button kc-delete data-ng-click="remove()" data-ng-hide="changed">Delete</button>
                <button kc-delete data-ng-click="triggerFullSync()" data-ng-hide="changed">Synchronize all users</button>
                <button kc-delete data-ng-click="triggerChangedUsersSync()" data-ng-hide="changed">Synchronize changed users</button>
            </div>
        </form>
    </div>
</div>