<div class="row page-titles">
    <div class="col-md-6 col-8 align-self-center">
        <h3 class="text-themecolor m-b-0 m-t-0">{{phrase.mobileNotifications}}</h3>
    </div>
    <div class="col-md-6 col-4 align-self-center">

    </div>
</div>


<div class="row" ng-show="views.list">
    <div class="col-12">
        <div class="card">
            <div class="card-block">
                <h4 class="card-title">{{phrase.mobileNotifications}}</h4>
                <div class="form">

                    <div>
                        <!-- Nav tabs -->
                        <ul class="nav nav-tabs tabsItem" role="tablist">
                            <li class="nav-item" role="presentation"><a showtab="" class="nav-link active" href="#sendNotif" aria-controls="sendNotif" role="tab" data-toggle="tab">{{phrase.sendNewNotification}}</a></li>
                            <li class="nav-item" role="presentation"><a showtab="" class="nav-link" href="#history" aria-controls="history" role="tab" data-toggle="tab">{{phrase.History}}</a></li>
                        </ul>

                        <!-- Tab panes -->
                        <div class="tab-content tabcontent-border">

                            <div role="tabpanel" class="tab-pane active p-20" id="sendNotif">

                                <form class="form-horizontal" ng-submit="saveAdd()" name="mailsms" ng-show="sendNewScope == 'form'" novalidate>
                                    <div class="form-group row" ng-class="{'has-error': mailsms.userType.$invalid}">
                                        <label class="col-sm-2 text-right control-label col-form-label">{{phrase.typeUsers}} *</label>
                                        <div class="col-sm-10">
                                            <div class="radio-list">
                                                <label>
                                                    <input type="radio" name="userType" value="all" ng-model="form.userType" required>
                                                    {{phrase.all}}
                                                </label>
                                            </div>
                                            <div class="radio-list">
                                                <label>
                                                    <input type="radio" name="userType" value="teachers" ng-model="form.userType" required>
                                                    {{phrase.teachers}}
                                                </label>
                                            </div>
                                            <div class="radio-list">
                                                <label>
                                                    <input type="radio" name="userType" value="students" ng-model="form.userType" required >
                                                    {{phrase.students}}
                                                </label>
                                            </div>
                                            <div class="radio-list">
                                                <label>
                                                    <input type="radio" name="userType" value="parents" ng-model="form.userType" required >
                                                    {{phrase.parents}}
                                                </label>
                                            </div>
                                            <div class="radio-list">
                                                <label>
                                                    <input type="radio" name="userType" value="users" ng-model="form.userType" required >
                                                    {{phrase.specificUsers}}
                                                </label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group row" ng-show="form.userType == 'teachers'" ng-class="{'has-error': mailsms.subjectId.$invalid}">
                                        <label class="col-sm-2 text-right control-label col-form-label">Subject *</label>
                                        <div class="col-sm-10">
                                            <select class="form-control" ng-model="form.subjectId" name="subjectId" multiple ng-required="form.userType == 'teachers'">
                                                <option ng-repeat="subject in subject_list" value="{{subject.id}}">{{subject.subjectTitle}}</option>
                                            </select>
                                        </div>
                                    </div>


                                    <div class="form-group row" ng-show="form.userType == 'students' || form.userType == 'parents'" ng-class="{'has-error': mailsms.classId.$invalid}">
                                        <label class="col-sm-2 text-right control-label col-form-label">{{phrase.class}} *</label>
                                        <div class="col-sm-10">
                                            <select class="form-control" ng-model="form.classId" name="classId" multiple ng-required="form.userType == 'students' || form.userType == 'parents'" ng-change="subjectList()">
                                                <option ng-repeat="class in classes" value="{{class.id}}">{{class.className}}</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group row" ng-show="(form.userType == 'students' || form.userType == 'parents') && $root.dashboardData.enableSections == '1'" ng-class="{'has-error': mailsms.sectionId.$invalid}">
                                        <label class="col-sm-2 text-right control-label col-form-label">{{phrase.section}} *</label>
                                        <div class="col-sm-10">
                                            <select class="form-control" ng-model="form.sectionId" name="sectionId" multiple ng-required="(form.userType == 'students' || form.userType == 'parents') && $root.dashboardData.enableSections == '1'">
                                                <option ng-repeat="section in sections" value="{{section.id}}">{{section.sectionName}} - {{section.sectionTitle}}</option>
                                            </select>
                                        </div>
                                    </div>
                                    
                                    <div class="form-group row" ng-show="form.userType == 'users'">
                                        <label class="col-sm-2 text-right control-label col-form-label">{{phrase.selUsers}} *</label>
                                        <div class="col-sm-10">

                                            <a type="button" ng-click="linkUsers('all')" class="btn btn-danger btn-flat">{{phrase.selUsers}}</a>
                                            <div class="row" ng-repeat="userOne in form.selectedUsers track by $index">
                                                <div class="col-xs-8"><input type="text" class="form-control" disabled="disabled" ng-model="userOne.student"></div>
                                                <a type="button" ng-click="removeUser($index)" class="btn btn-danger btn-flat"><i class="fa fa-trash-o"></i></a></li>
                                            </div>

                                        </div>
                                    </div>
                                    <div class="form-group row" ng-class="{'has-error': mailsms.notifData.$invalid}">
                                        <label class="col-sm-2 text-right control-label col-form-label">{{phrase.messageContent}} *</label>
                                        <div class="col-sm-10">
                                            <textarea name="notifData" class="form-control" ng-model="form.notifData" required placeholder="{{phrase.messageContent}}"></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group m-b-0">
                                        <div class="offset-sm-2 col-sm-10">
                                            <button type="submit" class="btn btn-info waves-effect waves-light" ng-disabled="mailsms.$invalid">{{phrase.sendNewNotification}}</button>
                                        </div>
                                    </div>
                                </form>

                                <span ng-show="sendNewScope == 'success'">
                                    {{phrase.messQueued}}
                                </span>

                            </div>
                            <div role="tabpanel" class="tab-pane p-20" id="history">

                                <br/>
                                <div class="pull-right card-block-input-group card-block-input-item">
                                    <div class="input-group input-group-sm">
                                        <input type="text"  name="table_search" ng-model="searchText" placeholder="{{phrase.Search}}" class="form-control input-sm">
                                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                                    </div>
                                </div>
                                <div class="table-responsive">
                                    <table class="table table-bordered table-hover">
                                        <tbody>
                                            <tr>
                                                <th>{{phrase.ID}}</th>
                                                <th>{{phrase.to}}</th>
                                                <th>{{phrase.Date}}</th>
                                                <th>{{phrase.details}}</th>
                                                <th>{{phrase.Sender}}</th>
                                                <th>{{phrase.Operations}}</th>
                                            </tr>
                                            <tr dir-paginate="message in messages | filter:searchText | itemsPerPage:20" total-items="totalItems">
                                                <td>{{message.id}}</td>
                                                <td>{{message.notifTo}}</td>
                                                <td>{{message.notifDate}}</td>
                                                <td>{{message.notifData}}</td>
                                                <td>{{message.notifSender}}</td>
                                                <td>
                                                    <button ng-click="remove(message,$index)" type="button" class="btn btn-danger btn-circle" title="{{phrase.Remove}}" tooltip><i class="fa fa-trash-o"></i></button>
                                                </td>
                                            </tr>
                                            <tr ng-show="!messages.length"><td class="noTableData" colspan="6">{{phrase.noMessages}}</td></tr>
                                        </tbody>
                                    </table>
                                    <dir-pagination-controls class="pull-right" on-page-change="loadNotifications(newPageNumber)" template-url="assets/templates/dirPagination.html" ></dir-pagination-controls>
                                </div>

                            </div>

                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<modal visible="showModalLink">
    <div class="row">
        <div class="col-md-9">
            <input type="text" class="form-control" id="searchLink" placeholder="{{phrase.typeNameUserMail}}">
        </div>
        <div class="col-md-2">
            <button type="button" ng-click="linkStudentButton()" class="btn btn-danger btn-flat">{{phrase.Search}}</button>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12" style="padding-top:10px;">
            <div class="box-body table-responsive">
                <table class="table table-bordered">
                    <tbody>
                        <tr ng-repeat="userOne in searchResults">
                            <td>{{userOne.name}} ({{userOne.role}})</td>
                            <td>{{userOne.email}}</td>
                            <td class="no-print">
                                <button type="button" ng-click="linkStudentFinish(userOne)" class="btn btn-success btn-flat">{{phrase.select}}</button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</modal>
