/*
This file is part of iCE Hrm.
iCE Hrm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
iCE Hrm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with iCE Hrm. If not, see .
------------------------------------------------------------------
Original work Copyright (c) 2012 [Gamonoid Media Pvt. Ltd]
Developer: Thilina Hasantha (thilina.hasantha[at]gmail.com / facebook.com/thilinah)
*/
function EmployeeTimeSheetAdapter(endPoint,tab,filter,orderBy) {
this.initAdapter(endPoint,tab,filter,orderBy);
}
EmployeeTimeSheetAdapter.inherits(AdapterBase);
this.currentTimesheetId = null;
this.currentTimesheet = null;
EmployeeTimeSheetAdapter.method('getDataMapping', function() {
return [
"id",
"date_start",
"date_end",
"total_time",
"status"
];
});
EmployeeTimeSheetAdapter.method('getHeaders', function() {
return [
{ "sTitle": "ID" ,"bVisible":false},
{ "sTitle": "Start Date"},
{ "sTitle": "End Date"},
{ "sTitle": "Total Time"},
{ "sTitle": "Status"}
];
});
EmployeeTimeSheetAdapter.method('getFormFields', function() {
return [
[ "id", {"label":"ID","type":"hidden"}],
[ "date_start", {"label":"TimeSheet Start Date","type":"date","validation":""}],
[ "date_end", {"label":"TimeSheet End Date","type":"date","validation":""}],
[ "details", {"label":"Reason","type":"textarea","validation":"none"}]
];
});
EmployeeTimeSheetAdapter.method('preProcessTableData', function(row) {
row[1] = Date.parse(row[1]).toString('MMM d, yyyy (dddd)');
row[2] = Date.parse(row[2]).toString('MMM d, yyyy (dddd)');
return row;
});
EmployeeTimeSheetAdapter.method('renderForm', function(object) {
var formHtml = this.templates['formTemplate'];
var html = "";
$("#"+this.getTableName()+'Form').html(formHtml);
$("#"+this.getTableName()+'Form').show();
$("#"+this.getTableName()).hide();
$('#timesheet_start').html(Date.parse(object.date_start).toString('MMM d, yyyy (dddd)'));
$('#timesheet_end').html(Date.parse(object.date_end).toString('MMM d, yyyy (dddd)'));
this.currentTimesheet = object;
this.getTimeEntries();
});
EmployeeTimeSheetAdapter.method('openTimeEntryDialog', function() {
this.currentTimesheetId = this.currentId;
var obj = modJsList['tabEmployeeTimeEntry'];
$('#TimeEntryModel').modal({
backdrop: 'static',
keyboard: false
});
obj.currentTimesheet = this.currentTimesheet;
obj.renderForm();
obj.timesheetId = this.currentId;
});
EmployeeTimeSheetAdapter.method('closeTimeEntryDialog', function() {
$('#TimeEntryModel').modal('hide');
});
EmployeeTimeSheetAdapter.method('getTimeEntries', function() {
timesheetId = this.currentId;
var sourceMappingJson = JSON.stringify(modJsList['tabEmployeeTimeEntry'].getSourceMapping());
object = {"id":timesheetId,"sm":sourceMappingJson};
var reqJson = JSON.stringify(object);
var callBackData = [];
callBackData['callBackData'] = [];
callBackData['callBackSuccess'] = 'getTimeEntriesSuccessCallBack';
callBackData['callBackFail'] = 'getTimeEntriesFailCallBack';
this.customAction('getTimeEntries','modules=time_sheets',reqJson,callBackData);
});
EmployeeTimeSheetAdapter.method('getTimeEntriesSuccessCallBack', function(callBackData) {
var entries = callBackData;
var html = "";
var temp = '