/**
* App User View - Account (js)
*/
'use strict';
document.addEventListener('DOMContentLoaded', function (e) {
// Variable declaration for table
const dt_project_table = document.querySelector('.datatable-project'),
dt_invoice_table = document.querySelector('.datatable-invoice');
// Project datatable
// --------------------------------------------------------------------
if (dt_project_table) {
let tableTitle = document.createElement('h5');
tableTitle.classList.add('card-title', 'mb-0', 'text-md-start', 'text-center', 'pt-md-0', 'pt-6');
tableTitle.innerHTML = 'Project List';
var dt_project = new DataTable(dt_project_table, {
ajax: assetsPath + 'json/user-profile.json', // JSON file to add data
columns: [
{ data: 'id' },
{ data: 'id', orderable: false, render: DataTable.render.select() },
{ data: 'project_name' },
{ data: 'project_leader' },
{ data: 'id' },
{ data: 'status' },
{ data: 'id' }
],
columnDefs: [
{
// For Responsive
className: 'control',
searchable: false,
orderable: false,
responsivePriority: 2,
targets: 0,
render: function (data, type, full, meta) {
return '';
}
},
{
// For Checkboxes
targets: 1,
orderable: false,
searchable: false,
responsivePriority: 3,
checkboxes: true,
render: function () {
return '';
},
checkboxes: {
selectAllRender: ''
}
},
{
targets: 2,
responsivePriority: 4,
render: function (data, type, full, meta) {
var userImg = full['project_img'],
name = full['project_name'],
date = full['date'];
var output;
if (userImg) {
// For Avatar image
output =
'';
} else {
// For Avatar badge
var stateNum = Math.floor(Math.random() * 6);
var states = ['success', 'danger', 'warning', 'info', 'primary', 'secondary'];
var state = states[stateNum],
initials = name.match(/\b\w/g) || [];
initials = ((initials.shift() || '') + (initials.pop() || '')).toUpperCase();
output = '' + initials + '';
}
// Creates full output for row
var rowOutput =
'
' +
'
' +
'
' +
output +
'
' +
'
' +
'
' +
'' +
name +
'' +
'' +
date +
'' +
'
' +
'
';
return rowOutput;
}
},
{
// Task
targets: 3,
render: function (data, type, full, meta) {
var task = full['project_leader'];
return '' + task + '';
}
},
{
targets: 4,
orderable: false,
searchable: false,
render: function (data, type, full, meta) {
const team = full['team'];
let teamItem = '';
let teamCount = 0;
// Iterate through team members and generate the list items
for (let i = 0; i < team.length; i++) {
teamItem += `
`;
teamCount++;
if (teamCount > 2) break;
}
// Check if there are more than 2 team members, and add the remaining avatars
if (teamCount > 2) {
const remainingAvatars = team.length - 3;
if (remainingAvatars > 0) {
teamItem += `
+${remainingAvatars}
`;
}
}
// Combine the team items into the final output
const teamOutput = `