<script type="text/javascript">
	$(document).ready(function(){
		console.log('tab professional licenses loaded..');
	});

	function btnEditLicense(elem) {
		var b64  = $(elem).data('content');
		var json = JSON.parse(atob(b64));

		console.log(json); 

		$('#mdl-license-id').val(json.id);
		$('#mdl-license-profession').val(json.profession);
		$('#mdl-license-no').val(json.license_no);
		var [yy_reg, mm_reg, dd_reg] = json.register_date.split('-');
		var [yy_ren, mm_ren, dd_ren] = json.renewal_date.split('-');
		
		$('#mdl-license-reg-date').val(dd_reg+'-'+mm_reg+'-'+yy_reg);
		$('#mdl-license-renew-date').val(dd_ren+'-'+mm_ren+'-'+yy_ren);

		$('#mdl-license-attachment-id').val(json.attachment_id);
	}

	function btnRemoveLicense (id) {
		iziToast.question({
	        title: '',
	        timeout:20000,
	        close: false,
	        toastOnce: true,
	        message: 'Are you sure you want to remove this record? ',
	        position:"center",
	        buttons: [
	                    ['<button><b>YES</b></button>', function (instance, toast) {
	                        _removeLicense(id);
	                        instance.hide(toast, {
	                            transitionOut: 'fadeOutUp'
	                        });
	                    }],
	                    ["<button>No</button>", function (instance, toast) {
	                        instance.hide(toast, {
	                            transitionOut: 'fadeOutUp'
	                        });

	                        iziToast.warning({
	                            position: 'bottomRight',
	                            message: 'Operation cancelled.'
	                        });

	                    },true]
	                ]
	        });
	}

	function _removeLicense(id) {
		var frmData = new FormData();
		frmData.append('id',id);

		$.ajax({
            url:"<?php echo base_url('hr/StaffProfile/removeLicense/'); ?>",
            type:'post',
            dataType:'json', //return type value
            data:frmData,
            processData: false,
            contentType: false,
            success:function(data){
                iziToast.success({
                    title: '',
                    message:'success'
                });
                window.location.replace("<?php echo base_url('hr/StaffProfile/staffDetail/'.$this->uri->segment(4)); ?>");            
            },error:function(){
                iziToast.error({
                    title: '',
                    message: '500 internal server error'
                });
            }
        });
	}
</script>