-
Notifications
You must be signed in to change notification settings - Fork 10
/
addTimesheet.js
96 lines (91 loc) · 4.19 KB
/
addTimesheet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
$(document).ready(function () {
//To activate Tooltip for this page
$('[data-toggle="tooltip"]').tooltip();
getTimesheetDetails();
//On successful submit display the Modal
if ($('#summarymodalDisplayFlag').val() === 'yes') {
$('#successModal').modal('show');
}
});
/**
* Get the Timesheet Information and populate the fields based on the information.
*/
function getTimesheetDetails() {
var endDate = $('#selectTimePeriod').val();
var employeeId = $('#employeeId').val();
console.log("Selected End Date: " + endDate);
$.ajax({
type: 'GET',
url: '/employeeManagement/api/getTimesheetByEndDate?endDate=' + endDate + "&employeeId=" + employeeId,
success: function (responsedata) {
console.log("Inside success function after getting the timesheet info.");
//Callback to avoid asynchronous calls.
populateTimesheetInfo(responsedata);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
console.log(jqXHR);
}
});
}
/**
* Populate the Timesheet information into the fields.
* @param timesheetObj
*/
function populateTimesheetInfo(timesheetObj) {
//Populate the HTML information.
$('#timesheetStatus').html(timesheetObj.timesheetStatus != null ? timesheetObj.timesheetStatus : '');
$('#submitterName').html(timesheetObj.nameCreated !== null ? timesheetObj.nameCreated : '');
$('#submittedDate').html(timesheetObj.createdAt !== null ? moment(timesheetObj.createdAt).format("MM/DD/YYYY hh:mm a") : '');
$('#approverName').html(timesheetObj.nameApproved !== null ? timesheetObj.nameApproved : '');
$('#approvalDate').html(timesheetObj.dateApproved !== null ? moment(timesheetObj.dateApproved).format("MM/DD/YYYY hh:mm a") : '');
//Populate the input values.
$('#timesheetId').val(timesheetObj.timesheetId != null ? timesheetObj.timesheetId : 0);
$('#regularHoursText').val(timesheetObj.regularHours !== null ? timesheetObj.regularHours : 0.0);
$('#extraHoursText').val(timesheetObj.extraHours !== null ? timesheetObj.extraHours : 0.0);
$('#dscCommentsText').val(timesheetObj.dscComments !== null ? timesheetObj.dscComments : '');
//Timesheet Upload Information
$('#uploadedTimesheetName').html(timesheetObj.dscFileName !== null ? timesheetObj.dscFileName : '');
$('#uploadTimesheetLink').attr('href', timesheetObj.timesheetId !== null ?
('/employeeManagement/api/getUploadedTimesheet?timesheetId=' + timesheetObj.timesheetId) : '#');
//Call the function to Show/Hide the sections based on the status
showHideAuditInfoBasedOnStatus(timesheetObj.timesheetStatus);
}
/**
* Show or Hide Audit information for Submission, Approval and Rejection status and also enable or disable the input elements.
* @param timesheetStatus
*/
function showHideAuditInfoBasedOnStatus(timesheetStatus) {
//Check Timesheet Status and change the Display configurations based on the Status.
console.log('Timesheet Status: ' + timesheetStatus);
if (timesheetStatus === 'SUBMITTED' || timesheetStatus === 'REJECTED') {
enableComponents();
$('#submissionInfoDiv').show();
$('#uploadedTimesheet').show();
$('#approvalInfoDiv').hide();
} else if (timesheetStatus === 'APPROVED') {
disableComponents();
$('#submissionInfoDiv').show();
$('#uploadedTimesheet').show();
$('#approvalInfoDiv').show();
} else {
$('#submissionInfoDiv').hide();
$('#approvalInfoDiv').hide();
$('#uploadedTimesheet').hide();
enableComponents();
}
}
/**
* Disable the form fields and other form components.
*/
function disableComponents() {
$('#addTimesheetForm').find('input, textarea, datepicker').prop('readonly', true);
$('#addTimesheetForm').find('input, textarea, checkbox, datepicker').prop('disabled', true);
}
/**
* Enable the form fields and other form components by removing the readonly and disabled attributes.
*/
function enableComponents() {
$('#addTimesheetForm').find('input, textarea, datepicker').prop('readonly', false);
$('#addTimesheetForm').find('input, textarea, checkbox, datepicker').prop('disabled', false);
}