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

326 lines
11 KiB
JavaScript

$(document).ready(function() {
var oTableTaskLst = $('#tblTaskLst').DataTable({
"dom": 'rt<"bottom text-center"pi><"clear">',
"scrollY": "442px",
"scrollCollapse": true,
"pagingType": "numbers",
"processing": true,
"serverSide": true,
'responsive': true,
'destroy': true,
"columns": [
{
"data": null, "orderable": false,
"render": function(data, type, row) {
var buttons = '<div class="btn-group btn-group-sm m-0 p-0 pull-right"><button type="button" rel="tooltip" class="btn btn-info btn-just-icon release" data-original-title="Release" title="Release">' +
'<i class="material-icons">launch</i>' +
'</button>' + action.viewIconButton + '</div>';
var status = "<div class='card m-0'><div class='card-body p-3'>" +
"<div class='row m-0 p-0'>" +
"<div class='col-6 m-0 p-0'><span class='badge badge-pill " + data.status.legendColor + "'>" + data.status.statusDesc + "</span></div>" +
"<div class='col-6 m-0 p-0 text-right'>" + buttons + "</div>" +
"</div>" +
"<h6 class='card-category'>" + data.type.description.toUpperCase() + "</h6>" +
"<h5 class='card-title mb-0'>" + data.applicant.toUpperCase() + "</h5>" +
"<div class='card-description p-0 m-0'><div class='row m-0 p-0'>" +
"<div class='col-6 m-0 p-0'>" + data.appRefNo + "</div>" +
"<div class='col-6 m-0 p-0 text-right'>" + data.appDate + "</div></div></div>";
return status;
}
},
],
"ajax": $.fn.dataTable.pipeline({
"pages": 1,
"type": "GET",
"url": contextPath + "/taskboard/inbox/paginated",
"action": 'xhttp',
"cache": false,
'beforeSend': dtRequestHeader,
'dataType': 'json',
"dataSrc": dtDataSrc,
"data": function(data) {
data.globalParam = $("input#globalParam").val();
},
"error": function() { // error handling
console.log("error");
}
}),
"initComplete": function(settings, json) {
$('#searchFilter').bind('click', function(e) {
oTableTaskLst.columns().search($('input#globalParam').val()).draw();
$(".em-toggle").click();
});
$('#clearFilter').bind('click', function(e) {
oTableTaskLst.columns().search($('input#globalParam').val("")).draw();
$(".em-toggle").click();
$('input#globalParam').parent().removeClass("is-filled")
});
},
"fnDrawCallback": function(oSettings) { hidePagination(this, "#tblTaskLst"); portalUtil.showMainLoading(false); $("#tblTaskLst thead").remove(); }
});
$('#tblTaskLst').dataTable().fnSetFilteringEnterPress();
$('#tblTaskLst tbody').on('click', 'button.view', function() {
var d = oTableTaskLst.row($(this).parents('tr')).data();
redirectPath(d);
});
$('#tblTaskLst tbody').on('click', 'button.release', function() {
var d = oTableTaskLst.row($(this).parents('tr')).data();
Swal.fire({
text: 'Are you sure you want to release the application (' + d.appRefNo + ')?',
type: 'question',
showCancelButton: true,
showConfirmButton: true,
cancelButtonText: 'No',
confirmButtonText: 'Yes',
allowOutsideClick: false,
allowEscapeKey: false,
cancelButtonColor: '#999999',
confirmButtonColor: '#4CAF50'
}).then((result) => {
if (result.value) {
var inputUrl = contextPath + "/taskboard/release";
var dataArr = {};
dataArr.taskMasterId = d.taskMasterId
$.ajax({
async: false,
global: false,
headers: {
'X-CSRF-Token': csrf_token
},
type: "POST",
action: 'xhttp',
url: inputUrl,
data: dataArr,
success: function(data) {
if (data == 'success') {
oTableTaskLst.clearPipeline();
oTableTaskLst.ajax.reload();
oTablePoolLst.clearPipeline();
oTablePoolLst.ajax.reload();
portalUtil.showNotification('bottom', 'right', "You have released <strong>" + d.appRefNo + "</strong> application.", 'success');
}
}
});
} else if (result.dismiss === swal.DismissReason.cancel) {
return false;
}
});
});
var oTablePoolLst = $('#tblPoolLst').DataTable({
dom: 'rt<"bottom text-center"pi><"clear">',
"scrollY": "442px",
"scrollCollapse": true,
"pagingType": "numbers",
"processing": true,
"serverSide": true,
'responsive': true,
'destroy': true,
"columns": [
{
"data": null, "orderable": false,
"render": function(data, type, row) {
var buttons = '<div class="btn-group btn-group-sm pull-right m-0 p-0"><button type="button" rel="tooltip" class="btn btn-info btn-just-icon claim" data-original-title="Claim" title="Claim">' +
'<i class="material-icons">system_update_alt</i>' +
'</button>' + action.viewIconButton + '</div>';
var status = "<div class='card m-0'><div class='card-body p-3'>" +
"<div class='row m-0 p-0'>" +
"<div class='col-6 m-0 p-0'><span class='badge badge-pill " + data.status.legendColor + "'>" + data.status.statusDesc + "</span></div>" +
"<div class='col-6 m-0 p-0 text-right'>" + buttons + "</div>" +
"</div>" +
"<h6 class='card-category'>" + data.type.description.toUpperCase() + "</h6>" +
"<h5 class='card-title mb-0'>" + data.applicant.toUpperCase() + "</h5>" +
"<div class='card-description p-0 m-0'><div class='row m-0 p-0'>" +
"<div class='col-6 m-0 p-0'>" + data.appRefNo + "</div>" +
"<div class='col-6 m-0 p-0 text-right'>" + data.appDate + "</div></div></div>";
return status;
}
},
],
"ajax": $.fn.dataTable.pipeline({
"pages": 1,
"type": "GET",
"url": contextPath + "/taskboard/pool/paginated",
"action": 'xhttp',
"cache": false,
'beforeSend': dtRequestHeader,
'dataType': 'json',
"dataSrc": dtDataSrc,
"data": function(data) {
data.globalParam = $("input#globalPoolParam").val();
data.pool = true;
},
"error": function() { // error handling
console.log("error");
}
}),
"initComplete": function(settings, json) {
$("#tblPoolLst thead").remove();
$('#searchPoolFilter').bind('click', function(e) {
oTablePoolLst.columns().search($('input#globalPoolParam').val()).draw();
$(".em-toggle").click();
});
$('#clearPoolFilter').bind('click', function(e) {
oTablePoolLst.columns().search($('input#globalPoolParam').val("")).draw();
$(".em-toggle").click();
$('input#globalPoolParam').parent().removeClass("is-filled")
});
},
"fnDrawCallback": function(oSettings) { hidePagination(this, "#tblPoolLst"); portalUtil.showMainLoading(false); }
});
$('#tblPoolLst').dataTable().fnSetFilteringEnterPress();
$('#tblPoolLst tbody').on('click', 'button.view', function() {
var d = oTablePoolLst.row($(this).parents('tr')).data();
redirectPath(d);
});
$('#tblPoolLst tbody').on('click', 'button.claim', function() {
var d = oTablePoolLst.row($(this).parents('tr')).data();
Swal.fire({
text: 'Are you sure you want to claim the application (' + d.appRefNo + ')?',
type: 'question',
showCancelButton: true,
showConfirmButton: true,
cancelButtonText: 'No',
confirmButtonText: 'Yes',
allowOutsideClick: false,
allowEscapeKey: false,
cancelButtonColor: '#999999',
confirmButtonColor: '#4CAF50'
}).then((result) => {
if (result.value) {
var inputUrl = contextPath + "/taskboard/claim";
var dataArr = {};
dataArr.taskMasterId = d.taskMasterId
$.ajax({
async: false,
global: false,
headers: {
'X-CSRF-Token': csrf_token
},
type: "POST",
action: 'xhttp',
url: inputUrl,
data: dataArr,
success: function(data) {
if (data == 'success') {
oTablePoolLst.clearPipeline();
oTablePoolLst.ajax.reload();
oTableTaskLst.clearPipeline();
oTableTaskLst.ajax.reload();
oTableHistoryLst.clearPipeline();
oTableHistoryLst.ajax.reload();
portalUtil.showNotification('bottom', 'right', "You have claimed <strong>" + d.appRefNo + "</strong> application.", 'success');
}
}
});
} else if (result.dismiss === swal.DismissReason.cancel) {
return false;
}
});
});
var oTableHistoryLst = $('#tblHistoryLst').DataTable({
dom: 'rt<"bottom text-center"pi><"clear">',
"scrollY": "442px",
"scrollCollapse": true,
"pagingType": "numbers",
"processing": true,
"serverSide": true,
'responsive': true,
'destroy': true,
"columns": [
{
"data": null, "orderable": false,
"render": function(data, type, row) {
var buttons = '<div class="btn-group btn-group-sm pull-right m-0 p-0">' + action.viewIconButton + '</div>';
var status = "<div class='card m-0'><div class='card-body p-3'>" +
"<div class='row m-0 p-0'><div class='col-6 m-0 p-0'>" +
"<span class='badge badge-pill " + data.status.legendColor + "'>" + data.status.statusDesc + "</span>" + "</div>" +
"<div class='col-6 m-0 p-0 text-right'>" + buttons + "</div></div>" +
"<h6 class='card-category'>" + data.type.description.toUpperCase() + "</h6>" +
"<h5 class='card-title mb-0'>" + data.applicant.toUpperCase() + "</h5>" +
"<div class='card-description p-0 m-0'><div class='row m-0 p-0'>" +
"<div class='col-6 m-0 p-0'>" + data.appRefNo + "</div>" +
"<div class='col-6 m-0 p-0 text-right'>" + data.appDate + "</div></div></div>";
return status;
}
},
],
"ajax": $.fn.dataTable.pipeline({
"pages": 1,
"type": "GET",
"url": contextPath + "/taskboard/history/paginated",
"action": 'xhttp',
"cache": false,
'beforeSend': dtRequestHeader,
'dataType': 'json',
"dataSrc": dtDataSrc,
"data": function(data) {
data.globalParam = $("#globalParamHistory").val();
data.history = true;
},
"error": function() { // error handling
console.log("error");
}
}),
"initComplete": function(settings, json) {
$('#searchHistoryFilter').bind('click', function(e) {
oTableHistoryLst.columns().search($('input#globalParamHistory').val()).draw();
$(".em-toggle").click();
});
$('#clearHistoryFilter').bind('click', function(e) {
oTableHistoryLst.columns().search($('input#globalParamHistory').val("")).draw();
$(".em-toggle").click();
$('input#globalParamHistory').parent().removeClass("is-filled")
});
},
"fnDrawCallback": function(oSettings) {
hidePagination(this, "#tblHistoryLst"); portalUtil.showMainLoading(false);
$("#tblHistoryLst thead").remove();
$('.dataTables_scrollHead').remove();
}
});
$('#tblHistoryLst').dataTable().fnSetFilteringEnterPress();
$('#tblHistoryLst tbody').on('click', 'button.view', function() {
var d = oTableHistoryLst.row($(this).parents('tr')).data();
redirectPath(d);
});
function redirectPath(d) {
if (d.type.redirectPath) {
var url = contextPath + '/taskboard/workflow'; //d.type.redirectPath;
var form = document.createElement("form");
form.setAttribute("method", "GET");
for (let k of Object.keys(d)) {
if (d[k] != null) {
setAttributes(k, d[k], form);
}
}
form.action = url;
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
}
}
function setAttributes(key, val, form) {
if (typeof val == 'string' || typeof val == 'number' || typeof val == 'boolean') {
$("<input />").attr("type", "hidden")
.attr("name", key).attr("value", val)
.appendTo(form);
} else if (val != null && typeof val == 'object') {
for (let s of Object.keys(val)) {
setAttributes(key + '.' + s, val[s], form)
}
}
}
});