
<?= $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</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
            
              <li class="breadcrumb-item active">Schedule draft & post</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">

      <!-- Default box -->
      <div class="card card-warning">
        <div class="card-header">
          <h3 class="card-title">Schedule draft & post</h3>
      <input type="hidden" id="hdraftid" value="<?php if (isset($id)) echo $id; ?>">
                <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> Database Schedule draft & post filter</p>
         
                </div>


                  <div id="calendar"></div>

        
        </div>
        <!-- /.card-body -->
        <div class="card-footer">
           <button type="submit" class="btn btn-danger" data-toggle="modal" data-target="#form-add">Add new</button>
        </div>
        <!-- /.card-footer-->
      </div>
      <!-- /.card -->

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  </div>
  <?php include('Add_draft_and_post.php');?>
  <?php include('Edit_draft_and_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>
  $(function () {
    $( "#DRAFT_DTM" ).datepicker({ dateFormat: 'dd/mm/yy'});
    $( "#eDRAFT_DTM" ).datepicker({ dateFormat: 'dd/mm/yy'});

  });


   function loadtalent(param){
  
    
      if(param == "new")
      {
        var ddl_username = $("#TALENT_ID");
     
      }else
      {
        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']));
               
             });
             
            }
          });

       
  }

   $(document).ready(function () {
    getcalenderevent();
    loadtalent("new");
    if($("#hdraftid").val() != "")
    {
        editdata();
    }


    $(document).on('click','.save-data', function () {
       if( $("#TALENT_ID").val() == "" || $("#DRAFT_DTM").val() == "" || $("#MEDIA_TYPE").val() == "" || $("#DETAIL_DRAFT").val() == "")
       {
        // Display an info toast with no title
          toastr.error("Mohon isi form dengan lengkap !")
          return false;
       }
       else
       { // jika sudah di isi semua.

          var $data = {
            'TALENT_ID' : $("#TALENT_ID").val(),
            'DRAFT_DTM' : $("#DRAFT_DTM").val(),
            'MEDIA_TYPE' : $("#MEDIA_TYPE").val(),
            'DETAIL_DRAFT' : $("#DETAIL_DRAFT").val()
            
            

          };
          $.ajax({
            type: "POST",
            url: "<?= site_url('tran/simpan/schedule')?>",
            data: $data,
           
            success: function (response) {
              $('#form-add').modal('hide');
              $('#form-add').find('input').val('');
              $("#table-data tbody").html("");
              loadtalent("new");
              getcalenderevent();
            
              toastr.success(response.status);
            
          
           
            }
          });
         

       }
    });

    function editdata (){   
      
    $id = $("#hdraftid").val();
 
    loadtalent("edit");
    $.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();
          $("#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','.edit-data', function () {
       if( $("#eTALENT_ID").val() == "" || $("#eDRAFT_DTM").val() == "" || $("#eMEDIA_TYPE").val() == "" || $("#eDETAIL_DRAFT").val() == "")
       {
        // Display an info toast with no title
          toastr.error("Mohon isi form dengan lengkap !")
          return false;
       }
       else
       { // jika sudah di isi semua.

           var $data = {
            'TALENT_ID' : $("#eTALENT_ID").val(),
            'DRAFT_DTM' : $("#eDRAFT_DTM").val(),
            'MEDIA_TYPE' : $("#eMEDIA_TYPE").val(),
            'DETAIL_DRAFT' : $("#eDETAIL_DRAFT").val(),
            'id' : $("#edraftid").val(),
            
            

          };
          $.ajax({
            type: "POST",
            url: "<?= site_url('tran/update/schedule')?>",
            data: $data,
           
            success: function (response) {
              $('#form-edit').modal('hide');
              $('#form-edit').find('input').val('');
            
              
              toastr.success(response.status);
              window.location.href="<?= site_url('tran/draft-post')?>";

            }
          });
         

       }
    });



   });// end doc ready function

</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('tran/get/calendar')?>',
				dataType: 'json',
				type	: 'POST',
				data	: {
					start	: start.format(),
					end		: end.format()
				},
				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()?>
