<?php
session_start();
include "../../inc/config.php";
    $token = get_token();
    $url_rest = $db->get_service_url('rest');

  $data_req_kelas = [
    'act' => 'GetListRencanaPembelajaran',
      'token' => $token,
      'filter' => "id_rencana_ajar='".$_POST['id_rencana_ajar']."'"
  ];

  $data_edit = service_request($data_req_kelas);
  $data_edit = $data_edit->data[0];
?>
<div class="alert alert-danger error_data_sks" style="display:none">
  <button type="button" class="close" data-dismiss="alert">&times;</button>
  <span class="isi_warning_sks"></span>
</div>


<form id="update" method="post" class="form-horizontal" action="<?=base_admin();?>modul/manage_matakuliah/manage_matakuliah_action.php?act=up_pembelajaran">
                      <div class="form-group">
                        <label for="pertemuan" class="control-label col-lg-2">Pertemuan</label>
                        <div class="col-lg-2">
                          <input type="number" name="pertemuan" value="<?=$data_edit->pertemuan;?>" class="form-control" > 
                        </div>
                      </div><!-- /.form-group -->
                       <div class="form-group">
                        <label for="pertemuan" class="control-label col-lg-2">Materi</label>
                        <div class="col-lg-10">
                          <textarea class="form-control" rows="6" name="materi_indonesia"><?=$data_edit->materi_indonesia;?></textarea>
                        </div>
                      </div><!-- /.form-group -->

                       <div class="form-group">
                        <label for="pertemuan" class="control-label col-lg-2">Materi Inggris</label>
                        <div class="col-lg-10">
                           <textarea class="form-control" rows="6" name="materi_inggris"><?=$data_edit->materi_inggris;?></textarea>
                        </div>
                      </div><!-- /.form-group -->

                      <input type="hidden" name="id" value="<?=$data_edit->id_rencana_ajar;?>">
                      <input type="hidden" name="id_matkul" value="<?=$data_edit->id_matkul;?>">
                      <div class="form-group">
                        <label for="tags" class="control-label col-lg-2">&nbsp;</label>
                        <div class="col-lg-10">
                          <button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Simpan</button>
                          <span class="btn btn-default btn-flat batal-edit"><i class="fa fa-step-backward"></i> Batal</span>
                        </div>
                      </div><!-- /.form-group -->
                    </form>
<script type="text/javascript">
	    $(document).ready(function() {
    
$(".batal-edit").on("click",function(){
  $("#modal_edit").modal( 'hide' ).data( 'bs.modal', null );
});

    
    $("#update").validate({
        errorClass: "help-block",
        errorElement: "span",
        highlight: function(element, errorClass, validClass) {
            $(element).parents(".form-group").removeClass(
                "has-success").addClass("has-error");
        },
        unhighlight: function(element, errorClass, validClass) {
            $(element).parents(".form-group").removeClass(
                "has-error").addClass("has-success");
        },
        errorPlacement: function(error, element) {
            if (element.hasClass("chzn-select")) {
                var id = element.attr("id");
                error.insertAfter("#" + id + "_chosen");
            } else if (element.attr("accept") == "image/*") {
                element.parent().parent().parent().append(error);
            } else if (element.hasClass("tgl_picker_input")) {
               element.parent().parent().append(error);
            } else if (element.hasClass("file-upload-data")) {
               element.parent().parent().parent().append(error);
            } else if (element.attr("type") == "checkbox") {
                element.parent().parent().append(error);
            } else if (element.attr("type") == "radio") {
                element.parent().parent().append(error);
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            $("#loadnya").show();
            $(form).ajaxSubmit({
                url : $(this).attr("action"),
                dataType: "json",
                type : "post",
                error: function(data ) { 
                  $("#loadnya").hide();
                  console.log(data); 
                  $(".isi_warning_sks").html(data.responseText);
                  $(".error_data_sks").focus()
                  $(".error_data_sks").fadeIn();
                },
                success: function(data) {
                  $("#loadnya").hide();
                  if (data.status=='good') {
                  	$(".isi_warning_sks").html('');
                  	$(".error_data_sks").hide();
	                $(".notif_top_up").fadeIn(1000);
	                $('#modal_edit').modal('hide');
	                $(".notif_top_up").fadeOut(1000, function() {
                    dataTable_pembelajaran.draw(false);
	                });
                  } else {
	                  $(".isi_warning_sks").html(data.error_desc);
	                  $(".error_data_sks").focus()
	                  $(".error_data_sks").fadeIn();
                  }
                  console.log(data.status);

                }

            });
        }
    });
});
</script>