<div class="modal-header">
    <button type="button" class="close closebtn" data-ng-click="cancel()" aria-hidden="true">&times;</button>
    <h1 class="modal-title">
        {{::channel.id ? 'Edit Channel' : 'Create Channel' | translate}}
        {{::channel.id ? (': ' + channel.name) : ''}}
    </h1>
</div>
<div class="container-fluid wt-navRowContainer">
    <div class="row wt-navRow">
        <div class="col-sm-3 wt-fullHeightColumn wt-navMenuColumn">
            <nav class="navbar navbar-default" role="navigation">
                <ul class="nav navbar-nav">
                    <li role="presentation" ng-class="{ active: channel.type == null}" ng-hide="channel.id != null && channel.type != null">
                        <a href="" ng-click="channel.id == null && (channel.type = null)">
                            <i class="glyphicon glyphicon-send" style="font-size:25px; vertical-align: bottom; color:#1775bc;"></i>{{'News channel' | translate}}</a>
                    </li>
                    <li role="presentation" ng-class="{ active: channel.type == 0}" ng-if="contentTypeExist('RSS')" ng-hide="isSaaS || channel.id != null && channel.type != 0">
                        <a href="" ng-click="channel.id == null && (channel.type = 0) || (channel.source = channel.rssUrl)">
                            <i class="icon icon-rss"></i>{{'Rss channel' | translate}}</a>
                    </li>
                    <li role="presentation" ng-class="{ active: channel.type == 1}" ng-if="contentTypeExist('Office365Video')" ng-hide="channel.id != null && channel.type != 1">
                        <a href="" ng-click="channel.id == null && (channel.type = 1) && (channel.source = channel.office365VideoChannel)">
                            <span class="o365-video"></span>{{'Office365 video channel' | translate}}</a>
                    </li>
                </ul>
            </nav>
        </div>
        <div class="col-sm-9 wt-fullHeightColumn wt-navContentColumn">
            <div class="modal-body">
                <form name="form" role="form">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="form-group">
                                    <label for="channelName">{{'Name' | translate}}</label>
                                    <input type="text" class="form-control" placeholder="Name" ng-model="channel.name" required>
                                    <span ng-show="errorName && (!channel.name || channel.name.length == 0)" class="label label-danger">{{'This field can not be empty' | translate}}</span>
                                </div>
                                <div class="form-group">
                                    <label for="parentChannel">{{'Parent channel' | translate}}</label>
                                    <select class="form-control" id="parentChannel"
                                            ng-model="channel.parentId"
                                            ng-options="channel.id as (channel.name | wizdom365NoticeboardChannelLevel:channel.level) for channel in parentChannels"></select>
                                </div>
                                <div ng-if="channel.type == null">
                                    <div class="form-group form-group2">
                                        <div class="checkbox">
                                            <label>
                                                <input type="checkbox" ng-model="channel.canContainItems" ng-disabled="channel !=null && channel.itemCount > 0">{{'Can contain items' | translate}}
                                            </label>
                                        </div>
                                        <div ng-if="channel != null && channel.itemCount > 0">
                                            <i>{{'Cannot change while there are items present in channel' | translate}}: ({{ channel.itemCount }})</i>
                                        </div>
                                    </div>
                                    <div class="form-group form-group2" ng-if="channel.canContainItems">
                                        <label for="channelName">{{'Limit to content types' | translate}}</label>
                                        <div class="checkbox" ng-repeat="ct in contentTypes | filter: { isVisible: true }">
                                            <label>
                                                <input type="checkbox" value="ctx.name" ng-model="ct.selected">{{::ct.name}}
                                            </label>
                                        </div>
                                    </div>
                                </div>
                                <div ng-if="channel.type == 0" ng-init="channel.rssUrl = channel.source">
                                    <div class="form-group rss-form" ng-class="rssValidated ? (rssValidationSuccess ? 'rss-correct' : 'rss-error') : ''">
                                        <label for="channelName">{{'RSS url' | translate}}</label>
                                        <input type="url" class="form-control" placeholder="RSS url" ng-model="channel.rssUrl" ng-change="rssUrlChanged()" required>
                                        <button type="button" class="btn btn-default wiz-btn-padding" ng-disabled="rssValidated" ng-click="validateFeed()">{{'Validate' | translate}}</button>
                                        <p ng-if="rssValidated" class="validation-message">{{ rssValidationMessage }}</p>                                        
                                    </div>
                                    

                                </div>
                                <div ng-if="channel.type == 1" ng-init="channel.office365VideoChannel = channel.source">
                                    <div class="form-group">
                                        <label for="channelName">{{'Office365 Video Channel' | translate}}</label>
                                        <select class="form-control" required ng-model="channel.office365VideoChannel"
                                                ng-options="channel.id as channel.name for channel in office365VideoChannels"></select>
                                    </div>
                                </div>
                                <div ng-if="channel.type != null">
                                    <div class="form-group">
                                        <label for="channelName">{{'Update interval (min)' | translate}}</label>
                                        <input type="number" class="form-control" placeholder="Update interval (min)"
                                               ng-model="channel.updateInterval"
                                               required
                                               notlessthen-error-message="This value should be bigger than 5"
                                               validate="{required: true, notlessthen: 'validationService.notLessThen($value, 5)' }">
                                    </div>
                                    <div class="form-group">
                                        <label for="channelName">{{'Days to keep' | translate}}</label>
                                        <input type="number"
                                               min="1"
                                               required
                                               class="form-control"
                                               placeholder="Days to keep"
                                               ng-model="channel.daysToKeep">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="modal-footer">
    <button type="button" class="btn btn-default wiz-btn-padding" ng-click="cancel()">{{'Cancel' | translate}}</button>
    <button type="button" class="btn btn-primary wiz-btn-padding" ng-disabled="form.$invalid || (channel.type == 0 && (!rssValidated || !rssValidationSuccess))" ng-click="createUpdateChannel()">{{'Save' | translate}}</button>
</div>
