<div class="modal-header">
    <button type="button" class="close closebtn" data-ng-click="cancel()" aria-hidden="true">&times;</button>
    <h1 class="modal-title">{{'Edit permissions' | translate}}</h1>
</div>
<div class="modal-body">
    <form>
        <p class="alert alert-warning" ng-if="selectedChannel.breakRightsInheritance && selectedChannel.permissionTargetType == null">{{'This channel has seperate permits' | translate}}</p>

        <p class="alert alert-info" ng-if="!selectedChannel.breakRightsInheritance">
            {{'Channel is inheriting its permits from' | translate}}: {{::inheritedChannel.name}}
        </p>

        <p class="alert alert-warning" ng-if="selectedChannel.permissionTargetType == 1">{{'Business App channel. The channel are managed through workspaces or one of the other business apps.' | translate}}</p>
        
        <div class="container-fluid">
            <div class="row" ng-if="selectedChannel.permissionTargetType == null">
                <div class="col-sm-12" style="padding-bottom: 15px;">
                    <button ng-if="!selectedChannel.breakRightsInheritance" type="button" class="btn btn-default" ng-click="breakInheritance()">{{'Break rights' | translate}}</button>
                    <button ng-if="selectedChannel.breakRightsInheritance" type="button" class="btn btn-default" ng-click="inheritrights()">{{'Inherit rights' | translate}}</button>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label for="readRights">{{'Read permissions' | translate}}</label>
                        <div ng-if="selectedChannel.breakRightsInheritance && selectedChannel.permissionTargetType == null">
                            <div class="radio">
                                <label><input type="radio" name="readPermissionsFor" ng-model="readPermissionsFor" ng-value="'none'" ng-change="changeReadPermissionsFor('none')">{{'None' | translate}}</label>
                            </div>
                            <div class="radio">
                                <label><input type="radio" name="readPermissionsFor" ng-model="readPermissionsFor" ng-value="'everybody'" ng-change="changeReadPermissionsFor('everybody')">{{'Everybody' | translate}}</label>
                            </div>
                            <div class="radio">
                                <label><input type="radio" name="readPermissionsFor" ng-model="readPermissionsFor" ng-value="'selected'" ng-change="changeReadPermissionsFor('selected')">{{'Selected' | translate}}</label>
                            </div>
                        </div>
                        <ul class="list-group">
                            <li class="list-group-item" ng-if="selectedChannel.breakRightsInheritance" ng-repeat="rp in selectedChannel.readRightsPrincipals" ng-show="readPermissionsFor == 'selected'">
                                {{(rp.category? '('+rp.category+') ':'')}}{{:: rp.displayName }}<span ng-if="rp.loginName">&nbsp;&lt;{{rp.loginName}}&gt;</span>
                                <button ng-if="selectedChannel.permissionTargetType == null" type="button" class="close" ng-click="removeReadPrincipal(rp.principalID, selectedChannel)"><span aria-hidden="true">&times;</span></button>
                            </li>
                            <li class="list-group-item text-muted" ng-if="!selectedChannel.breakRightsInheritance" ng-repeat="rp in inheritedChannel.readRightsPrincipals">
                                {{(rp.category? '('+rp.category+') ':'')}}{{:: rp.displayName }}<span ng-if="rp.loginName">&nbsp;&lt;{{rp.loginName}}&gt;</span>
                            </li>
                        </ul>
                        <input ng-show="selectedChannel.breakRightsInheritance && selectedChannel.permissionTargetType == null"
                               ng-disabled="readPermissionsFor != 'selected'"
                               type="text"
                               ng-model="readRights"
                               placeholder="{{'Add group or person' | translate}}"
                               typeahead-on-select="addReadPrincipal($model, selectedChannel);"
                               typeahead="user as (user.category? '('+user.category+') ':'')+user.displayName + (user.loginName ? ' - ' + user.loginName : '') for user in searchForPrincipal($viewValue,false) | limitTo:10"
                               typeahead-loading="loadingreadRights"
                               class="form-control"
                               typeahead-min-length="2">
                        <i ng-show="loadingreadRights" class="glyphicon glyphicon-refresh"></i>
                    </div>

                    <div class="form-group">
                        <label for="editRights">{{'Write permissions' | translate}}</label>
                        <div ng-if="selectedChannel.breakRightsInheritance && selectedChannel.permissionTargetType == null">
                            <div class="radio">
                                <label><input type="radio" name="writePermissionsFor" ng-model="writePermissionsFor" ng-value="'none'" ng-change="changeWritePermissionsFor('none')">{{'None' | translate}}</label>
                            </div>
                            <div class="radio">
                                <label><input type="radio" name="writePermissionsFor" ng-model="writePermissionsFor" ng-value="'everybody'" ng-change="changeWritePermissionsFor('everybody')">{{'Everybody' | translate}}</label>
                            </div>
                            <div class="radio">
                                <label><input type="radio" name="writePermissionsFor" ng-model="writePermissionsFor" ng-value="'selected'" ng-change="changeWritePermissionsFor('selected')">{{'Selected' | translate}}</label>
                            </div>
                        </div>
                        <ul class="list-group">
                            <li class="list-group-item" ng-if="selectedChannel.breakRightsInheritance" ng-repeat="wr in selectedChannel.writeRightsPrincipals" ng-show="writePermissionsFor == 'selected'">
                                {{(wr.category? '('+wr.category+') ':'')}}{{:: wr.displayName }}<span ng-if="wr.loginName">&nbsp;&lt;{{wr.loginName}}&gt;</span>
                                <button ng-if="selectedChannel.permissionTargetType == null" type="button" class="close" ng-click="removeWritePrincipal(wr.principalID, selectedChannel)"><span aria-hidden="true">&times;</span></button>
                            </li>
                            <li class="list-group-item text-muted" ng-if="!selectedChannel.breakRightsInheritance" ng-repeat="wr in inheritedChannel.writeRightsPrincipals">
                                {{(wr.category? '('+wr.category+') ':'')}}{{:: wr.displayName }}<span ng-if="wr.loginName">&nbsp;&lt;{{wr.loginName}}&gt;</span>
                            </li>
                        </ul>
                        <input ng-show="selectedChannel.breakRightsInheritance && selectedChannel.permissionTargetType == null" ng-disabled="writePermissionsFor != 'selected'" type="text" ng-model="writeRights" placeholder="{{'Add group or person' | translate}}" typeahead-on-select="addWritePrincipal($model, selectedChannel);" 
                               typeahead="user as (user.category? '('+user.category+') ':'')+user.displayName + (user.loginName ? ' - ' + user.loginName : '') for user in searchForPrincipal($viewValue,false) | limitTo:10" typeahead-loading="loadingwriteRights" class="form-control" typeahead-min-length="2">
                        <i ng-show="loadingwriteRights" class="glyphicon glyphicon-refresh"></i>

                        <label ng-show="writePermissionsFor != 'none' && selectedChannel.permissionTargetType == null">
                            <input type="checkbox" ng-model="selectedChannel.canOnlyEditItsOwn" ng-disabled="!selectedChannel.breakRightsInheritance" ng-change="setCanEditOnlyItsOwn(selectedChannel)">{{'Can only edit its own' | translate}}</label>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default wiz-btn-padding" ng-click="cancel()">{{'Close' | translate}}</button>
</div>


