Upgrade to v26 (#172)
* A bunch of new updates from icehrm pro * Push changes to frontend
This commit is contained in:
4
web/admin/src/attendance/index.js
Normal file
4
web/admin/src/attendance/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import { AttendanceAdapter, AttendanceStatusAdapter } from './lib';
|
||||
|
||||
window.AttendanceAdapter = AttendanceAdapter;
|
||||
window.AttendanceStatusAdapter = AttendanceStatusAdapter;
|
||||
289
web/admin/src/attendance/lib.js
Normal file
289
web/admin/src/attendance/lib.js
Normal file
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
Copyright (c) 2018 [Glacies UG, Berlin, Germany] (http://glacies.de)
|
||||
Developer: Thilina Hasantha (http://lk.linkedin.com/in/thilinah | https://github.com/thilinah)
|
||||
*/
|
||||
|
||||
import AdapterBase from '../../../api/AdapterBase';
|
||||
import FormValidation from '../../../api/FormValidation';
|
||||
|
||||
class AttendanceAdapter extends AdapterBase {
|
||||
constructor(endPoint, tab, filter, orderBy) {
|
||||
super(endPoint, tab, filter, orderBy);
|
||||
this.photoAttendance = false;
|
||||
}
|
||||
|
||||
getDataMapping() {
|
||||
return [
|
||||
'id',
|
||||
'employee',
|
||||
'in_time',
|
||||
'out_time',
|
||||
'note',
|
||||
];
|
||||
}
|
||||
|
||||
getHeaders() {
|
||||
return [
|
||||
{ sTitle: 'ID', bVisible: false },
|
||||
{ sTitle: 'Employee' },
|
||||
{ sTitle: 'Time-In' },
|
||||
{ sTitle: 'Time-Out' },
|
||||
{ sTitle: 'Note' },
|
||||
];
|
||||
}
|
||||
|
||||
getFormFields() {
|
||||
return [
|
||||
['employee', {
|
||||
label: 'Employee', type: 'select2', 'allow-null': false, 'remote-source': ['Employee', 'id', 'first_name+last_name'],
|
||||
}],
|
||||
['id', { label: 'ID', type: 'hidden' }],
|
||||
['in_time', { label: 'Time-In', type: 'datetime' }],
|
||||
['out_time', { label: 'Time-Out', type: 'datetime', validation: 'none' }],
|
||||
['note', { label: 'Note', type: 'textarea', validation: 'none' }],
|
||||
];
|
||||
}
|
||||
|
||||
getFilters() {
|
||||
return [
|
||||
['employee', {
|
||||
label: 'Employee', type: 'select2', 'allow-null': false, 'remote-source': ['Employee', 'id', 'first_name+last_name'],
|
||||
}],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
setPhotoAttendance(val) {
|
||||
this.photoAttendance = parseInt(val, 10);
|
||||
}
|
||||
|
||||
|
||||
getCustomTableParams() {
|
||||
const that = this;
|
||||
const dataTableParams = {
|
||||
aoColumnDefs: [
|
||||
{
|
||||
fnRender(data, cell) {
|
||||
return that.preProcessRemoteTableData(data, cell, 2);
|
||||
},
|
||||
aTargets: [2],
|
||||
},
|
||||
{
|
||||
fnRender(data, cell) {
|
||||
return that.preProcessRemoteTableData(data, cell, 3);
|
||||
},
|
||||
aTargets: [3],
|
||||
},
|
||||
{
|
||||
fnRender(data, cell) {
|
||||
return that.preProcessRemoteTableData(data, cell, 4);
|
||||
},
|
||||
aTargets: [4],
|
||||
},
|
||||
{
|
||||
fnRender: that.getActionButtons,
|
||||
aTargets: [that.getDataMapping().length],
|
||||
},
|
||||
],
|
||||
};
|
||||
return dataTableParams;
|
||||
}
|
||||
|
||||
preProcessRemoteTableData(data, cell, id) {
|
||||
if (id === 2) {
|
||||
if (cell === '0000-00-00 00:00:00' || cell === '' || cell === undefined || cell == null) {
|
||||
return '';
|
||||
}
|
||||
return Date.parse(cell).toString('yyyy MMM d <b>HH:mm</b>');
|
||||
} if (id === 3) {
|
||||
if (cell === '0000-00-00 00:00:00' || cell === '' || cell === undefined || cell == null) {
|
||||
return '';
|
||||
}
|
||||
return Date.parse(cell).toString('MMM d <b>HH:mm</b>');
|
||||
} if (id === 4) {
|
||||
if (cell !== undefined && cell !== null) {
|
||||
if (cell.length > 10) {
|
||||
return `${cell.substring(0, 10)}..`;
|
||||
}
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
save() {
|
||||
const validator = new FormValidation(`${this.getTableName()}_submit`, true, { ShowPopup: false, LabelErrorClass: 'error' });
|
||||
if (validator.checkValues()) {
|
||||
const params = validator.getFormParameters();
|
||||
|
||||
const msg = this.doCustomValidation(params);
|
||||
if (msg == null) {
|
||||
const id = $(`#${this.getTableName()}_submit #id`).val();
|
||||
if (id != null && id !== undefined && id !== '') {
|
||||
params.id = id;
|
||||
}
|
||||
|
||||
const reqJson = JSON.stringify(params);
|
||||
const callBackData = [];
|
||||
callBackData.callBackData = [];
|
||||
callBackData.callBackSuccess = 'saveSuccessCallback';
|
||||
callBackData.callBackFail = 'saveFailCallback';
|
||||
|
||||
this.customAction('savePunch', 'admin=attendance', reqJson, callBackData);
|
||||
} else {
|
||||
const label = $(`#${this.getTableName()}Form .label`);
|
||||
label.html(msg);
|
||||
label.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
saveSuccessCallback(callBackData) {
|
||||
this.get(callBackData);
|
||||
}
|
||||
|
||||
|
||||
saveFailCallback(callBackData) {
|
||||
this.showMessage('Error saving attendance entry', callBackData);
|
||||
}
|
||||
|
||||
isSubProfileTable() {
|
||||
return this.user.user_level !== 'Admin';
|
||||
}
|
||||
|
||||
showPunchImages(id) {
|
||||
const reqJson = JSON.stringify({ id });
|
||||
const callBackData = [];
|
||||
callBackData.callBackData = [];
|
||||
callBackData.callBackSuccess = 'getImagesSuccessCallback';
|
||||
callBackData.callBackFail = 'getImagesFailCallback';
|
||||
this.customAction('getImages', 'admin=attendance', reqJson, callBackData);
|
||||
}
|
||||
|
||||
getImagesSuccessCallback(callBackData) {
|
||||
$('#attendancePhotoModel').modal('show');
|
||||
$('#attendnaceCanvasEmp').html(callBackData.employee_Name);
|
||||
if (callBackData.in_time) {
|
||||
$('#attendnaceCanvasPunchInTime').html(Date.parse(callBackData.in_time).toString('yyyy MMM d <b>HH:mm</b>'));
|
||||
}
|
||||
|
||||
if (callBackData.image_in) {
|
||||
const myCanvas = document.getElementById('attendnaceCanvasIn');
|
||||
const ctx = myCanvas.getContext('2d');
|
||||
const img = new Image();
|
||||
img.onload = function () {
|
||||
ctx.drawImage(img, 0, 0); // Or at whatever offset you like
|
||||
};
|
||||
img.src = callBackData.image_in;
|
||||
}
|
||||
|
||||
if (callBackData.out_time) {
|
||||
$('#attendnaceCanvasPunchOutTime').html(Date.parse(callBackData.out_time).toString('yyyy MMM d <b>HH:mm</b>'));
|
||||
}
|
||||
|
||||
if (callBackData.image_out) {
|
||||
const myCanvas = document.getElementById('attendnaceCanvasOut');
|
||||
const ctx = myCanvas.getContext('2d');
|
||||
const img = new Image();
|
||||
img.onload = function () {
|
||||
ctx.drawImage(img, 0, 0); // Or at whatever offset you like
|
||||
};
|
||||
img.src = callBackData.image_out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
getImagesFailCallback(callBackData) {
|
||||
this.showMessage('Error', callBackData);
|
||||
}
|
||||
|
||||
getActionButtonsHtml(id, data) {
|
||||
const editButton = '<img class="tableActionButton" src="_BASE_images/edit.png" style="cursor:pointer;" rel="tooltip" title="Edit" onclick="modJs.edit(_id_);return false;"></img>';
|
||||
const deleteButton = '<img class="tableActionButton" src="_BASE_images/delete.png" style="margin-left:15px;cursor:pointer;" rel="tooltip" title="Delete" onclick="modJs.deleteRow(_id_);return false;"></img>';
|
||||
const photoButton = '<img class="tableActionButton" src="_BASE_images/cam.png" style="margin-left:15px;cursor:pointer;" rel="tooltip" title="Show Photo" onclick="modJs.showPunchImages(_id_);return false;"></img>';
|
||||
|
||||
let html;
|
||||
if (this.photoAttendance === 1) {
|
||||
html = '<div style="width:80px;">_edit__delete__photo_</div>';
|
||||
} else {
|
||||
html = '<div style="width:80px;">_edit__delete_</div>';
|
||||
}
|
||||
|
||||
html = html.replace('_photo_', photoButton);
|
||||
|
||||
if (this.showDelete) {
|
||||
html = html.replace('_delete_', deleteButton);
|
||||
} else {
|
||||
html = html.replace('_delete_', '');
|
||||
}
|
||||
|
||||
if (this.showEdit) {
|
||||
html = html.replace('_edit_', editButton);
|
||||
} else {
|
||||
html = html.replace('_edit_', '');
|
||||
}
|
||||
|
||||
html = html.replace(/_id_/g, id);
|
||||
html = html.replace(/_BASE_/g, this.baseUrl);
|
||||
return html;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Attendance Status
|
||||
*/
|
||||
|
||||
class AttendanceStatusAdapter extends AdapterBase {
|
||||
getDataMapping() {
|
||||
return [
|
||||
'id',
|
||||
'employee',
|
||||
'status',
|
||||
];
|
||||
}
|
||||
|
||||
getHeaders() {
|
||||
return [
|
||||
{ sTitle: 'ID', bVisible: false },
|
||||
{ sTitle: 'Employee' },
|
||||
{ sTitle: 'Clocked In Status' },
|
||||
];
|
||||
}
|
||||
|
||||
getFormFields() {
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
getFilters() {
|
||||
return [
|
||||
['employee', {
|
||||
label: 'Employee', type: 'select2', 'allow-null': false, 'remote-source': ['Employee', 'id', 'first_name+last_name'],
|
||||
}],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
getActionButtonsHtml(id, data) {
|
||||
let html = '<div class="online-button-_COLOR_"></div>';
|
||||
html = html.replace(/_BASE_/g, this.baseUrl);
|
||||
if (data[2] == 'Not Clocked In') {
|
||||
html = html.replace(/_COLOR_/g, 'gray');
|
||||
} else if (data[2] == 'Clocked Out') {
|
||||
html = html.replace(/_COLOR_/g, 'yellow');
|
||||
} else if (data[2] == 'Clocked In') {
|
||||
html = html.replace(/_COLOR_/g, 'green');
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
isSubProfileTable() {
|
||||
return this.user.user_level !== 'Admin';
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { AttendanceAdapter, AttendanceStatusAdapter };
|
||||
Reference in New Issue
Block a user