var audit_log_obj = null;

$(document).ready(function() {
}) ;

function filterAuditLog() {
	LoadingScreen("show");
	if (validateFilter()) {
        var data = { 
			"type": C_QUERY, 
			"log_bu": $('#txtFilterAuditLogBU').val(), 
			"log_table": $('#txtFilterAuditLogTable').val(), 
			"log_table_desc": $('#txtFilterAuditLogTable option:selected').text(),
			"log_user": $('#txtFilterAuditLogUser').val(), 
			"log_activity": $('#txtFilterAuditLogActivity').val(), 
			"log_date_from": $('#txtFilterAuditLogDateFrom').val(), 
			"log_date_to": $('#txtFilterAuditLogDateTo').val(),
		} ;
        var url = "request.pzx?c=" + audit_log_url + "&d=" + new Date().getTime() ;
        callServer(url,"json",data,onResponseAuditLog) ;
    }else{
		LoadingScreen("hide");
	}
}

function validateFilter() {
	if ($('#txtFilterAuditLogBU').val()=='') {
		swal.fire("Warning", 'You must select a business unit.',"warning") ;
		$('#txtFilterAuditLogBU').focus() ;
		return false ;
	}
	if ($('#txtFilterAuditLogTable').val()=='') {
		swal.fire("Warning", 'You must select a table.',"warning") ;
		$('#txtFilterAuditLogTable').focus() ;
		return false ;
	}
	return true ;
}

function onResponseAuditLog(obj, resp){
	LoadingScreen("hide");
    if(resp.status != C_OK){
		$('#modalMessageHomeViewContent').html(resp.mesg);
		$('#messageHomeView').modal('show');
		return;
    }
	
    if(resp.type == C_QUERY){
		$('#auditlog-table-body').html('');
	   	$('#auditlog-table-body').html(resp.data.htmlContent);
		$('#totalRecords').html(resp.data.totalRecords);
	   	filterRow('auditlog-row-filter',this,false);
	}
}

// function exportAuditLogReport() {
// 	if (validateAuditLogReport()) {
// 		var url = "report.pzx?c=" + audit_log_report_url + "&d=" + new Date().getTime() +
//                 "&code=" + $('#cobAuditLogReportUserId').val() + 
//                 "&dt=" + $('#txtAuditLogReportStart').val() + 
//                 "&dtend=" + $('#txtAuditLogReportEnd').val() + 
//             "&t=" + C_EXPORT ;
// 		showReport(url); ;
// 	}
// }
// function printAuditLogReport() {
// 	var url = "report.pzx?c=" + audit_log_report_url + "&d=" + new Date().getTime() +
//                 "&code=" + $('#cobAuditLogReportUserId').val() + 
//                 "&dt=" + $('#txtAuditLogReportStart').val() + 
//                 "&dtend=" + $('#txtAuditLogReportEnd').val() + 
//                 "&t=" + C_REPORT ;
// 	showReport(url) ;
// }

