<?php $__env->startSection('content_header'); ?>
    <?php echo notifyCss(); ?>
    <?php echo notifyJs(); ?>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <div class="row">
      <div class="col-12">
        <div class="card">
          <div class="card card-primary">
            <div class="card-header">
                <h3 class="card-title">Topic</h3>
            </div>
            <?php echo $__env->make('notify::messages', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
            <!-- /.card-header -->
            <div class="card-body">
              <ul class="nav nav-tabs">
                  <li class="nav-item"><a class="nav-link active" data-toggle="pill" href="#organisation_form"><b>Add Organisation</b></a></li>
                  <li class="nav-item"><a class="nav-link" data-toggle="pill" href="#listorgdata"><b>View Organisation</b></a></li>
              </ul>
              <div class="tab-content">
                <div id="organisation_form" class="tab-pane fade active show">
                  <!-- form start -->
                  <form id="userregform" class="form-horizontal" action="<?php echo e(URL::to('/topic_post')); ?>" method="post" onsubmit="return validation();" autocomplete="off" enctype="multipart/form-data">
                      <?php echo e(csrf_field()); ?>

                      <div class="card-body">
                          <div class="col-6">
                              <div class="form-group row">
                                  <label for="exampleInputEmail1">Organisation</label>
                                  <select name="organisation_id" id="organisation_id" class="form-control" required onchange="load_material_type(this.value)">
                                      <option value="">Select Organisation</option>
                                      <?php $__currentLoopData = $organisations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $organisation): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                          <option value="<?php echo e($organisation->id); ?>"><?php echo e($organisation->organisation_name); ?></option>
                                      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                  </select>
                              </div>
                              <div class="form-group row">
                                  <label for="exampleInputEmail1">Material Type</label>
                                  <select name="material_type_id" id="material_type_id" class="form-control" required onchange="load_material_subtype(this.value)">
                                      <option value=""> Select Material Type</option>
                                  </select>
                              </div>
                              <div class="form-group row">
                                  <label for="exampleInputEmail1">Material Sub Type</label>
                                  <select name="material_subtype_id" id="material_subtype_id" class="form-control" required>
                                      <option value=""> Select Material Sub Type</option>
                                  </select>
                              </div>
                              <div class="form-group row">
                                  <label for="exampleInputEmail1">Topic Name</label>
                                  <input type="text" class="form-control" id="topic_name" name="topic_name" placeholder="Enter Topic Name" required>
                              </div>
                              <div class="form-group row">
                                  <label for="exampleInputEmail1">Remarks</label>
                                  <input type="text" class="form-control" id="remarks" name="remarks" placeholder="Enter Remarks">
                              </div>
                          </div>
                      </div>
                      <!-- /.card-body -->

                      <div class="card-footer">
                        <button type="submit" class="btn btn-primary">Submit</button>
                      </div>
                  </form>
                </div>
                <div id="listorgdata"  class="tab-pane fade" style="padding: 10px;">
                  <table class="table table-hover table-bordered table-striped datatable" id="dept_details" width="100%">
                      <thead>
                          <tr>
                            <th>Slno</th>
                            <th>Organisation</th>
                            <th>Material Typee</th>
                            <th>Material Sub Type Name</th>
                            <th>Topic Name</th>
                            <th>Remarks</th>
                            <th>Actions</th>
                          </tr>
                      </thead>
                  </table>
              </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <script type="text/javascript">
        function load_material_type(organisation_id)
        {
            $.ajax({
               type:'GET',
               url: "<?php echo url('get_materialtype/"+organisation_id+"'); ?>",
               success:function(data)
               {
                  $('#material_type_id').empty();
                  $('#material_type_id').append("<option value=''>Select Material Type</option>");
                  $.each(data, function(key, element) {
                      $('#material_type_id').append("<option value='" + key +"'>" + element + "</option>");
                  }); 
               }
            });
        }
        function load_material_subtype(material_type_id)
        {
            $.ajax({
               type:'GET',
               url: "<?php echo url('get_materialsubtype/"+material_type_id+"'); ?>",
               success:function(data)
               {
                  $('#material_subtype_id').empty();
                  $('#material_subtype_id').append("<option value=''>Select Material Sub Type</option>");
                  $.each(data, function(key, element) {
                      $('#material_subtype_id').append("<option value='" + key +"'>" + element + "</option>");
                  }); 
               }
            });
        }
        $(document).ready(function () 
        {
            $('#dept_details').DataTable({
                "buttons" : ['excelHtml5', 'excel', 'pdf', 'print', 'reset', 'reload'],
                "processing": true,
                "serverSide": true,
                "ajax":{
                         "url": "<?php echo e(url('get_topic_details')); ?>",
                         "dataType": "json",
                         "type": "POST",
                         "data":{ _token: "<?php echo e(csrf_token()); ?>"}
                       },
                "columns": [
                    { "data": "DT_RowIndex" },
                    { "data": "organisation_name" },
                    { "data": "material_type_name" },
                    { "data": "material_subtype_name"},
                    { "data": "topic_name" },
                    { "data": "remarks" },
                    { "data": "action" }
                ], 
                "order": [[1, 'asc']]
            });      
        });

        
        function confirmDeleteTopics(topic_id) 
        {
            var x = confirm("Are you sure you want to delete?");
            if (x)
            {
                var csrf = "<?php echo e(csrf_token()); ?>";
                $.ajax({
                    type: "POST",
                    url: "<?php echo e(url('delete_topic')); ?>",
                    dataType : 'json',
                    data: {_token: csrf, topic_id: topic_id},
                    success: function( msg ) {
                      if(msg)
                        alert("Topic has been deleted");
                      //else
                        //alert("Active Department are assigned to Organisation.");
                      location.reload();
                    }
                });  
            }
            else
            {
              return false;
            }
        }
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('adminlte::page', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH E:\xampp7.3\htdocs\kmportal\resources\views/Admin/Settings/topic.blade.php ENDPATH**/ ?>