
<div id="newsChannels" ng-controller="Wizdom365NoticeboardNewsChannelsController" class="lt-module-page">

    <div class="lt-module-page__top lt-module-page-top">
        <div class="lt-module-page-top__title">
            <h1>Noticeboard Channels</h1>
        </div>
        <div class="lt-module-page-top__actions">
            <button type="button" class="btn btn-primary" ng-click="createEditChannel()">{{'Create channel' | translate}}</button>
        </div>
    </div>



    <!----------------------------------- Default channels permissions --------------------------------------->
    <div class="lt-module-page__content-accordion">
        <accordion>
            <accordion-group is-open="panelExpanded">
                <accordion-heading class="panel-title">
                    <a>{{'Default channels permissions' | translate}}</a>
                    <i class="pull-right streamline" ng-class="{'icon-arrow-down-1': panelExpanded, 'icon-arrow-right-1': !panelExpanded}"></i>
                </accordion-heading>
                <div class="form-group">
                    <label for="readRights">{{'Read permissions' | translate}}</label>
                    <div class="radio">
                        <label><input type="radio" name="readRootPermissionsFor" ng-model="readRootPermissionsFor" ng-value="'none'" ng-change="changeReadPermissionsFor('none')">{{'None' | translate}}</label>
                    </div>
                    <div class="radio">
                        <label><input type="radio" name="readRootPermissionsFor" ng-model="readRootPermissionsFor" ng-value="'everybody'" ng-change="changeReadPermissionsFor('everybody')">{{'Everybody' | translate}}</label>
                    </div>
                    <div class="radio">
                        <label><input type="radio" name="readRootPermissionsFor" ng-model="readRootPermissionsFor" ng-value="'selected'" ng-change="changeReadPermissionsFor('selected')">{{'Selected' | translate}}</label>
                    </div>
                    <ul class="list-group" ng-show="readRootPermissionsFor == 'selected'">
                        <li class="list-group-item" ng-repeat="rp in rootChannel.readRightsPrincipals">
                            {{(rp.category? '('+rp.category+') ':'')}}{{::rp.displayName }}<span ng-if="rp.loginName">&nbsp;&lt;{{rp.loginName}}&gt;</span>
                            <button type="button" class="close" ng-click="removeReadPrincipal(rp.principalID, rootChannel)"><span aria-hidden="true">&times;</span></button>
                        </li>
                    </ul>
                    <input type="text" ng-model="readRights" ng-disabled="readRootPermissionsFor != 'selected'" placeholder="{{'Add group or person' | translate}}"
                           typeahead-on-select="addReadPrincipal($model, rootChannel);"
                           typeahead="user as (user.category? '('+user.category+') ':'')+user.displayName + (user.loginName ? '  - ' + user.loginName : '') for user in searchForPrincipal($viewValue,false) | limitTo:10"
                           typeahead-loading="loadingLocations" class="form-control"
                           typeahead-min-length="2">
                    <i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
                </div>
                <div class="form-group">
                    <label for="editRights">{{'Write permissions' | translate}}</label>
                    <div class="radio">
                        <label><input type="radio" name="writeRootPermissionsFor" ng-model="writeRootPermissionsFor" ng-value="'none'" ng-change="changeWritePermissionsFor('none')">{{'None' | translate}}</label>
                    </div>
                    <div class="radio">
                        <label><input type="radio" name="writeRootPermissionsFor" ng-model="writeRootPermissionsFor" ng-value="'everybody'" ng-change="changeWritePermissionsFor('everybody')">{{'Everybody' | translate}}</label>
                    </div>
                    <div class="radio">
                        <label><input type="radio" name="writeRootPermissionsFor" ng-model="writeRootPermissionsFor" ng-value="'selected'" ng-change="changeWritePermissionsFor('selected')">{{'Selected' | translate}}</label>
                    </div>
                    <ul class="list-group" ng-show="writeRootPermissionsFor == 'selected'">
                        <li class="list-group-item" ng-repeat="wr in rootChannel.writeRightsPrincipals">
                            {{(wr.category? '('+wr.category+') ':'')}}{{ ::wr.displayName }}<span ng-if="wr.loginName">&nbsp;&lt;{{wr.loginName}}&gt;</span>
                            <button type="button" class="close" ng-click="removeWritePrincipal(wr.principalID, rootChannel)"><span aria-hidden="true">&times;</span></button>
                        </li>
                    </ul>
                    <input type="text" ng-model="writeRights" ng-disabled="writeRootPermissionsFor != 'selected'" placeholder="{{'Add group or person' | translate}}"
                           typeahead-on-select="addWritePrincipal($model, rootChannel);"
                           typeahead="user as (user.category? '('+user.category+') ':'')+user.displayName + (user.loginName ? ' - ' + user.loginName : '') for user in searchForPrincipal($viewValue,false) | limitTo:10"
                           typeahead-loading="loadingLocations" class="form-control"
                           typeahead-min-length="2">
                    <i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>

                    <div class="checkbox">
                        <label ng-show="writeRootPermissionsFor != 'none'">
                            <input type="checkbox" ng-model="rootChannel.canOnlyEditItsOwn" ng-change="setCanEditOnlyItsOwn(rootChannel)">{{'Can only edit its own' | translate}}
                        </label>
                    </div>
                </div>
            </accordion-group>
        </accordion>
    </div>

    <!----------------------------------- List of channels --------------------------------------->
    <div class="panel panel-default lt-module-page__content-panel">
        <div class="panel-heading">{{'Channels' | translate}}</div>
        <ul class="list-group lt-tree" ng-repeat="channel in data" wizdom-include="'channelTree'">
        </ul>
    </div>

    <!----------------------------------- Recycle bin --------------------------------------->
    <div class="lt-module-page__content-accordion">
        <accordion>
            <accordion-group is-open="panelExpanded">
                <accordion-heading class="panel-title">
                    <a>{{'Recycle bin' | translate}}</a>
                    <i class="pull-right streamline" ng-class="{'icon-arrow-down-1': panelExpanded, 'icon-arrow-right-1': !panelExpanded}"></i>
                </accordion-heading>
                <div>
                    <ul class="list-group lt-tree" ng-repeat="channel in softDeletedChannels">
                        <li class="list-group-item lt-tree__item" style="border-bottom:1px solid">
                            <div class="lt-tree-item__title">
                                <span>{{::channel.name}}</span>
                                <span style="margin-left:8px" class="lt-status lt-status--warning"> {{getRemainingDaysText(channel.daysUntilPermanentDelete)}} </span>
                            </div>
                            <div class="lt-tree-item__actions">
                                <button class="btn btn-danger" title="{{'Permanent delete' | translate}}" style="color: red;background-color:white" ng-click="deleteChannel(channel, false)">
                                    <span style="display:flex" class="streamline icon-bin-1"></span>
                                </button>
                                <button class="btn btn-primary" ng-click="recoverChannel(channel.id)">
                                    {{'Recover' | translate}}
                                </button>
                            </div>
                        </li>
                    </ul>
                </div>
            </accordion-group>
        </accordion>
    </div>
</div>


<script type="text/ng-template" id="channelTree">
        <li class="list-group-item lt-tree__item">
            <div class="lt-tree-item__title">
                <span ng-if="false" ng-class="{'glyphicon glyphicon-folder-open':channel.canContainItems,'glyphicon glyphicon-folder-close':!channel.canContainItems}" aria-hidden="true"></span>
                <span>{{::channel.name}}</span>
                <i ng-show="::channel.isExternal" class="streamline icon-earth-3" title="{{'External channel. Items are created from a feed' | translate}}"></i>
                <i ng-show="::(channel.permissionTargetType == 1)" class="streamline icon-baggage" title="{{'Business App channel. The channel are managed through workspaces or one of the other business apps.' | translate}}"></i>
            </div>
            <div class="lt-tree-item__actions">
                <span class="streamline icon-hierarchy-files" aria-hidden="true" title="{{'Create subchannel' | translate}}" ng-click="createEditChannel(null, channel)"></span>
                <span class="streamline icon-login-keys" aria-hidden="true" ng-class="{'broken_perm': channel.breakRightsInheritance}" ng-attr-title="{{channel.breakRightsInheritance ? ('Permissions' | translate) + ' - ' + ('This channel has seperate permits' | translate) : ('Permissions' | translate)}}" ng-click="openDialogEditRights(channel.id)"></span>
                <span class="streamline icon-pencil-1" aria-hidden="true" title="{{'Edit' | translate}}" ng-click="createEditChannel(channel)"></span>
                <span class="streamline icon-bin-1" aria-hidden="true" title="{{'Delete' | translate}}" ng-style="{visibility: (channel.childs == 0) ? 'visible':'hidden'}" ng-click="deleteChannel(channel, true)"></span>
            </div>
        </li>
        <ul ng-if="channel.childs" class="list-group lt-tree lt-tree__child" ng-repeat="channel in channel.childs" wizdom-include="::'channelTree'"></ul>
</script>
