
<?= $this->extend('Page_layout') ?>
<?= $this->section('content') ?>
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Schedule Draft & Post Report</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
            
              <li class="breadcrumb-item active">Schedule Draft & Post Report</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
    <input type="hidden" id="hdraftid" value="<?php if (isset($id)) echo $id; ?>">
    <input type="hidden" id="hdn_talentid">
      <!-- Default box -->
      <div class=" card card-primary ">
        <div class="bg-olive card-header">
          <h3 class="card-title">Schedule Draft & Post Report</h3>

          <div class="card-tools">
            <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
              <i class="fas fa-minus"></i>
            </button>
            <button type="button" class="btn btn-tool" data-card-widget="remove" title="Remove">
              <i class="fas fa-times"></i>
            </button>
          </div>
        </div>
        <div class="card-body">
          <p> Schedule Draft & Post Report filter</p>
         
                <div class="card-body">
                  <div class="form-group row">
                    <label for="names" class="col-sm-2 col-form-label">Talent name</label>
                    <div class="col-sm-4">
                      <input type="text" class="form-control" id="nama" placeholder="Input Name">
                    </div>
                  </div>
                  <!--
                  <div class="form-group row">
                    <label for="names" class="col-sm-2 col-form-label">Year</label>
                    <div class="col-sm-4">
                      <input type="number" class="form-control" id="tahun" placeholder="Input Year">
                    </div>
                  </div>
                  <div class="form-group row">
                    <label for="names" class="col-sm-2 col-form-label">Month</label>
                    <div class="col-sm-4">
                      <input type="text" class="form-control" id="bulan" placeholder="Input Month">
                    </div>
                  </div>
                  -->

                  
                   <button type="button" class="btn btn-info search-data">Search</button>
                   <button type="button" class="btn btn-info reset-data">Reset</button>
           
                </div>

             <div class="col-12" style="overflow-x:scroll">
                <div id="calendar"></div>
                 </div>
        </div>
        <!-- /.card-body -->
        <div class="card-footer">
            </div>
        <!-- /.card-footer-->
      </div>
      <!-- /.card -->

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  </div>
  <?php include('View-draft-post.php');?>


   <?= $this->endSection() ?> 

  <?=$this->section("scripts")?>
<script src="<?=base_url('public/plugins/jquery-ui/jquery-ui.js')?>"></script>  
<script src="<?=base_url('public/plugins/datatables/jquery.dataTables.min.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-bs4/js/dataTables.bootstrap4.min.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-responsive/js/dataTables.responsive.min.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-responsive/js/responsive.bootstrap4.min.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-buttons/js/dataTables.buttons.min.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-buttons/js/buttons.bootstrap4.min.js')?>"></script>
<script src="<?=base_url('public/plugins/jszip/jszip.min.js')?>"></script>
<script src="<?=base_url('public/plugins/pdfmake/pdfmake.min.js')?>"></script>
<script src="<?=base_url('public/plugins/pdfmake/vfs_fonts.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-buttons/js/buttons.html5.min.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-buttons/js/buttons.print.min.js')?>"></script>
<script src="<?=base_url('public/plugins/datatables-buttons/js/buttons.colVis.min.js')?>"></script>
<script src="<?=base_url('public/plugins/moment/moment.min.js')?>"></script>
<script src="<?=base_url('public/plugins/fullcalendar/fullcalendar.min.js')?>"></script>

<script>
$(document).ready(function () {

  if($("#hdraftid").val() != "")
    {
        editdata();
    }

    function loadtalent(param){
  
    
  if(param == "edit")
 
  {
    var ddl_username = $("#eTALENT_ID");  
   
  }
    
 $.ajax({
        type: "GET",
        url: "<?= site_url('tran/get/talent')?>",
      
    
        success: function (response) {
         ddl_username.empty().append('<option selected="selected" value="">Please select</option>');
      
         $.each(response.data, function (key, value) { 
           ddl_username.append($("<option></option>").val(value['TALENT_ID']).html(value['XNAME']));
           
         });

         if($("#hdn_talentid").val() != "")
             {
              $("#eTALENT_ID").val($("#hdn_talentid").val());
             }
         
        }
      });

   
}


    function editdata (){   
      
      $id = $("#hdraftid").val();
      loadtalent("edit");
      getcalenderevent();
    
      $.ajax({
        type: "POST",
        url: "<?= site_url('getevent/edit')?>",
        data: {'id' : $id},
      
        success: function (response) {
        
         $.each(response, function (key, dataval) { 
         
            $('#form-edit').find('input').val('');
            $("#eTALENT_ID").val(dataval['TALENT_ID']).change();
            $("#hdn_talentid").val(dataval['TALENT_ID']);
            $("#eDRAFT_DTM").val(dataval['DRAFT_DTM']);
            $("#eMEDIA_TYPE").val(dataval['MEDIA_TYPE']);
            $("#eDETAIL_DRAFT").val(dataval['DETAIL_DRAFT']);
          
            $("#edraftid").val($id);
            $("#form-edit").modal("show");
         });
        }
      });
    }


  $(document).on('click','.search-data', function () {
    $('.search-data').hide();
    getcalenderevent();

  });

    $(document).on('click','.reset-data', function () {

    location.reload();

  });


});

</script>

<script language="javascript">
function getcalenderevent () {

  

	$('#calendar').fullCalendar({
		//timeFormat: 'H(:mm)t',
		header: {
        	left: 'prev,next today',
            center: 'title',
            right: 'month'
		},
        buttonText: {
            today: 'today',
            month: 'month',
            week: 'week',
            day: 'day'
        },
		//hiddenDays: [ 2, 4 ],
        events: function(start, end, timezone, callback) {
       
			$.ajax({
        
    
				url	: '<?= site_url('report/schedule')?>',
				dataType: 'json',
				type	: 'POST',
				data	: {
					start	: start.format(),
					end		: end.format(),
          nama : $("#nama").val(),
          tahun : $("#tahun").val(),
          bulan : $("#bulan").val()
          
				},
       
				success: function(doc) {
					var events = [];
					//console.log('events #########');
					callback(doc);
				}
			});
		},
        editable: true,
        droppable: true, // this allows things to be dropped onto the calendar !!!
        drop: function (date, allDay) { },
		eventClick: function(calEvent, jsEvent, view) {
			//alert('Event: ' + calEvent.title);
			//alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY);
			//alert('View: ' + view.name);
			// change the border color just for fun
			//$(this).css('border-color', 'red');
		},
		dayRender: function(date, cell){
			//console.log('dayRender');
    		//console.log(date.format());
			//$(cell).addClass('fc-disabled').html('Disabled');
			 $(cell).css('opacity', 1);
			//$(cell).css("display", "none");//    display:none;
		},
		viewRender: function(view, element) {},
		eventRender: function(ev, element, view) {
			//element.qtip({content: ev.title});
		},
		eventAfterRender : function(ev, element, view) {
			if(ev.block == true) {
				//console.log('After Render = ' + ev.title + ' BLOCK ? ' + ev.block);
				//fc-day fc-widget-content
				var start = ev.start.format();
				$("td.fc-day[data-date='"+ start +"']").addClass('fc-disabled');
			}
		}

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

<?=$this->endSection()?>
