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

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

	console.log(json);

	$('#mdl-recognition-id').val(json.id);
	$('#mdl-recognition-achievement').val(json.achievement);
	$('#mdl-recognition-award').val(json.award);
	$('#mdl-recognition-year').val(json.year);

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

function btnRemoveRecognition(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) {
	                        _removeRecognition(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 _removeRecognition(id) {
		var frmData = new FormData();
		frmData.append('id',id);

		$.ajax({
            url:"<?php echo base_url('hr/StaffProfile/removeRecognition/'); ?>",
            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>