(function( $ ){
   $.fn.refreshAcSessionList = function(options) {

		var defaultContentField = $(this).find("tbody");
		var defaultContent = $(defaultContentField).html();

      	$.ajax({
		    type: 'POST',
		    url: 'contents/plugins/eedu_portal/ajax.php',
		    data: {action: 'get_ac_sessions'},
		    success: function(data) {
		    	data = JSON.parse(data);
		    	if(data.error == 1) {
		    		$(defaultContentField).html(defaultContent);
		    	} else if(data.error == 0) {
		    		var html = "";
		    		var i = 1;
		    		for(var key in data.acsessions) {
			    		html += '<tr>';
			    		html += '<td class="pt-0 pb-0">'+i+'</td>';
			    		html += '<td class="pt-0 pb-0">'+data.acsessions[key].id+'</td>';
			    		html += '<td class="pt-0 pb-0">'+data.acsessions[key].session_name+'</td>';
			    		if(data.current == data.acsessions[key].id) {
			    			html += '<td class="pt-0 pb-0 green">In Session</td>';
			    		} else {
			    			html += '<td class="pt-0 pb-0 red">Not In Session</td>';
			    		}
			    		html += '<td class="pt-0 pb-0"><a href="academic-session?id='+data.acsessions[key].id+'" class="btn btn-outline-info btn-block"><i class="fas fa-folder-open"></i> View</a></td>';
			    		html += '</tr>';
			    		i++;
			    	}
		    		$(defaultContentField).html(html);
		    	}	
		    },
		    error: function(e) {
		    	$(defaultContentField).html(defaultContent);
		    }
		});
   }; 
})( jQuery );

jQuery(document).ready(function($){
	var table = $(".list-table");
	$.each(table, function(index, tabl){
		var refreshFunction = $(tabl).data("refresh");
		eval('$("#'+tabl.id+'").'+refreshFunction+"()");
	})
})