/* 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 EmployeeAdapter(endPoint) { this.initAdapter(endPoint); this.fieldNameMap = {}; this.hiddenFields = {}; this.tableFields = {}; this.formOnlyFields = {}; this.customFields = []; } EmployeeAdapter.inherits(AdapterBase); this.currentUserId = null; EmployeeAdapter.method('setFieldNameMap', function(fields) { var field; for(var i=0;i 0) { var ct = '
'; var customFieldHtml; for (index in data.customFields) { if(!data.customFields[index][1]){ data.customFields[index][1] = 'Other Details'; } sectionId = data.customFields[index][1].toLocaleLowerCase(); sectionId = sectionId.replace(' ','_'); if($("#cont_"+sectionId).length <= 0){ //Add section sectionHtml = sectionTemplate; sectionHtml = sectionHtml.replace('#_section_#', sectionId); sectionHtml = sectionHtml.replace('#_section.name_#', data.customFields[index][1]); $("#customFieldsCont").append($(sectionHtml)); } customFieldHtml = ct; customFieldHtml = customFieldHtml.replace('#_label_#', index); customFieldHtml = customFieldHtml.replace('#_value_#', data.customFields[index][0]); $("#cont_"+sectionId).append($(customFieldHtml)); } }else{ $("#customFieldsCont").remove(); } $("#"+this.getTableName()+" #subordinates").html(subordinates); $("#"+this.getTableName()+" #name").html(data.first_name + " " + data.last_name); this.currentUserId = data.id; $("#"+this.getTableName()+" #profile_image_"+data.id).attr('src',data.image); if(this.checkPermission("Upload/Delete Profile Image") == "No"){ $("#employeeUploadProfileImage").remove(); $("#employeeDeleteProfileImage").remove(); } if(this.checkPermission("Edit Employee Details") == "No"){ $("#employeeProfileEditInfo").remove(); } if(currentEmpId != userEmpId){ $("#employeeUpdatePassword").remove(); } this.cancel(); }); EmployeeAdapter.method('modEmployeeGetFailCallBack' , function(data) { }); EmployeeAdapter.method('editEmployee' , function() { this.edit(this.currentUserId); }); EmployeeAdapter.method('changePassword', function() { $('#adminUsersModel').modal('show'); $('#adminUsersChangePwd #newpwd').val(''); $('#adminUsersChangePwd #conpwd').val(''); }); EmployeeAdapter.method('changePasswordConfirm', function() { $('#adminUsersChangePwd_error').hide(); var passwordValidation = function (str) { var val = /^[a-zA-Z0-9]\w{6,}$/; return str != null && val.test(str); }; var password = $('#adminUsersChangePwd #newpwd').val(); if(!passwordValidation(password)){ $('#adminUsersChangePwd_error').html("Password may contain only letters, numbers and should be longer than 6 characters"); $('#adminUsersChangePwd_error').show(); return; } var conPassword = $('#adminUsersChangePwd #conpwd').val(); if(conPassword != password){ $('#adminUsersChangePwd_error').html("Passwords don't match"); $('#adminUsersChangePwd_error').show(); return; } var req = {"pwd":conPassword}; var reqJson = JSON.stringify(req); var callBackData = []; callBackData['callBackData'] = []; callBackData['callBackSuccess'] = 'changePasswordSuccessCallBack'; callBackData['callBackFail'] = 'changePasswordFailCallBack'; this.customAction('changePassword','modules=employees',reqJson,callBackData); }); EmployeeAdapter.method('closeChangePassword', function() { $('#adminUsersModel').modal('hide'); }); EmployeeAdapter.method('changePasswordSuccessCallBack', function(callBackData,serverData) { this.closeChangePassword(); this.showMessage("Password Change","Password changed successfully"); }); EmployeeAdapter.method('changePasswordFailCallBack', function(callBackData,serverData) { this.closeChangePassword(); this.showMessage("Error",callBackData); }); /* * Company Graph */ function CompanyStructureAdapter(endPoint) { this.initAdapter(endPoint); } CompanyStructureAdapter.inherits(AdapterBase); CompanyStructureAdapter.method('getDataMapping', function() { return [ "id", "title", "address", "type", "country", "parent" ]; }); CompanyStructureAdapter.method('getHeaders', function() { return [ { "sTitle": "ID","bVisible":false }, { "sTitle": "Name" }, { "sTitle": "Address"}, { "sTitle": "Type"}, { "sTitle": "Country", "sClass": "center" }, { "sTitle": "Parent Structure"} ]; }); CompanyStructureAdapter.method('getFormFields', function() { return [ [ "id", {"label":"ID","type":"hidden","validation":""}], [ "title", {"label":"Name","type":"text","validation":""}], [ "description", {"label":"Details","type":"textarea","validation":""}], [ "address", {"label":"Address","type":"textarea","validation":"none"}], [ "type", {"label":"Type","type":"select","source":[["Company","Company"],["Head Office","Head Office"],["Regional Office","Regional Office"],["Department","Department"],["Unit","Unit"],["Sub Unit","Sub Unit"],["Other","Other"]]}], [ "country", {"label":"Country","type":"select","remote-source":["Country","code","name"]}], [ "parent", {"label":"Parent Structure","type":"select","allow-null":true,"remote-source":["CompanyStructure","id","title"]}] ]; }); function CompanyGraphAdapter(endPoint) { this.initAdapter(endPoint); this.nodeIdCounter = 0; } CompanyGraphAdapter.inherits(CompanyStructureAdapter); CompanyGraphAdapter.method('convertToTree', function(data) { var ice = {}; ice['id'] = -1; ice['title'] = ''; ice['name'] = ''; ice['children'] = []; var parent = null; var added = {}; for(var i=0;i"; obj.parent = null; break; } parentIdArr[parent.id] = 1; curObj = parent; } } if(errorMsg != ""){ this.showMessage("Company Structure is having a cyclic dependency","We found a cyclic dependency due to following reasons:
"+errorMsg); return false; } return true; });