<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.sections}}</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">
                <button ng-show="$root.can('sections.addSection')" ng-click="changeView('add')" class="btn pull-right btn-success card-block-input-item">{{phrase.addSection}}</button>
                <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="searchInput" ng-change="searchDB()" placeholder="{{phrase.Search}}" class="form-control">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
                <h4 class="card-title">{{phrase.listSections}}</h4>
                <div class="table-responsive">
                    
                    <table class="table table-bordered table-hover">
                        <tbody>
                            <tr>
                                <th>{{phrase.section}} </th>
                                <th>{{phrase.sectionTitle}}</th>
                                <th>{{phrase.class}}</th>
                                <th>{{phrase.teacher}}</th>
                                <th ng-show="$root.can('sections.editSection') || $root.can('sections.delSection')">{{phrase.Operations}}</th>
                            </tr>
                            <tr dir-paginate="section in sections | itemsPerPage:20" total-items="totalItems">
                                <td>{{section.sectionName}}</td>
                                <td>{{section.sectionTitle}}</td>
                                <td style="font-weight:500;">{{classes[section.classId]}}</td>
                                <td>
                                    <span ng-repeat="(key_,value_) in section.teacherId">
                                        {{teachers[value_]}} <br/>
                                    </span>
                                </td>
                                <td>
                                    <button ng-show="$root.can('sections.editSection')" ng-click="edit(section.id)" type="button" class="btn btn-info btn-circle" title="{{phrase.Edit}}" tooltip><i class="fa fa-pencil"></i></button>
                                    <button ng-show="$root.can('sections.delSection')" ng-click="remove(section,$index)" type="button" class="btn btn-danger btn-circle" title="{{phrase.Remove}}" tooltip><i class="fa fa-trash-o"></i></button>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <dir-pagination-controls class="pull-right" on-page-change="getResultsPage(newPageNumber)" template-url="assets/templates/dirPagination.html" ></dir-pagination-controls>

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

<div class="row" ng-show="views.add">
    <div class="col-12">
        <div class="card">
            <div class="card-block">
                <button ng-click="changeView('list')" class="btn btn-danger btn-flat pull-right card-block-input-item">{{phrase.cancelAdd}}</button>
                <h4 class="card-title">{{phrase.addSection}}</h4>
                <div class="table-responsive">

                    <form class="form-horizontal" name="addSection" role="form" ng-submit="saveAdd()" novalidate>
                        <div class="form-group row" ng-class="{'has-error': addSection.sectionName.$invalid}">
                            <label class="col-sm-2 text-right control-label col-form-label">{{phrase.section}} * </label>
                            <div class="col-sm-10">
                                <input type="text" name="sectionName" ng-model="form.sectionName" class="form-control" required placeholder="{{phrase.section}}">
                            </div>
                        </div>
                        <div class="form-group row" ng-class="{'has-error': addSection.sectionTitle.$invalid}">
                            <label class="col-sm-2 text-right control-label col-form-label">{{phrase.sectionTitle}} * </label>
                            <div class="col-sm-10">
                                <input type="text" name="sectionTitle" ng-model="form.sectionTitle" class="form-control" required placeholder="{{phrase.sectionTitle}}">
                            </div>
                        </div>
                        <div class="form-group row" ng-class="{'has-error': addSection.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" required>
                                    <option ng-repeat="(key,value) in classes" value="{{key}}">{{value}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row" ng-class="{'has-error': addSection.teacherId.$invalid}">
                            <label class="col-sm-2 text-right control-label col-form-label">{{phrase.teacher}} *</label>
                            <div class="col-sm-10">
                                <select class="form-control" ng-model="form.teacherId" name="teacherId" multiple required>
                                    <option ng-repeat="(key,value) in teachers" value="{{key}}">{{value}}</option>
                                </select>
                            </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="addSection.$invalid">{{phrase.addSection}}</button>
                            </div>
                        </div>
                    </form>

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

<div class="row" ng-show="views.edit">
    <div class="col-12">
        <div class="card">
            <div class="card-block">
                <button ng-click="changeView('list')" class="btn btn-danger btn-flat pull-right card-block-input-item">{{phrase.cancelEdit}}</button>
                <h4 class="card-title">{{phrase.editSection}}</h4>
                <div class="table-responsive">

                    <form class="form-horizontal" name="editSection" role="form" ng-submit="saveEdit()" novalidate>
                        <div class="form-group row" ng-class="{'has-error': editSection.sectionName.$invalid}">
                            <label class="col-sm-2 text-right control-label col-form-label">{{phrase.section}} * </label>
                            <div class="col-sm-10">
                                <input type="text" name="sectionName" ng-model="form.sectionName" class="form-control" required placeholder="{{phrase.section}}">
                            </div>
                        </div>
                        <div class="form-group row" ng-class="{'has-error': editSection.sectionTitle.$invalid}">
                            <label class="col-sm-2 text-right control-label col-form-label">{{phrase.sectionTitle}} * </label>
                            <div class="col-sm-10">
                                <input type="text" name="sectionTitle" ng-model="form.sectionTitle" class="form-control" required placeholder="{{phrase.sectionTitle}}">
                            </div>
                        </div>
                        <div class="form-group row" ng-class="{'has-error': editSection.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" required>
                                    <option ng-repeat="(key,value) in classes" value="{{key}}">{{value}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group row" ng-class="{'has-error': editSection.teacherId.$invalid}">
                            <label class="col-sm-2 text-right control-label col-form-label">{{phrase.teacher}} *</label>
                            <div class="col-sm-10">
                                <select class="form-control" ng-model="form.teacherId" name="teacherId" multiple required>
                                    <option ng-repeat="(key,value) in teachers" value="{{key}}">{{value}}</option>
                                </select>
                            </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="editSection.$invalid">{{phrase.editSection}}</button>
                            </div>
                        </div>
                    </form>

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