var badges=[];
var global_models={};
var search_result=null;
var current_page_number=0;
$(function(){
getAllModels().done(function(models){
global_models=models;
for(var key in models) {
//console.log(key);
if(parseInt(key) >= 156 && parseInt(key) <= 175){
model=models[key];
//console.log(model);
var tot_basic=0;
badges[key]={};
$.each(model.groups, function(id2,group) {
//if(group.master_id==null) $('.sub_block_title_'+key).html(group.title+" ");
$.each(group.inputs, function(id3,input){
if(input.type!="9") return true;
//displayInput(".fields > .competences > .sub_block_content_"+key, input,".fields > .competences > .sub_block_content_"+key+" > .input#"+input.id);
if(typeof(badges[key])=="undefined") badges[key]={};
badges[key].name=""+model.name;
temp_groups=model.groups;
badges[key].badgeImage=""+model.groups[0].image;
if(input.badgeType=="0") tot_basic++;
if(typeof(badges[key].fields)=="undefined") badges[key].fields=[];
badges[key].fields.push({code:input.code,badgeType:input.badgeType,name:input.labels});
});
});
badges[key].tot_basic=tot_basic;
}
}
//console.log(badges);//badgeImage
displaySearchCurriculum();
});
});
function displaySearchCurriculum(){
var myProvincesList={};
var provinces_list={};
//recupero lista professioni
getProfessions().done(function(result){
$('#profession-list').append("
");
$.each(result.data,function(id,profession){
//
var new_profession=""+
" "+
""+profession.name+" "
"
";
$('#profession-list > .groups').append(new_profession);
});
$('#profession-list').find(".pro_selection").first().prop("checked",true);
});
getUser(ucode).done(function(result){
data=result.data;
myCities=data.cities;
//se l'utente del sistema ha almeno una città settata, devo recuperare la lista delle provincie attive
if(myCities.length>0){
$.each(myCities,function(id,elem){
myProvincesList[elem.province_slug]=1;
});
}
objectLength=Object.keys(myProvincesList).length;
//console.log(myProvincesList);
getProvinces().done(function(result){
$.each(result.data,function(id,province){
//console.log(province.slug);
if(objectLength==0 || typeof(myProvincesList[province.slug])!="undefined"){
provinces_list[province.slug]={slug:province.slug,name:province.name,cities:province.cities,tot:province.cities.length};
//console.log("prova");
}
});
//console.log(provinces_list);
/*$.each(result.data,function(id,province){
$(filter).append(""+province.name+" ")
});*/
if(objectLength==0) displayProvinces('#city-list',result,0);
else displayProvinces('#city-list',{data:provinces_list},0);
});
});
//anagrafica
data=global_models[151];
$.each(data.groups, function(id2,group){
$.each(group.inputs, function(id3,input){
displayInput(".registry", input,".fields .registry .input#"+input.id);
//console.log(input.type);
});
});
//lingue
data=global_models[152];
var tot_groups=Object.keys(data.groups).length;
//console.log("---->"+tot_groups);
$.each(data.groups, function(id2,group){
if(group.master_id!=null){
if(group.inputs[2].type==19) displayInputLanguage(group, group.inputs[2],'.languages .input#'+group.inputs[2].id);
}
});
//recupero modello professione
data=global_models[153];
$.each(data.groups, function(id2,group){
$.each(group.inputs, function(id3,input){
input.code=input.code;
displayInput(".professions", input,'.fields .professions .input#'+input.id);
});
});
//badge
for(i=156;i<173;i++){
data=badges[i];
//console.log(data);
var tot_basic=0;
$.each(data.fields,function(id,elem){
var input_text="";
$('.sub_block_content_'+i).append(input_text);
if(typeof(badges[i])=="undefined") badges[i]={};
if(elem.badgeType=="0") tot_basic++;
});
$('.sub_block_title_'+i).append(data.name+' ');
badges[i].tot_basic=tot_basic;
badges[i].name=""+data.name;
badges[i].image=""+data.badgeImage;
}
//recupero modello esperienze - quelle alla fine del curriculum
data=global_models[173];
$.each(data.groups, function(id2,group){
$.each(group.inputs, function(id3,input){
input.code=input.code;
displayInput(".experiences_1", input,'.fields .experiences_1 .input#'+input.id);
});
});
//recupero modello esperienze - quelle alla fine del curriculum
data=global_models[174];
$.each(data.groups, function(id2,group){
$.each(group.inputs, function(id3,input){
input.code=input.code;
displayInput(".experiences_2", input,'.fields .experiences_2 .input#'+input.id);
});
});
//recupero modello esperienze - quelle alla fine del curriculum
data=global_models[175];
$.each(data.groups, function(id2,group){
$.each(group.inputs, function(id3,input){
input.code=input.code;
displayInput(".experiences_3", input,'.fields .experiences_3 .input#'+input.id);
});
});
setSubTabAccordion();
setMainTabAccordion();
}
function searchCurricula(offset,limit,display_button_bar){
toggleDefaultLoader();
if(!display_button_bar) display_button_bar=1;
var professions=[];
var cities=[];
var fields=[];
var checkboxes={};
if(!limit) limit=main_limit;
if(!offset) offset=0;
//chiave valore per tutti gli input, da salvare in mongodb
$(".fields ").find("input, select").each(function(id,elem){
var icode = $(this).attr("code");
if(typeof icode !== typeof undefined && icode !== false){
if($(this).val()!=null) var ivalue = $(this).val();
else var ivalue="";
if(ivalue=="") return true;
if($(elem).attr("type")=="radio"){
if($(elem).prop("checked")==true){
fields.push({
key: icode,
value: $(elem).attr("value")
});
//console.log("-------");
//console.log(fields);
//return;
}
}else if($(elem).attr("type")=="checkbox"){
if($(elem).prop("checked")==true){
if(!checkboxes.hasOwnProperty(icode)) checkboxes[icode]="";
if(checkboxes[icode]!="") checkboxes[icode]+="," + $(elem).attr("value");
else checkboxes[icode]=$(elem).attr("value");
}else{
if(!checkboxes.hasOwnProperty(icode)) checkboxes[icode]="";
}
}else{
if($(elem).attr("type")!="file"){
fields.push({
key: icode,
value: ivalue
});
}
}
}
});
$.each(checkboxes,function(id,elem){
if(elem!=""){
fields.push({
key: id,
value: elem
});
}
});
//console.log(checkboxes);
//professioni
profession_id=$("input[name=profession]:checked").val();
if(profession_id!="") professions.push(profession_id);
//città
$("input.city_list").each(function(){
city_id=$(this).val();
cities.push(city_id);
});
var searchCurriculamData={
"professions": professions,
"cities": cities,
"fields": fields,
"offset": offset,
"limit": limit
};
//console.log(modelData);
//creo il modello
//var user_code=null;
//var create_deferred = this.request.Deferred();
//console.log(searchCurriculamData);
//return;
$.ajax({
url: remoteAPIurl+'/api/v1/profile/search?api_token='+token,
crossDomain: true,
type: "post",
data: searchCurriculamData,
dataType: 'json',
success: function(result, statusText, resObject){
$('#result-list').html("");
$('.panel-result').show();
search_result=result.data;
matches=[];
$.each(result.data.matches,function(id,elem){
matches[elem.user_code]=elem.tot_matches;
displayCurriculum(elem,profession_id);
});
functionName="searchCurricula";
//console.log("----->"+result.tot_unpaging_record);
if(display_button_bar==1) displayPagingBar(result.tot_unpaging_record,functionName);
scrollToElement('.panel.panel-result',$('.header-section').height(),400);
toggleDefaultLoader();
},
error: function() { console.log('error'); }
});
}
function getProfessions(){
var create_deferred = $.Deferred();
$.ajax({
url: remoteAPIurl+'/api/v1/profession?api_token='+token,
crossDomain: true,
type: "get",
dataType: 'json',
success: function(result, statusText, resObject){
create_deferred.resolve(result);
},
error: function() { console.log('error'); }
});
return create_deferred;
}
function displayGroups(groups,where){
$.each(groups, function(id2,group){
if(group.master_id==null){
var new_group="";
$(where+' > .groups').append(new_group);
}else{
var new_group="";
$('.group#'+group.master_id+" > .groups").append(new_group);
}
$.each(group.inputs, function(id3,input){
$('.group#'+group.id+" > .group_inputs").append("
");
displayInput(input,".input#"+input.id);
//console.log(input.type);
});
});
}
function displayCurriculum(cv_result,profession_id){
var matching_percent=cv_result.matching_percent;
//console.log(cv_result.postal_code);
if(cv_result.postal_code!="" && cv_result.postal_code!=undefined) var cap="CAP: "+cv_result.postal_code;
else var cap="CAP: Da impostare";
var avatar="../images/noUser.png";
if(typeof(cv_result.avatar) !== "undefined" && cv_result.avatar!=null && cv_result.avatar!="") avatar = cv_result.avatar;
cv_result=cv_result.curriculum_data[0];
var account_type=cv_result.curriculum['7w4h33fgh2ldw50f710qaibe0tsp1g48c8qgc5xt7j64p6kw8lnj3yy3rqts6x1i'];
if(account_type=="0") account_type="basic";
else if(account_type=="1") account_type="verified";
else if(account_type=="2") account_type="certified";
var name=cv_result.curriculum['e2ef524fbf3d9fe611d5a8e90fefdc9c63923f49e5241343aa7acb6a06a751e7'];
var surname=cv_result.curriculum['ac627ab1ccbdb62ec96e702f07f6425b20f07591c6fcb220ffe637cda29bb3f6'];
var description=cv_result.curriculum['i2x9xhqvuotzb7cg193kzwc8hk1r9udrwa1tsrpmgjlsqy9r8dc79pfq9hhicva8'];
if(description=="" || description==undefined) description="Descrizione: Da impostare ";
var code = cv_result.user_code;
//console.log(cv_result);
var cv_title="Candidato";
/*if(auto_join==1){
auto_join_text="Auto candidato
";
} */
//console.log(""+name+" - "+code+"
");
var result_block="";
result_block+="";
result_block+="
";
result_block+="
";
result_block+="
";
result_block+="
Referenze lavorative
";
result_block+="
";
result_block+="
";
result_block+="
";
$("#result-list").append(result_block);
displayBadges(cv_result);
//referenze
displayReferences(cv_result,profession_id,code);
displayCCNL(cv_result,profession_id,code);
displayWorkStatus(cv_result,profession_id,code);
//console.log(matches[code]);
var order=parseInt(matches[code]);
$(".single-result-"+code).css("order",order);
$(".single-result-"+code).css("-webkit-order",order);
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
function displayReferences(data, profession_id, user_code){
var div_master=$(".single-result-"+user_code+" .result-references");
var model=global_models[154];
var mainFilter="";
//var counter_master=0;
for(var i=0;i<3;i++){ //per iterare sulla i-esima esperienza(composta da base + conferma)
div_master.append("
");
var tot_inputs=0;
$.each(model.groups, function(id2,group){ //per iterare sulla base e conferma
//console.log(mainFilter);
if(group.master_id==null) div_master.find(".reference_"+i).append(""+group.title+" "+(i+1)+"
");
$.each(group.inputs, function(id3,input){
//console.log(input.code);
var input_values=[];
if(input.values!="" && typeof(input.values)!="undefined") input_values=input.values.split("#@#");
//console.log(input_code);
//console.log(input_values);
var input_labels=[""];
if(input.labels!="" && typeof(input.labels)!="undefined") input_labels=input.labels.split("#@#");
var input_texts=[];
if(input.texts!="" && typeof(input.texts)!="undefined") input_texts=input.texts.split("#@#");
var input_placeholder=input.placeholder;
input_type=input.type;
if(input.code=="t81p00pqr0gm4f5klnnpw9py2dramhdfpf5qguh7vxuzc0kyn7ojgeijs9ueq7ug" || input.code=="bd4c9ab730f5513206b999ec0d90d1fb04025959b191f8f9de3f924f0940515f"){
//primo campo di conferma referenza
div_master.find(".reference_"+i).append("-----------------------------------------------------------------------
");
}
var curriculum_value="";
if(typeof(data.curriculum[input.code+"P"+profession_id+"E"+i])!="undefined" && data.curriculum[input.code+"P"+profession_id+"E"+i]!=""){
curriculum_value=data.curriculum[input.code+"P"+profession_id+"E"+i];
//console.log("curriculum_value=");
//console.log(curriculum_value);
if(input_type==19) curriculum_value=input_texts[curriculum_value];
tot_inputs++;
}else{
curriculum_value="";
}
var input_text="";
if(input_type==2 || input_type==4 || input_type==11 || input_type==13){
input_text=""+input_labels[0]+" "+
""+curriculum_value+"
";
}else if(input_type==19){
input_text=""+input_labels[0]+" "+
""+curriculum_value+"
";
}
div_master.find(".reference_"+i).append(""+input_text+"
");
});
});
if(tot_inputs==0) div_master.find('.reference_'+i).hide();
}
}
//
function displayCCNL(data, profession_id, user_code){
var div_master=$(".single-result-"+user_code+" .result-ccnl-lvl");
/* console.log(profession_id);
console.log(user_code);
console.log(data);
console.log(data.curriculum["37a749d808e46495a8da1e5352d03caefe73f687e5bc5280214e0486b273a5f9P47P"+profession_id]);
console.log("");*/
var ccnl=parseInt(data.curriculum["37a749d808e46495a8da1e5352d03caefe73f687e5bc5280214e0486b273a5f9P"+
profession_id]);
var ccnl_string="";
if(ccnl==0){
ccnl_string="A";
}else if(ccnl==1){
ccnl_string="Asuper";
}else if(ccnl==2){
ccnl_string="B";
}else if(ccnl==3){
ccnl_string="Bsuper";
}else if(ccnl==4){
ccnl_string="C";
}else if(ccnl==5){
ccnl_string="Csuper";
}else if(ccnl==6){
ccnl_string="D";
}else if(ccnl==7){
ccnl_string="Dsuper";
}else{
ccnl_string="Da impostare";
}
div_master.html("Livello CCNL: "+ccnl_string);
}
function displayWorkStatus(data, profession_id, user_code){
var div_master=$(".single-result-"+user_code+" .result-work-state");
/* console.log(profession_id);
console.log(user_code);
console.log(data);
console.log(data.curriculum["37a749d808e46495a8da1e5352d03caefe73f687e5bc5280214e0486b273a5f9P47P"+profession_id]);
console.log("");*/
var work_state=parseInt(data.curriculum["2dx351dw1gl6clo8z186v936d5hlyw90974f8hbayxgai5ji6sp21t8fyp0xmaxw"]);
var work_state_string="";
if(work_state==0){
work_state_string="Disoccupato";
}else if(work_state==1){
work_state_string="Semi-occupato";
}else if(work_state==2){
work_state_string="Occupato";
}else{
work_state_string="Da impostare";
}
div_master.html("Stato occupazionale: "+work_state_string);
}
function displayBadges(data){
var user_code = data.user_code;
var curriculum_badges={};
var curriculum_badges_details={};
var main_filter='.single-result-'+user_code+' .result-badges';
var tot_badges=0;
//console.log("badges");
//console.log(badges);
for(i=156;i<173;i++){
badge=badges[i];
badge_name=badge.name;
badge_image=badge.image;
badge_tot_basic=badge.tot_basic;
badge_fields=badge.fields;
$.each(badge_fields,function(id,field){
if(typeof(curriculum_badges[i])=="undefined") curriculum_badges[i]=0;
if(typeof(data.curriculum[field.code])!=="undefined" && data.curriculum[field.code]=="1"){
if(typeof(curriculum_badges_details[i])=="undefined") curriculum_badges_details[i]={};
if(typeof(curriculum_badges_details[i].badgeImage)=="undefined") curriculum_badges_details[i].badgeImage=badge_image;
if(typeof(curriculum_badges_details[i].fields)=="undefined") curriculum_badges_details[i].fields=[];
//console.log(field.code+"--->"+field.badgeType);
if(field.badgeType=="0") curriculum_badges[i]++;
else if(field.badgeType=="1") curriculum_badges_details[i].fields.push({code:field.code,badgeType:field.badgeType,name:field.name});
}
});
//console.log("model i="+i+"--->");
//console.log(curriculum_badges);
//console.log(curriculum_badges[i]+"?=?"+badge_fields.length);
//controllo se il numero di skill flaggate a true di tipo basic è uguale al massimo, solo in questo caso accendo il badge
if(curriculum_badges[i]==badge_tot_basic){
displayBadge(user_code,badge);
tot_badges++;
}
}
if(tot_badges>0) $(main_filter).before("Lista badge
");
else $('.single-result-'+user_code).find(".toggle_profile").hide();
//console.log(curriculum_badges_details);
//$(main_filter).append('Mostra di più ');
$('.single-result-'+user_code).find(".toggle_profile").click(function(){
$(this).toggleClass("toggled");
var find_top=$(this).find(".glyphicon-triangle-top").length;
if(find_top==0){
$(this).find(".glyphicon").addClass("glyphicon-triangle-top");
$(this).find(".glyphicon").removeClass("glyphicon-triangle-bottom");
}else{
$(this).find(".glyphicon").removeClass("glyphicon-triangle-top");
$(this).find(".glyphicon").addClass("glyphicon-triangle-bottom");
}
//console.log(".toggle_profile");
if($(main_filter).parent().find('.result-block-title-hidden').is(":visible")){
$(main_filter).parent().find('.result-block-title-hidden').hide();
}else{
$(main_filter).parent().find('.result-block-title-hidden').fadeIn();
$(main_filter).parent().find('.result-block-title-hidden').css("display","flex");
}
if($(main_filter).parent().find('.result-badges-details').is(":visible")){
$(main_filter).parent().find('.result-badges-details').hide();
}else{
$(main_filter).parent().find('.result-badges-details').fadeIn();
$(main_filter).parent().find('.result-block-title-hidden').css("display","flex");
}
if($(main_filter).parent().find('.result-references').is(":visible")){
$(main_filter).parent().find('.result-references').hide();
}else{
$(main_filter).parent().find('.result-references').fadeIn();
$(main_filter).parent().find('.result-block-title-hidden').css("display","flex");
}
});
displayBadgePlus(user_code,curriculum_badges_details);
}
function displayBadgePlus(user_code,plus){
var tot_badge_plus=0;
$.each(plus,function(id,badge){
//console.log(badge);
if(badge.fields.length==0) return true;
tot_badge_plus++;
$('.single-result-'+user_code+' .result-badges-details').append('
');
badge_image=badge.badgeImage;
if(typeof(badge_image)=="undefined" || badge_image=="") badge_image="badge/badge_icon.png";
$('.single-result-'+user_code+' .single-badge-details-'+id).append(" ");
$.each(badge.fields,function(id2,skill_plus){
$('.single-result-'+user_code+' .single-badge-details-'+id).append(""+skill_plus.name+"
");
});
});
if(tot_badge_plus>0) $('.single-result-'+user_code+' .result-badges-details').before("Lista skill plus
");
else $('.single-result-'+user_code+' .result-badges-details').hide();
}
function displayBadge(user_code,badge){
badge_name=badge.name;
badge_image=badge.image;
if(typeof(badge_image)=="undefined" || badge_image=="") badge_image="badge/badge_icon.png";
$('.single-result-'+user_code+' .result-badges').append("");
}
function getAllModels(){
var create_deferred = $.Deferred();
$.ajax({
url: remoteAPIurl+'/api/v1/model?api_token='+token,
crossDomain: true,
type: "get",
dataType: 'json',
success: function(result, statusText, resObject){
var models=[];
$.each(result.data,function(id,elem){
models[parseInt(elem.id)]=elem;
});
//console.log(models);
create_deferred.resolve(models);
},
error: function() { console.log('error'); }
});
return create_deferred;
}
function selectAll(elem){
//ho cliccato il checbox mentre era già cliccato
if(!$(elem).prop('checked')){
//console.log("Non è selezionato");
//deseleziono tutto
$(elem).parent().next(".sub_block_content").find("input[type=radio][value=0]").prop("checked",true);
}else{
//console.log("è selezionato");
$(elem).parent().next(".sub_block_content").find("input[type=radio][value=1]").prop("checked",true);
}
}
function displayInput(parent,input,where){
var input_type=input.type;
var input_id=input.id;
var input_code=input.code;
if(input_type==2 || input_type==4 || input_type==11 || input_type==13 || input_type==0 || input_type==9 || input_type==20 || input_type==19){
$(parent).append("
");
var where=$(where);
}else{
return;
}
var input_values=[];
if(input.values!="" && typeof(input.values)!="undefined") input_values=input.values.split("#@#");
//console.log(input_code);
//console.log(input_values);
var input_labels=[""];
if(input.labels!="" && typeof(input.labels)!="undefined") input_labels=input.labels.split("#@#");
var input_texts=[];
if(input.texts!="" && typeof(input.texts)!="undefined") input_texts=input.texts.split("#@#");
var input_placeholder=input.placeholder;
if(input_type==2 || input_type==4 || input_type==11 || input_type==13){
if(input_type==2) sub_type="date";
else if(input_type==4) sub_type="email";
else if(input_type==11) sub_type="tel";
else if(input_type==13) sub_type="text";
where.append(""+input_labels[0]+" "+
"
"+
"");
}else if(input_type==0 || input_type==9 || input_type==20){
if(input_type==0 || input_type==20) sub_type="radio"; //prima era checkbox
else sub_type="radio";
var input_text="";
input_text+=""+input_labels[0]+" ";
input_text+="";
var counter=0;
var input_name="inputs["+input_id+"]";
//console.log("------ "+input_code+" -------");
$.each(input_values,function(id,elem){
//if(input_type==0 || input_type==20) input_name="inputs["+input_id+"]["+counter+"]";
//console.log(input_values[counter]);
input_text+="
";
counter++;
});
input_text+="
";
where.append(input_text);
}else if(input_type==19){
var input_text="";
input_text+=""+input_labels[0]+" ";
input_text+="";
input_text+="";
input_text+=""+input_placeholder+" ";
var counter=0;
$.each(input_values,function(id,elem){
input_text+=""+input_texts[counter]+" ";
counter++;
});
input_text+="
";
where.append(input_text);
}
}
function displayInputLanguage(group,input,where){
var new_group=""+group.title+"
";
new_group+="
";
new_group+="
";
$('.languages > .groups').append(new_group);
$('.box_language#'+group.id+" .group_inputs").append("
");
var where=$(where);
input_type=input.type;
input_id=input.id;
input_code=input.code;
var input_values=[];
if(input.values!="" && typeof(input.values)!="undefined") input_values=input.values.split("#@#");
var input_labels=[""];
if(input.labels!="" && typeof(input.labels)!="undefined") input_labels=input.labels.split("#@#");
var input_texts=[];
if(input.texts!="" && typeof(input.texts)!="undefined") input_texts=input.texts.split("#@#");
var input_placeholder=input.placeholder;
if(input_type==19){
//console.log("OK");
var input_text="";
input_text+="";
input_text+=""+input_placeholder+" ";
var counter=0;
$.each(input_values,function(id,elem){
input_text+=""+input_texts[counter]+" ";
counter++;
});
input_text+=" ";
where.append(input_text);
}
}
function setMainTabAccordion(){
$(function() {
$('.block_content').hide();
//$('.block_title:first').addClass("active");
$('.block_title').click(function() {
var elem=this;
if(!$(elem).hasClass("active")){
$(".block_title").removeClass("active");
$(elem).addClass("active");
$('.block_content').slideUp('slow');
$(elem).next('.block_content').slideDown('slow',function(){
$('html, body').animate({
scrollTop: $(elem).offset().top - 50
}, 1000);
});
}else{
$(elem).removeClass("active");
$(elem).next('.block_content').slideUp('slow',function(){
$('html, body').animate({
scrollTop: $(elem).offset().top + 50
}, 1000);
});
}
});
});
}
function setSubTabAccordion(){
$(function() {
$('.sub_block_content:not(:first)').hide();
$('.sub_block_title:first').addClass("active");
$('.sub_block_title').click(function(e) {
//console.log("click")
if(e.target != this){
//console.log("is not "+e.target);
return;
}
var elem=this;
if(!$(elem).hasClass("active")){
$(".sub_block_title").removeClass("active");
$(elem).addClass("active");
$('.sub_block_content').slideUp('slow');
$(elem).next('.sub_block_content').slideDown('slow',function(){
$('html, body').animate({
scrollTop: $(elem).offset().top - 50
}, 1000);
});
}else{
$(elem).removeClass("active");
$(elem).next('.sub_block_content').slideUp('slow',function(){
$('html, body').animate({
scrollTop: $(elem).offset().top + 50
}, 1000);
});
}
});
/*$(".active_checkbox").click(function(e) {
return false;
});*/
});
}