myMedisys/tomcatfiles/mymedisys-frontend/WEB-INF/classes/scripts/registration/worker-profile.js
2023-09-06 05:56:42 +05:30

125 lines
4.1 KiB
JavaScript

$(document).ready(function() {
component.initFile();
setTimeout(function() {
$('.card.card-wizard').addClass('active');
}, 600);
$('.lazy').lazy();
$(".imageLoad").each(function() {
var val = $(this).val().split(':');
var id = $(this).attr('id') + 'Obj';
$.ajax({
headers: { 'X-CSRF-Token': csrf_token },
type: 'GET',
contentType: "application/json; charset=utf-8",
url: contextPath + "/resources/download?docMgtId=" + val[0] + "&bucketName=" + val[1],
success: function(data) {
imageDetails(data.content, data.contentType, id);
},
error: function(e) {
console.log(e);
}
});
});
$("a.proj-flow").on('show.bs.tab', function(e) {
var val = $(this).closest('li').find('input[type="hidden"]').val();
var reportType = $(this).attr('data-target');
if (val != undefined) {
reportType = reportType.replace("#", "");
var attrReport = $("#" + reportType + "_REPORT");
if (attrReport.attr('data') == undefined) {
portalUtil.showMainLoading(true);
$.ajax({
headers: { 'X-CSRF-Token': csrf_token },
type: 'GET',
contentType: "application/json; charset=utf-8",
url: contextPath + "/resources/getReportDetails?reportType=" + reportType + "&docMgmtId=" + val,
success: function(data) {
// always remove attribute first
removeAttr(data[0].reportType);
reportDetails(data[0].base64image, data[0].docType, data[0].reportType);
portalUtil.showMainLoading(false);
},
error: function(e) {
portalUtil.showMainLoading(false);
}
});
}
}
});
$("#hiddenRow").on('click', '.btn-report', function() {
var data = $(this).attr('value');
reportDetails(data, 'application/pdf');
});
$("#report").on('change', function() {
var reportType = $(this).val();
var wrkrRegId = $("#wrkrRegId").val();
portalUtil.showMainLoading(true);
$.ajax({
headers: { 'X-CSRF-Token': csrf_token },
type: 'GET',
contentType: "application/json; charset=utf-8",
url: contextPath + "/resources/getClearanceReportDetails?reportType=" + reportType + "&wrkrRegId=" + wrkrRegId,
success: function(data) {
// always remove attribute first
removeAttr('reportObj');
// if 1, display immediately the report in screen
if (data.length == 1) {
reportDetails(data[0].base64image, data[0].docType, 'reportObj');
} else {
// if more than 2 create divs by 4
$.each(data, function(i) {
appendReport(data, i);
});
}
portalUtil.showMainLoading(false);
},
error: function(e) {
portalUtil.showMainLoading(false);
}
});
});
});
function appendReport(data, i) {
var imageName = data[i].imageName.split(".")[0].replace(/ /g, '');
var content = "<div class='col-sm-12 col-lg-4 col-md-4'><div class='form-group'>";
content = content + "<button type='button' class='btn btn-block btn-info btn-report' value='" + data[i].base64image + "' id='" + imageName + "_btn'>"
content = content + "<i class='material-icons'>photo</i>";
content = content + data[i].imageName.split(".")[0] + "</button>";
content = content + "<input type='hidden' value='" + data[i].docType + "' id='" + imageName + "_inp'></div></div>"
$("#hiddenRow").append(content);
$("#hiddenRow").slideDown();
}
function removeAttr(reportType) {
$("#" + reportType).removeAttr('data');
$("#" + reportType).removeAttr('type');
}
function reportDetails(content, contentType, reportType) {
// Remove attribute to refresh details
var parent = $("#" + reportType).parent();
contentType = (null != contentType ? contentType : 'application/pdf');
var dt = "data:" + contentType + ";base64," + content;
$("#" + reportType).attr('data', dt);
var newObj = $("#" + reportType).clone();
$("#" + reportType).remove();
$(parent).append(newObj);
}
function imageDetails(content, contentType, id) {
// Remove attribute to refresh details
var parent = $("#" + id).parent();
contentType = (null != contentType ? contentType : 'image/jpeg');
var dt = "data:" + contentType + ";base64," + content;
$("#" + id).attr('src', dt);
var newObj = $("#" + id).clone();
$("#" + id).remove();
$(parent).append(newObj);
}