var temporalAccount = {
organizationId:0,
showTemporalAccountsTable:function(orgId){
temporalAccount.organizationId=orgId;
organization.currentEmployeeStatus = "active";
var html="";
html+=''+
'
'+
''+
''+
'Filter by:
'+
'
'+
'
'+
''+
'';
var labelHeader = 'Temporal accounts
';
$("#definePeople").html(labelHeader + html);
organization.currentEmployeeStatus="all";
temporalAccount.includeTemporalAccountsTable(orgId);
},
includeTemporalAccountsTable:function(orgId){
var hash = generateHash();
includeComponent("#temporalAccountsTable",PATH_HTML_TEMPORAL_ACCOUNTS_GRID()+'?organizationId='+orgId,function(){
});
},
iniDataTableTemporalAccounts:function(orgId){
$('.selectPlanningstatus').show();
var url=PATH_SERVICE_GET_ALL_ORGANIZATION_TEMPORALACCOUNTS()+'?organizationId='+orgId+'&status='+organization.currentEmployeeStatus;
var table = $("#temporalAccountsTrack").DataTable({
"stripeClasses": [],
"orderClasses": false,
"destroy": true,
"autoWidth": true,
"paging": true,
"pagingType" : "full_numbers",
"pageLength": 10,
"lengthMenu": [1, 5, 10, 20, 50, 100],
"searching": true,
"ordering": true,
"language": {
"processing": "Processing...",
"search": "Search:",
"lengthMenu": "Show _MENU_ rows",
"info": "Showing _START_ to _END_ of _TOTAL_ rows",
"infoEmpty": "Showing 0 to 0 of 0 rows",
"infoFiltered": "(filtered _MAX_ filtered)",
"infoPostFix": "",
"loadingRecords": "Loading...",
"zeroRecords": "Not found",
"emptyTable": "No results",
paginate: {
"first": "First",
"previous": "Previous",
"next": "Next",
"last": "Last"
}
},
"info": true,
"columnDefs": [
{
"data":"id",
"orderable":false,
"searchable":false,
"targets":0,
"createdCell": function(td, cellData, rowData, row, col) {
if (rowData["status"] == 1) {
$(td).addClass('hide-checkboxes');
}
},
"checkboxes": {
"selectRow": true
}
},{"className": "text-left", "targets": [1, 2, 3, 4, 6]}
],
retrieve : true,
"select": {
style: 'multi',
selector: 'td:first-child'
},
"columns": [
{ "data": "id"},
{
"data": null,
render: function (data, type, row) {
return ""+convertDate(data.creationDate,CURRENT_LOCALE)+"";
}
},
{ "data": "userKey"},
{ "data": "password"},
{
"data": null,
render: function (data, type, row) {
if(data.status==1){
return ""+data.userName+" "+data.userLastName+"";
}else{
return ""+data.userName+" "+data.userLastName+"";
}
}
},
{
"data": null,
render: function (data, type, row) {
if(data.status==0){
return "Pending";
}else{
return "Used";
}
}
},
{
"data": null,
render: function (data, type, row) {
if(data.status==1){
return ""+convertDate(data.useDate,CURRENT_LOCALE)+"";
}else{
return " ";
}
}
},
],
"createdRow": function( row, data, dataIndex){
$(row).attr('id', data.id);
if( data.status == 0 ){
$(row).addClass('trBlockedEmployee');
}
},
"order": [[ 1, "desc" ]],
"processing": true,
"serverSide": true,
"ajax":url
});
$('.dt-checkboxes-select-all input[type="checkbox"]').on('change', function(){
temporalAccount.showEditButton("HIDE");
if(this.checked){
temporalAccount.showDeleteButton("SHOW");
} else{
temporalAccount.showDeleteButton("HIDE");
}
});
$('#temporalAccountsTrack').on('click', 'input[type="checkbox"]', function() {
temporalAccount.showEditButton("HIDE");
temporalAccount.showDeleteButton("HIDE");
if (this.checked){
temporalAccount.showDeleteButton("SHOW");
if($('.selected').length == 0){
temporalAccount.showEditButton("SHOW");
}
}else{
if($('.selected').length == 1){
temporalAccount.showDeleteButton("HIDE");
temporalAccount.showEditButton("HIDE");
}
if($('.selected').length > 1){
temporalAccount.showDeleteButton("SHOW");
temporalAccount.showEditButton("HIDE");
}
if($('.selected').length == 0){
temporalAccount.showDeleteButton("HIDE");
temporalAccount.showEditButton("SHOW");
}
}
});
},
loadTemporalAccounts:function(){
var e = document.getElementById("temporalAccountStatusSelect");
var status = e.options[e.selectedIndex].value;
organization.currentEmployeeStatus = status;
temporalAccount.includeTemporalAccountsTable();
},
showDeleteButton:function(type){
if(type=="SHOW"){
$("#deleteButton").show();
}else if(type=="HIDE"){
$("#deleteButton").hide();
}
},
showEditButton:function(type){
if(type=="SHOW"){
$("#editButton").show();
}else if(type=="HIDE"){
$("#editButton").hide();
}
},
evtDeleteTemporalAccount:function(){
var temporalAccountIdsList;
var temporalAccountIdsString="";
var cont = 0;
$('.selected').each(function() {
cont = cont + 1;
temporalAccountIdsString=temporalAccountIdsString+this.id+",";
});
if(cont == 1){
confirmation("Are you sure you want to delete this temporal account?",function(){
var param={};
param.temporalAccountIds = temporalAccountIdsString;
showGenericLoading();
$.when(temporalAccount.deleteTemporalAccount(param)).then(function(data){
hideGenericLoading();
organization.includeTemporalAccounts();
},function(){
hideGenericLoading();
redirectToGenericError("temporalAccount.evtDeleteTemporalAccount()","We are sorry, an error occurred and failed to save your changes.",true);
});
},function(){
});
}else{
if(cont > 1){
confirmation("Are you sure you want to delete this temporal accounts?",function(){
var param={};
param.temporalAccountIds = temporalAccountIdsString;
showGenericLoading();
$.when(temporalAccount.deleteTemporalAccount(param)).then(function(data){
hideGenericLoading();
organization.includeTemporalAccounts();
},function(){
hideGenericLoading();
redirectToGenericError("temporalAccount.evtDeleteTemporalAccount()","We are sorry, an error occurred and failed to save your changes.",true);
});
},function(){
});
}else{
showMessage("You must select at least one person");
}
}
},
deleteTemporalAccount:function(param){
return requestService(PATH_SERVICE_DELETE_TEMPORAL_ACCOUNT(), param, "GET", true,
function(data) { }, function() {});
},
evtTemporalAccountEdit:function(accountId,orgId){
showGenericLoading();
$.fancybox.close();
excludeComponent("#temporalAccountEditPopup");
$("#content").append("");
$("#content").append("");
includeComponent("#temporalAccountEditPopup",PATH_JSP_TEMPORARLACCOUNT_EDIT()+"?organizationId="+orgId+"&accountId="+accountId,function(){
hideGenericLoading();
showFancyPopup("#temporalAccountEditPopupLink",function(){});
});
},
evtTemporalAccountEditPopup:function(){
var accountId;
$('.selected').each(function() {
accountId=this.id;
});
temporalAccount.evtTemporalAccountEdit(accountId,temporalAccount.organizationId);
},
evtEnabledUserKeyField:function(){
$('#divUserKey').hide();
$('#divUserKeyEdit').show();
},
evtCancelEditUserKey:function(){
$('#divUserKey').show();
$('#divUserKeyEdit').hide();
},
evtSaveEditUserKey:function(orgId){
var hash = generateHash();
var userKey = $("#userKey").val().trim();
$('#userKey').removeClass('error');
$('#messagesEditProfile').empty();
if( userKey != '' && userKey.length > 0 ){
var param = {};
param.accountId=$("#accountId").val();
param.orgId=orgId;
param.fieldValue=userKey;
param.fieldEdit='userKey';
showGenericLoading();
$.when(temporalAccount.editTemporalAccountData(param)).then(function(data){
if(hash == currentHash){
hideGenericLoading();
}
},function(){
if(hash == currentHash){
hideGenericLoading();
redirectToGenericError("organization.evtSaveEditUserKey(orgId)","We are sorry, an error occurred and failed to save your changes.",true);
}
});
}else{
$('#userKey').addClass('error');
var msjError = "The username must have at least 8 characters.
";
$('#messagesEditProfile').append(msjError);
}
},
evtEnabledPassTempField:function(){
$('#divPassTemp').hide();
$('#divPassTempEdit').show();
},
evtCancelEditPassTemp:function(){
$('#divPassTemp').show();
$('#divPassTempEdit').hide();
},
evtSaveEditPassTemp:function(orgId){
var hash = generateHash();
var passTemp = $("#passTemp").val().trim();
$('#passTemp').removeClass('error');
$('#messagesEditProfile').empty();
if( passTemp != '' && passTemp.length >= 8 ){
var param = {};
param.accountId=$("#accountId").val();
param.orgId=orgId;
param.fieldValue=passTemp;
param.fieldEdit='passTemp';
showGenericLoading();
$.when(temporalAccount.editTemporalAccountData(param)).then(function(data){
if(hash == currentHash){
hideGenericLoading();
}
},function(){
if(hash == currentHash){
hideGenericLoading();
redirectToGenericError("organization.evtSaveEditPassTemp(orgId)","We are sorry, an error occurred and failed to save your changes.",true);
}
});
}else{
$('#passTemp').addClass('error');
var msjError = "The password must be at least 8 characters and max. 25.
";
$('#messagesEditProfile').append(msjError);
}
},
evtEnabledNameField:function(){
$('#divNameUser').hide();
$('#divNameUserEdit').show();
},
evtCancelEditName:function(){
$('#divNameUser').show();
$('#divNameUserEdit').hide();
},
evtSaveEditName:function(orgId){
var hash = generateHash();
var userName = $("#userName").val().trim();
$('#userName').removeClass('error');
$('#messagesEditProfile').empty();
if( userName != '' && userName.length > 0 ){
var param = {};
param.accountId=$("#accountId").val();
param.orgId=orgId;
param.fieldValue=userName;
param.fieldEdit='userName';
showGenericLoading();
$.when(temporalAccount.editTemporalAccountData(param)).then(function(data){
if(hash == currentHash){
hideGenericLoading();
}
},function(){
if(hash == currentHash){
hideGenericLoading();
redirectToGenericError("organization.evtSaveEditName(orgId)","We are sorry, an error occurred and failed to save your changes.",true);
}
});
}else{
$('#userName').addClass('error');
var msjError = "The first name must have at least one character.
";
$('#messagesEditProfile').append(msjError);
}
},
evtEnabledLastNameField:function(){
$('#divLastName').hide();
$('#divLastNameEdit').show();
},
evtCancelEditLastName:function(){
$('#divLastName').show();
$('#divLastNameEdit').hide();
},
evtSaveEditLastName:function(orgId){
var hash = generateHash();
var lastName = $("#lastName").val().trim();
$('#lastName').removeClass('error');
$('#messagesEditProfile').empty();
if( lastName != '' && lastName.length > 0 ){
var param = {};
param.accountId=$("#accountId").val();
param.orgId=orgId;
param.fieldValue=lastName;
param.fieldEdit='lastName';
showGenericLoading();
$.when(temporalAccount.editTemporalAccountData(param)).then(function(data){
if(hash == currentHash){
hideGenericLoading();
}
},function(){
if(hash == currentHash){
hideGenericLoading();
redirectToGenericError("organization.evtSaveEditLastName(orgId)","We are sorry, an error occurred and failed to save your changes.",true);
}
});
}else{
$('#lastName').addClass('error');
var msjError = "The last name must have at least one character.
";
$('#messagesEditProfile').append(msjError);
}
},
evtEnabledEditLanguage:function(){
$('#divLanguage').hide();
$('#divLanguageEdit').show();
},
evtCancelEditLanguage:function(){
$('#divLanguage').show();
$('#divLanguageEdit').hide();
},
evtEnabledEditArea:function(){
$('#divArea').hide();
$('#divAreaEdit').show();
},
evtCancelEditArea:function(){
$('#divArea').show();
$('#divAreaEdit').hide();
},
evtEnabledEditRole:function(){
$('#divRole').hide();
$('#divRoleEdit').show();
},
evtCancelEditRole:function(){
$('#divRole').show();
$('#divRoleEdit').hide();
},
evtSaveEditLanguage:function(orgId){
var hash = generateHash();
var language = $('#languageCmb option:selected').val();
$('#languageCmb').removeClass('error');
$('#messagesEditProfile').empty();
if( language != '' ){
var param = {};
param.accountId=$("#accountId").val();
param.orgId=orgId;
param.fieldValue=language;
param.fieldEdit='language';
showGenericLoading();
$.when(temporalAccount.editTemporalAccountData(param)).then(function(data){
if(hash == currentHash){
hideGenericLoading();
}
},function(){
if(hash == currentHash){
hideGenericLoading();
redirectToGenericError("organization.evtSaveEditLanguage(orgId)","We are sorry, an error occurred and failed to save your changes.",true);
}
});
}else{
$('#languageCmb').addClass('error');
var msjError = "Select an language
";
$('#messagesEditProfile').append(msjError);
}
},
evtSaveEditArea:function(orgId){
var hash = generateHash();
var area = $('#areaCmb option:selected').val();
$('#areaCmb').removeClass('error');
$('#messagesEditProfile').empty();
if( area != '' ){
var param = {};
param.accountId=$("#accountId").val();
param.orgId=orgId;
param.fieldValue=area;
param.fieldEdit='area';
showGenericLoading();
$.when(temporalAccount.editTemporalAccountData(param)).then(function(data){
if(hash == currentHash){
hideGenericLoading();
}
},function(){
if(hash == currentHash){
hideGenericLoading();
redirectToGenericError("organization.evtSaveEditArea(orgId)","We are sorry, an error occurred and failed to save your changes.",true);
}
});
}else{
$('#areaCmb').addClass('error');
var msjError = "Select an area
";
$('#messagesEditProfile').append(msjError);
}
},
evtSaveEditRole:function(orgId){
var hash = generateHash();
var role = $('#roleCmb option:selected').val();
$('#roleCmb').removeClass('error');
$('#messagesEditProfile').empty();
if( role != '' ){
var param = {};
param.accountId=$("#accountId").val();
param.orgId=orgId;
param.fieldValue=role;
param.fieldEdit='role';
showGenericLoading();
$.when(temporalAccount.editTemporalAccountData(param)).then(function(data){
if(hash == currentHash){
hideGenericLoading();
}
},function(){
if(hash == currentHash){
hideGenericLoading();
redirectToGenericError("organization.evtSaveEditRole(orgId)","We are sorry, an error occurred and failed to save your changes.",true);
}
});
}else{
$('#roleCmb').addClass('error');
var msjError = "Select a role
";
$('#messagesEditProfile').append(msjError);
}
},
evtEnabledEditCountry:function(){
$('#divCountry').hide();
$('#divCountryEdit').show();
},
evtCancelEditCountry:function(){
$('#divCountry').show();
$('#divCountryEdit').hide();
},
evtSaveEditCountry:function(orgId){
var hash = generateHash();
var country = $('#countryCmb option:selected').val();
$('#countryCmb').removeClass('error');
$('#messagesEditProfile').empty();
if( country != '' ){
var param = {};
param.accountId=$("#accountId").val();
param.orgId=orgId;
param.fieldValue=country;
param.fieldEdit='country';
showGenericLoading();
$.when(temporalAccount.editTemporalAccountData(param)).then(function(data){
if(hash == currentHash){
hideGenericLoading();
}
},function(){
if(hash == currentHash){
hideGenericLoading();
redirectToGenericError("organization.evtSaveEditCountry(orgId)","We are sorry, an error occurred and failed to save your changes.",true);
}
});
}else{
$('#countryCmb').addClass('error');
var msjError = "Select an country
";
$('#messagesEditProfile').append(msjError);
}
},
editTemporalAccountData:function(param){
return requestService(PATH_SERVICE_EDIT_TEMPORARLACCOUNT_DATA(), param, "GET", true,
function(data) {
organization.includeTemporalAccounts();
}, function() {});
},
iniDataTableApprenticeInvitations:function(organizationId,labelAccept,courseId,status){
$('#apprTableIdo').DataTable().destroy();
var url=PATH_SERVICE_GET_PENDING_INVITATIONS()+'?organizationId='+organizationId+'&courseId='+courseId+'&status='+status;
var table = $("#apprTableIdo").DataTable({
"stripeClasses": [],
"orderClasses": false,
"destroy": true,
"autoWidth": true,
"paging": true,
"pagingType" : "full_numbers",
"pageLength": 10,
"lengthMenu": [1, 5, 10, 20, 50, 100],
"searching": true,
"ordering": true,
"language": {
"processing": "Processing...",
"search": "Search:",
"lengthMenu": "Show _MENU_ rows",
"info": "Showing _START_ to _END_ of _TOTAL_ rows",
"infoEmpty": "Showing 0 to 0 of 0 rows",
"infoFiltered": "(filtered _MAX_ filtered)",
"infoPostFix": "",
"loadingRecords": "Loading...",
"zeroRecords": "Not found",
"emptyTable": "No results",
paginate: {
"first": "First",
"previous": "Previous",
"next": "Next",
"last": "Last"
}
},
"info": true,
"columnDefs": [
{
"orderable":false,
"searchable":false,
"targets":3
},
{"className": "text-left", "targets": [0, 1, 2]}
],
retrieve : true,
"select": {
style: 'multi',
selector: 'td:first-child'
},
"columns": [
{ "data": "profileLogin"},
{
"data": null,
render: function (data, type, row) {
if(data.sentDate!=''){
return ""+convertDate(data.sentDate,CURRENT_LOCALE)+"";
}else{
return "";
}
}
},
{
"data": null,
render: function (data, type, row) {
if(data.acceptDate!=''){
return ""+convertDate(data.acceptDate,CURRENT_LOCALE)+"";
}else{
return "";
}
}
},
{ "data": null,
render: function (data, type, row) {
if(data.status == 1){
return labelAccept;
}else{
return "";
}
}
},
],
"order": [[ 1, "desc" ]],
"processing": true,
"serverSide": true,
"ajax":url
});
},
iniDataTableApprenticeInvitationsSpecialization:function(organizationId,labelAccept,specializationId,status){
$('#apprTableIdo').DataTable().destroy();
var url=PATH_SERVICE_GET_PENDING_INVITATIONS_SPECIALIZATIONS()+'?organizationId='+organizationId+'&specializationId='+specializationId+'&status='+status;
var table = $("#apprTableIdo").DataTable({
"stripeClasses": [],
"orderClasses": false,
"destroy": true,
"autoWidth": true,
"paging": true,
"pagingType" : "full_numbers",
"pageLength": 10,
"lengthMenu": [1, 5, 10, 20, 50, 100],
"searching": true,
"ordering": true,
"language": {
"processing": "Processing...",
"search": "Search:",
"lengthMenu": "Show _MENU_ rows",
"info": "Showing _START_ to _END_ of _TOTAL_ rows",
"infoEmpty": "Showing 0 to 0 of 0 rows",
"infoFiltered": "(filtered _MAX_ filtered)",
"infoPostFix": "",
"loadingRecords": "Loading...",
"zeroRecords": "Not found",
"emptyTable": "No results",
paginate: {
"first": "First",
"previous": "Previous",
"next": "Next",
"last": "Last"
}
},
"info": true,
"columnDefs": [
{
"orderable":false,
"searchable":false,
"targets":3
},
{"className": "text-left", "targets": [0, 1, 2]}
],
retrieve : true,
"select": {
style: 'multi',
selector: 'td:first-child'
},
"columns": [
{ "data": "profileLogin"},
{
"data": null,
render: function (data, type, row) {
if(data.sentDate!=''){
return ""+convertDate(data.sentDate,CURRENT_LOCALE)+"";
}else{
return "";
}
}
},
{
"data": null,
render: function (data, type, row) {
if(data.acceptDate!=''){
return ""+convertDate(data.acceptDate,CURRENT_LOCALE)+"";
}else{
return "";
}
}
},
{ "data": null,
render: function (data, type, row) {
if(data.status == 1){
return labelAccept;
}else{
return "";
}
}
},
],
"order": [[ 1, "desc" ]],
"processing": true,
"serverSide": true,
"ajax":url
});
},
evtSaveEditPass:function(orgId,profileId,newPassword){
var currentPass = newPassword.trim();
var param={};
param.newPassword= currentPass;
param.profilePassId= profileId;
param.orgId= orgId;
requestService(PATH_SERVICE_EDIT_PASS(), param, "GET", true,
function(data) {
if(data.responseInfoJSON.responseCode==1){
$.fancybox.close();
showMessage($.i18n._("changePassword.label.success"));
}
}, function() {
});
},
evtHabilitarCampoPass:function(){
$('#divPass').hide();
$('#divPassEdit').show();
},
evtCancelEditPass:function(){
$('#divPass').show();
$('#divPassEdit').hide();
},
showChangePassword: function(organizationId,profileId) {
$("#changePasswordEmployee").remove();
$("#changePasswordEmployeeLink").remove();
$("#content").append("");
$("#content").append("");
excludeComponent("#changePasswordEmployee");
includeComponent("#changePasswordEmployee", PATH_HTML_CHANGEPASSWORDEMPLOYEE()+"?organizationId="+organizationId+"&profileId="+profileId,
function() {
showFancyPopup("#changePasswordEmployeeLink", function() {
});
});
}
};