/* 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 = '_start__end__duration__project__details_'; for(var i=0;i'; html = html.replace(/_id_/g,id); html = html.replace(/_BASE_/g,this.baseUrl); html = html.replace(/_status_/g,data[3]); return html; }); SubEmployeeTimeSheetAdapter.method('getCustomTableParams', function() { var that = this; var dataTableParams = { "aoColumnDefs": [ { "fnRender": function(data, cell){ return that.preProcessRemoteTableData(data, cell, 2) } , "aTargets": [2] }, { "fnRender": function(data, cell){ return that.preProcessRemoteTableData(data, cell, 3) } , "aTargets": [3] }, { "fnRender": that.getActionButtons, "aTargets": [that.getDataMapping().length] } ] }; return dataTableParams; }); /** * EmployeeTimeEntryAdapter */ function EmployeeTimeEntryAdapter(endPoint,tab,filter,orderBy) { this.initAdapter(endPoint,tab,filter,orderBy); } EmployeeTimeEntryAdapter.inherits(AdapterBase); this.timesheetId = null; this.currentTimesheet = null; this.allProjectsAllowed = 1; this.employeeProjects = []; EmployeeTimeEntryAdapter.method('getDataMapping', function() { return [ "id", "project", "date_start", "time_start", "date_end", "time_end", "details" ]; }); EmployeeTimeEntryAdapter.method('getHeaders', function() { return [ { "sTitle": "ID" ,"bVisible":false}, { "sTitle": "Project"}, { "sTitle": "Start Date"}, { "sTitle": "Start Time"}, { "sTitle": "End Date"}, { "sTitle": "End Time"}, { "sTitle": "Details"} ]; }); EmployeeTimeEntryAdapter.method('getFormFields', function() { return [ [ "id", {"label":"ID","type":"hidden"}], [ "project", {"label":"Project","type":"select2","allow-null":false,"remote-source":["Project","id","name","getEmployeeProjects"]}], [ "date_select", {"label":"Date","type":"select","source":[]}], [ "date_start", {"label":"Start Time","type":"time","validation":""}], [ "date_end", {"label":"End Time","type":"time","validation":""}], [ "details", {"label":"Details","type":"textarea","validation":""}] ]; }); /* EmployeeTimeEntryAdapter.method('renderForm', function(object) { var formHtml = this.templates['orig_formTemplate']; formHtml = formHtml.replace(/modJs/g,"modJsList['tabEmployeeTimeEntry']"); var html = ""; var fields = this.getFormFields(); for(var i=0;i'+datesArray[i].toString("d-MMM-yyyy")+''; optionList += ''; } formHtml = formHtml.replace(/_id_/g,this.getTableName()+"_submit"); formHtml = formHtml.replace(/_fields_/g,html); $("#"+this.getTableName()+'Form').html(formHtml); $("#"+this.getTableName()+'Form').show(); $("#"+this.getTableName()).hide(); $("#"+this.getTableName()+'Form .datefield').datepicker({'viewMode':2}); $("#"+this.getTableName()+'Form .datetimefield').datetimepicker({ language: 'en' }); $("#"+this.getTableName()+'Form .timefield').datetimepicker({ language: 'en', pickDate: false }); $("#"+this.getTableName()+'Form .select2Field').select2(); $("#date_select").html(optionList); /* var projectOptionList = ""; projectOptionList += ''; if(this.allProjectsAllowed == 0){ for(var i=0;i'+this.employeeProjects[i].name+''; } }else{ for(var i=0;i'+this.employeeProjects[i].name+''; } } $("#project").html(projectOptionList); */ if(object != undefined && object != null){ this.fillForm(object); } }); EmployeeTimeEntryAdapter.method('cancel', function() { $('#TimeEntryModel').modal('hide'); }); EmployeeTimeEntryAdapter.method('setAllProjectsAllowed', function(allProjectsAllowed) { this.allProjectsAllowed = allProjectsAllowed; }); EmployeeTimeEntryAdapter.method('setEmployeeProjects', function(employeeProjects) { this.employeeProjects = employeeProjects; }); /* EmployeeTimeEntryAdapter.method('save', function() { var validator = new FormValidation(this.getTableName()+"_submit",true,{'ShowPopup':false,"LabelErrorClass":"error"}); if(validator.checkValues()){ var params = validator.getFormParameters(); params.date_end = params.date_start; $(params).attr('timesheet',this.timesheetId); if(params.time_start.indexOf("am") != -1 && params.time_start.indexOf("12:") != -1){ params.time_start = params.time_start.replace("12:","00:"); } if(params.time_end.indexOf("am") != -1 && params.time_end.indexOf("12:") != -1){ params.time_end = params.time_end.replace("12:","00:"); } params.date_start = Date.parse(params.date_start+" "+params.time_start.replace('am',' AM').replace('pm',' PM')).toString("yyyy-MM-dd HH:mm:ss"); params.date_end = Date.parse(params.date_end+" "+params.time_end.replace('am',' AM').replace('pm',' PM')).toString("yyyy-MM-dd HH:mm:ss"); var msg = this.doCustomValidation(params); if(msg == null){ var id = $('#'+this.getTableName()+"_submit #id").val(); if(id != null && id != undefined && id != ""){ $(params).attr('id',id); } this.add(params,[]); this.cancel(); }else{ $("#"+this.getTableName()+'Form .label').html(msg); $("#"+this.getTableName()+'Form .label').show(); } } }); */ EmployeeTimeEntryAdapter.method('save', function() { var validator = new FormValidation(this.getTableName()+"_submit",true,{'ShowPopup':false,"LabelErrorClass":"error"}); if(validator.checkValues()){ var params = validator.getFormParameters(); $(params).attr('timesheet',this.timesheetId); params.time_start = params.date_start; params.time_end = params.date_end; params.date_start = params.date_select+" "+params.date_start; params.date_end = params.date_select+" "+params.date_end; var msg = this.doCustomValidation(params); if(msg == null){ var id = $('#'+this.getTableName()+"_submit #id").val(); if(id != null && id != undefined && id != ""){ $(params).attr('id',id); } this.add(params,[]); this.cancel(); }else{ $("#"+this.getTableName()+'Form .label').html(msg); $("#"+this.getTableName()+'Form .label').show(); } } }); EmployeeTimeEntryAdapter.method('doCustomValidation', function(params) { var st = Date.parse(params.date_start); var et = Date.parse(params.date_end); if(st.compareTo(et) != -1){ return "Start time should be less than End time"; } /* var sd = Date.parse(this.currentTimesheet.date_start); var ed = Date.parse(this.currentTimesheet.date_end).addDays(1); if(sd.compareTo(et) != -1 || sd.compareTo(st) > 0 || st.compareTo(ed) != -1 || et.compareTo(ed) != -1){ return "Start time and end time shoud be with in " + sd.toString('MMM d, yyyy (dddd)') + " and " + ed.toString('MMM d, yyyy (dddd)'); } */ return null; }); EmployeeTimeEntryAdapter.method('addSuccessCallBack', function(callBackData,serverData) { this.get(callBackData); modJs.getTimeEntries(); }); EmployeeTimeEntryAdapter.method('deleteRow', function(id) { this.deleteObj(id,[]); }); EmployeeTimeEntryAdapter.method('deleteSuccessCallBack', function(callBackData,serverData) { modJs.getTimeEntries(); });