<% layout('../layouts/main') -%>

<!-- DataTables -->
<% stylesheet('/css/dataTables.bootstrap.min.css') %>

<!-- DataTables -->
<% script('/js/jquery.dataTables.min.js') %>
<% script('/js/dataTables.bootstrap.min.js') %>

<% block('custom_scripts', `
<script>
  $(document).ready(function () {
      $('#example1').DataTable({
          "aoColumnDefs": [
              {'bSortable': false, 'aTargets': [5]},
//              //{"aTargets": [3], "sClass": "text-justify"},
//              {"sClass": "center", "aTargets": [1, 2]},
              {"width": "9%", "targets": [0]},
              {"width": "9%", "targets": [5]},
//              {"width": "8%", "targets": [8]},
//                  //{"width": "9%", "targets": [7]},
          ],
          "paging": true,
          "lengthChange": true,
          "searching": true,
          "ordering": true,
          "info": true,
          "autoWidth": false,
          "stateSave": true
      });
  });

  $(document).ready(function () {
      $(document).on('click', ".delete_confirmation", function (e) {
          e.preventDefault();
          if (confirm("Do you want delete this item")) {
              //alert($(this).attr('href'));
              window.location.href = $(this).attr('href');
          }
      });
  });
</script>
`) %>


<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        Questions and Answers
        <!--<small>advanced tables</small>-->
    </h1>
    <ol class="breadcrumb">
        <li><a href="/dashboard"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Questions and Answers</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">
    <% if (Object.prototype.hasOwnProperty.call(flash, 'success')) { %>
    <div class="alert alert-success alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
                aria-hidden="true">&times;</span></button>
        <%= flash.success %>
    </div>
    <% } %>
    <% if (Object.prototype.hasOwnProperty.call(flash, 'error')) { %>
    <div class="alert alert-danger alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
                aria-hidden="true">&times;</span></button>
        <%= flash.error %>
    </div>
    <% } %>
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <h3 class="box-title">List of Questions and Answers</h3>
                    <div class="pull-right">
                        <a href="/questions/add" class="btn btn-primary">Add New Questions</a>
                    </div>

                </div>
                <!-- /.box-header -->
                <div class="box-body">
                    <table id="example1" class="table table-bordered table-hover">
                        <thead>
                            <tr>
                                <th>Ranking position</th>
                                <th>Question</th>
                                <th>Submit by Email</th>
                                <th>Submit Date</th>
                                <th>Category</th>
                                <th>Unit</th>
                                <th>Action</th>


                            </tr>
                        </thead>






                        <% 
                            if(docs){
                            for(var i=0; len=docs.length, i < len; i++) { %>
                        <tbody>
                            <td></td>
                            <td>
                                <%= docs[i].question %>
                            </td>
                            <td>
                                <%= docs[i].questioner_email||"" %>
                            </td>
                            <td>
                                <%= docs[i].createdAt %>
                            </td>
                            <td>
                                <%= docs[i].category %>
                            </td>
                            <td>
                                <%= docs[i].unit||"" %>
                            </td>

                            <td class="text-center">
                                <a href="<%= '/questions/edit/'+docs[i]._id %>" class="btn btn-sm btn-primary"
                                    title="Edit"><span class="glyphicon glyphicon-edit"></span></a>

                                <a href="<%= '/questions/delete/'+docs[i]._id %>"
                                    class="btn btn-sm btn-danger delete_confirmation" title="Delete"><span
                                        class="glyphicon glyphicon-trash"></span></a>

                                <% if(docs[i].isPublished=="no") {
                                            %>


                                <a href="<%='/questions/status/'+docs[i]._id+'/yes/'%>"
                                    class="btn btn-sm btn-success inactive_confirmation" title="Published">Published</a>

                                <% } else { %>

                                <a href="<%='/questions/status/'+docs[i]._id+'/no/'%>"
                                    class="btn btn-sm btn-danger inactive_confirmation" title="Un Published"> Un
                                    Published</a>

                                <% } %>
                            </td>
                        </tbody>
                        <% 
                            }
                            }
                            %>




                        <tfoot>
                            <tr>
                                <th>Ranking position</th>
                                <th>Question</th>
                                <th>Submit by Email</th>
                                <th>Submit Date</th>
                                <th>Category</th>
                                <th>Unit</th>
                                <th>Action</th>
                            </tr>
                        </tfoot>
                    </table>
                </div>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </div>
        <!-- /.col -->
    </div>
    <!-- /.row -->
</section>
<!-- /.content -->