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

120 lines
4.9 KiB
JavaScript

$(document).ready(function() {
var oTableUserLst = $('#tblUserLst').DataTable({
"processing": true,
"serverSide": true,
'responsive': false,
'destroy' : true,
"columns": [
{ "data": "status", "orderable" : false,
"render": function ( data, type, row ) {
var status = "-", statusDesc;
if(data) {
var color = "badge-primary";
if(data == 'A') {
color = "badge-success";
statusDesc = "ACTIVE";
} else if(data == 'F') {
color = "badge-warning";
statusDesc = "PENDING";
} else {
color = "badge-danger";
statusDesc = "INACTIVE";
}
status = "<span class='badge badge-pill " + color + "'>" + statusDesc + "</span>";
}
return status;
}
},
{ "data": null,
"render": function ( data, type, row ) {
return "<div>" + row.firstName + " " + row.lastName + "</div><i>" + row.email + "</i>" ;
}
},
{ "data": "userId" },
{ "data": "userRoleGroup.userGroupDesc" },
{ "data": "createDt", "render": function ( data, type, row ) {
return data ? data : "";
}
},
{ "data": "lastLogin", "render": function ( data, type, row ) {
return data ? data : "";
}
},
{ "data": null, className: 'td-actions text-right', "orderable" : false,
"render": function ( data, type, row ) {
var buttons = action.btnGroupOpen + action.viewButton + action.closeDiv;
if (row.status == 'A') {
buttons = action.btnGroupOpen + action.editButton + action.deactivateButton + action.closeDiv;
} else if (row.status == 'I') {
buttons = action.btnGroupOpen + action.viewButton + action.closeDiv;
} else if (row.status == 'F') {
buttons = action.btnGroupOpen + action.viewButton + action.deactivateButton + action.closeDiv;
}
return buttons;
}
},
],
"ajax": $.fn.dataTable.pipeline({
"pages" : 1,
"type" : "GET",
"url": contextPath + "/manageUsers/paginated",
"action": 'xhttp',
'beforeSend': dtRequestHeader,
"dataSrc": dtDataSrc,
"data": function ( data ) {
data.firstName = $("#firstName").val();
data.lastName = $("#lastName").val();
data.status = $('#status').find(":selected").val();
data.userRoleGroupCode = $('#userRoleGroupCode').find(":selected").val();
},
"error": function(){ // error handling
console.log("error");
}
}),
"initComplete": function(settings, json) {
$('input#firstName').unbind();
$('input#lastName').unbind();
$('input#status').unbind();
$('#searchFilter').bind('click', function(e) {
portalUtil.showMainLoading(true);
oTableUserLst
.column(1).search($('input#firstName').val())
.column(2).search($('input#lastName').val())
.column(4).search($('#status').find(":selected").val())
if($('#userRoleGroupCode') != undefined) {
oTableUserLst.column(3).search($('#userRoleGroupCode').find(":selected").val())
}
oTableUserLst.draw();
$(".em-toggle").click();
});
$('#searchClear').bind('click', function(e) {
$('input#firstName').val("")
$('input#lastName').val("")
$("#status").val("").select2();
$("#userRoleGroupCode").val("").select2();
oTableUserLst.columns().search("").draw();
$(".em-toggle").click();
});
},
"fnDrawCallback": function ( oSettings ) { hidePagination(this,"#tblUserLst"); portalUtil.showMainLoading(false);}
});
$('#tblUserLst').dataTable().fnSetFilteringEnterPress();
$('#tblUserLst tbody').on( 'click', 'button.view', function () {
var d = oTableUserLst.row( $(this).parents('tr') ).data();
location.href = contextPath + "/manageUsers/edit?id=" + d.userProfId;
});
$('#tblUserLst tbody').on( 'click', 'button.edit', function () {
var d = oTableUserLst.row( $(this).parents('tr') ).data();
location.href = contextPath + "/manageUsers/edit?id=" + d.userProfId;
});
/*$('#tblUserLst tbody').on( 'click', 'button.btn-view', function () {
var d = oTableUserLst.row( this ).data();
location.href = contextPath + "/users/user?id=" + d.userId;
});*/
/*$('#tblUserLst tbody').on( 'mouseover', 'tr', function () {
var d = oTableUserLst.row( this ).data();
if(d != undefined) { $(this).addClass('cursor-pointer'); }
});*/
});