X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=htdocs%2Fjavascript%2Fprofile.js;h=f0ca309b4487c23c9c9bbdabb4f389b93e3fe95e;hb=63c891790bd2fe0fd5319908cbeafee7e06a5a3b;hp=690c1bac4eeed9a12a96392458e71a858d095c59;hpb=89cb2025f5f2aed0be3994c89ac473aa11535853;p=platal.git diff --git a/htdocs/javascript/profile.js b/htdocs/javascript/profile.js index 690c1ba..f0ca309 100644 --- a/htdocs/javascript/profile.js +++ b/htdocs/javascript/profile.js @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2003-2009 Polytechnique.org * + * Copyright (C) 2003-2011 Polytechnique.org * * http://opensource.polytechnique.org/ * * * * This program is free software; you can redistribute it and/or modify * @@ -45,9 +45,8 @@ function wizPage_onLoad(id) } break; case 'emploi': - for (var i = 0 ; $('#job_' + i).length != 0; ++i) { - updateJobSector(i, $('#job_' + i).find("[name*='[ss_secteur]']").val()); - updateJobSubSector(i, $('#job_' + i).find("[name*='[sss_secteur]']").val()); + if ($('#jobs_0').find("[name='jobs[0][name]']").val() == '') { + registerEnterpriseAutocomplete(0); } break; } @@ -59,6 +58,12 @@ var educationDegreeName; var subgrades; var names; +// Publicity follows the following ordering: private < ax < public. +var publicity = []; +publicity['private'] = 0; +publicity['ax'] = 1; +publicity['public'] = 2; + // Names {{{1 function toggleNamesAdvanced() @@ -66,22 +71,24 @@ function toggleNamesAdvanced() $('.names_advanced').toggle(); } -function addSearchName() +function addSearchName(isFemale) { var i = 0; while ($('#search_name_' + i).length != 0) { i++; } - Ajax.update_html('search_name_' + i, 'profile/ajax/searchname/' + i, function(data){ - $('#searchname').before(data); - changeNameFlag(i); - }); + $('#search_name_' + i) + .updateHtml('profile/ajax/searchname/' + i + '/' + isFemale, + function(data) { + $('#searchname').before(data); + changeNameFlag(i); + }); } -function removeSearchName(i) +function removeSearchName(i, isFemale) { $('#search_name_' + i).remove(); - updateNameDisplay(); + updateNameDisplay(isFemale); } function changeNameFlag(i) @@ -103,7 +110,7 @@ function changeNameFlag(i) } } -function updateNameDisplay() +function updateNameDisplay(isFemale) { var searchnames = ''; for (var i = 0; i < 10; i++) { @@ -112,30 +119,47 @@ function updateNameDisplay() searchnames += $('#search_name_' + i).find(':text').val() + ';;'; } } - Ajax.update_html(null, 'profile/ajax/buildnames/' + searchnames, function(data){ - var name = data.split(';'); - $('#public_name').html(name[0]); - $('#private_name').html(name[0] + name[1]); - }); + $.xget('profile/ajax/buildnames/' + searchnames + '/' + isFemale, + function(data){ + var name = data.split(';'); + $('#public_name').html(name[0]); + $('#private_name').html(name[0] + name[1]); + }); +} + +function toggleParticle(id) +{ + if ($('#search_name_' + id).find("[name*='[particle]']").val() == '') { + $('#search_name_' + id).find("[name*='[particle]']").val(1); + } else { + $('#search_name_' + id).find("[name*='[particle]']").val(''); + } +} + +// Promotions {{{1 + +function togglePromotionEdition() +{ + $(".promotion_edition").toggle(); } // Nationalities {{{1 function delNationality(i) { - $('#nationalite' + i).hide().find('select').val(''); + $('#nationality' + i).hide().find('select').val(''); } function addNationality() { var i = 0; - if ($('#nationalite2').find('select').val() == "") { + if ($('#nationality2').find('select').val() == "") { i = 2; - } else if ($('#nationalite3').find('select').val() == "") { + } else if ($('#nationality3').find('select').val() == "") { i = 3; } if ((i == 2) || (i == 3)) { - $('#nationalite' + i).show(); + $('#nationality' + i).show(); } } @@ -146,7 +170,11 @@ function prepareType(id) var edu = $('.edu_' + id).find("[name='edus[" + id + "][eduid]']").val() - 1; var sel = $('.edu_' + id).find('[name=edu_' + id + '_tmp]').val(); var html = ''; - var length = educationDegree[edu].length; + if (educationDegree[edu]) { + var length = educationDegree[edu].length; + } else { + var length = 0; + } for (i = 0; i < length; ++i) { html += ''; + } $('.edu_' + id).find("[name='edus[" + id + "][degreeid]']").html(html); } @@ -179,7 +211,7 @@ function addEdu() i++; $('#edu_add').addClass(prefix + i); i--; - $.get(platal_baseurl + 'profile/ajax/edu/' + i + '/' + class_parity, + $.xget('profile/ajax/edu/' + i + '/' + class_parity, function(data) { $('#edu_add').before(data); prepareType(i); @@ -292,28 +324,32 @@ function addAddress() i++; } $('#add_address').before('
'); - Ajax.update_html('addresses_' + i + '_cont', 'profile/ajax/address/' + i, checkCurrentAddress()); + $('#addresses_' + i + '_cont').updateHtml('profile/ajax/address/' + i, + checkCurrentAddress()); } -function addressChanged(id) +function addressChanged(prefid) { - $('#addresses_' + id + '_cont').find('[name*=changed]').val("1"); + $('#' + prefid + '_cont').find('[name*=changed]').val("1"); } -function validGeoloc(id, geoloc) +function validGeoloc(prefid, id, geoloc) { if (geoloc == 1) { - $('#addresses_' + id + '_cont').find('[name*=text]').val($('#addresses_' + id + '_cont').find('[name*=geoloc]').val()); - $('#addresses_' + id + '_cont').find('[name*=postalText]').val($('#addresses_' + id + '_cont').find('[name*=geocodedPostalText]').val()); + $('#' + prefid + '_cont').find('[name*=text]').val($('#' + prefid + '_cont').find('[name*=geocodedText]').val()); + $('#' + prefid + '_cont').find('[name*=postalText]').val(''); } - $('#addresses_' + id + '_cont').find('[name*=text]').removeClass('error'); - $('#addresses_' + id + '_cont').find('[name*=geoloc_choice]').val(geoloc); - $('.addresses_' + id + '_geoloc').remove(); + if (geoloc > 0) { + $('#' + prefid + '_cont').find("[name*='[geocodedText]']").remove(); + } + $('#' + prefid + '_cont').find('[name*=text]').removeClass('error'); + $('#' + prefid + '_cont').find('[name*=geocodeChosen]').val(geoloc); + $('.' + prefid + '_geoloc').remove(); } // {{{1 Phones -function addTel(prefid, prefname) +function addTel(prefid, prefname, subField, mainField, mainId) { var i = 0; var prefix = prefid + '_'; @@ -321,25 +357,53 @@ function addTel(prefid, prefname) i++; } $('#' + prefix + 'add').before('
'); - Ajax.update_html(prefix + i, 'profile/ajax/tel/' + prefid + '/' + prefname + '/' + i); + $('#' + prefix + i).updateHtml('profile/ajax/tel/' + prefid + '/' + prefname + '/' + i + '/' + subField + '/' + mainField + '/' + mainId); } -function removeTel(id) +function removeTel(prefname, prefid, id) { - $('#' + id).remove(); + var total = 0; + while ($('#' + prefid + '_' + total).length != 0) { + ++total; + } + $('#' + prefid + '_' + id).remove(); + for (var i = parseInt(id) + 1; i < total; ++i) { + renumberPhone(prefname, prefid, i); + } } function addPhoneComment(id) { - $(id + '_comment').show(); - $(id + '_addComment').hide(); + $('#' + id + '_comment').show(); + $('#' + id + '_addComment').hide(); } function removePhoneComment(id, pref) { - $(id + '_comment').hide(); - $(id + '_comment').find("[name='" + pref + "[comment]']").val(''); - $(id + '_addComment').show(); + $('#' + id + '_comment').hide(); + $('#' + id + '_comment').find("[name='" + pref + "[comment]']").val(''); + $('#' + id + '_addComment').show(); +} + +function renumberPhone(prefname, prefid, i) +{ + var telid = i - 1; + var telprefOld = prefname + '[' + i + ']'; + var telpref = prefname + '[' + telid + ']'; + var idOld = prefid + '_' + i; + var id = prefid + '_' + telid; + + $('#' + idOld).attr('id', id); + $('#' + id).find('div.titre').html('N°' + i); + $('#' + id).find('a.removeTel').attr('href', 'javascript:removeTel(\'' + prefname + '\',\'' + prefid + '\',' + telid + ')'); + $('#' + id).find('select').attr('name', telpref + '[type]'); + $('#' + id).find("[name='" + telprefOld + "[display]']").attr('name', telpref + '[display]'); + $('#' + id).find("[name='" + telprefOld + "[comment]']").attr('name', telpref + '[comment]'); + $('#' + id).find('a.removePhoneComment').attr('href', 'javascript:removePhoneComment(' + id + ',' + telpref + ')'); + $('#' + id).find('#' + idOld + '_addComment').attr('id', id + '_addComment'); + $('#' + id).find('#' + id + '_addComment').attr('href', 'javascript:addPhoneComment(' + id + ')'); + $('#' + id).find('#' + idOld + '_comment').attr('id', id + '_comment'); + $('#' + id).find("[name='" + telprefOld + "[pub]']").attr('name', telpref + '[pub]'); } // {{{1 Groups @@ -356,7 +420,7 @@ function addBinet() + '
' + text + '
' - + ' ' + + ' ' + ' cross' + ' ' + ' ' @@ -425,7 +489,7 @@ function makeAddProcess(id) function addMedal() { var id = $('#medals').find('[name=medal_sel]').val(); - $.get(platal_baseurl + 'profile/ajax/medal/' + id, makeAddProcess(id)); + $.xget('profile/ajax/medal/' + id, makeAddProcess(id)); } function removeMedal(id) @@ -439,42 +503,18 @@ function removeMedal(id) function removeJob(id, pref) { $('#' + id + '_cont').hide(); - if ($('#' + id).find("[name='" + id + "[new]']").val() == '0') { + if ($('#' + id).find("[name='" + pref + "[new]']").val() == '0') { $('#' + id + '_grayed').show(); - $('#' + id + '_grayed_name').html($('#' + id).find("[name='" + id + "[name]']").val()); + $('#' + id + '_grayed_name').html($('#' + id).find("[name='" + pref + "[name]']").val()); } - $('#' + id).find("[name='" + id + "[removed]']").val('1'); + $('#' + id).find("[name='" + pref + "[removed]']").val('1'); } function restoreJob(id, pref) { $('#' + id + '_cont').show(); $('#' + id + '_grayed').hide(); - $('#' + id).find("[name='" + id + "[removed]']").val('0'); -} - -function updateJobSector(id, sel) -{ - var sector = $('#job_' + id).find("[name*='[secteur]']").val(); - if (sector == '') { - sector = '-1'; - } - Ajax.update_html('job_' + id + '_ss_secteur', 'profile/ajax/secteur/' + id + '/job_' + id + '/jobs[' + id + ']/' + sector + '/' + sel); -} - -function updateJobSubSector(id, sel) -{ - var subSector = $('#job_' + id).find("[name*='[ss_secteur]']").val(); - if (subSector == '') { - subSector = '-1'; - } - Ajax.update_html('job_' + id + '_sss_secteur', 'profile/ajax/ssecteur/' + id + '/' + subSector + '/' + sel); -} - -function displayAllSector(id) -{ - $('.sector_text_' + id).remove(); - $('.sector_' + id).show(); + $('#' + id).find("[name='" + pref + "[removed]']").val('0'); } function makeAddJob(id) @@ -483,17 +523,16 @@ function makeAddJob(id) { $('#add_job').before(data); registerEnterpriseAutocomplete(id); - updateSector('job_' + id, 'jobs[' + id + ']', ''); }; } function addJob() { var i = 0; - while ($('#job_' + i).length != 0) { + while ($('#jobs_' + i).length != 0) { ++i; } - $.get(platal_baseurl + 'profile/ajax/job/' + i, makeAddJob(i)); + $.xget('profile/ajax/job/' + i, makeAddJob(i)); } function addEntreprise(id) @@ -501,13 +540,140 @@ function addEntreprise(id) $('.entreprise_' + id).toggle(); } +/** + * Adds a job term in job profile page + * @param jobid id of profile's job among his different jobs + * @param jtid id of job term to add + * @param full_name full text of job term + * @return false if the term already exist for this job, true otherwise + */ +function addJobTerm(jobid, jtid, full_name) +{ + var termid = 0; + var parentpath; + var formvarname; + if (jobid < 0) { + parentpath = ''; + jobid = ''; + formvarname = 'terms'; + } else { + parentpath = '#jobs_'+jobid+' '; + formvarname = 'jobs['+jobid+'][terms]'; + } + var lastJobTerm = $(parentpath + '.jobs_term:last'); + if (lastJobTerm.length != 0) { + termid = parseInt(lastJobTerm.children('input').attr('name').replace(/^(jobs\[[0-9]+\]\[terms\]|terms)\[([0-9]+)\]\[jtid\]/, '$2')) + 1; + if ($('#job'+jobid+'_term'+jtid).length > 0) { + return false; + } + } + var newdiv = '
'+ + ''+full_name+''+ + ''+ + 'retirer'+ + '
'; + if (lastJobTerm.length == 0) { + $(parentpath + '.jobs_terms').prepend(newdiv); + } else { + lastJobTerm.after(newdiv); + } + $('#job'+jobid+'_term'+jtid+' img').css('cursor','pointer').click(removeJobTerm); + return true; +} + +/** + * Remove a job term in job profile page. + * Must be called from a button in a div containing the term + */ +function removeJobTerm() +{ + $(this).parent().remove(); +} + +/** + * Prepare display for autocomplete suggestions in job terms + * @param row an array of (title of term, id of term) + * @return text to display + * If id is negative, it is because there are too much terms to + * be displayed. + */ +function displayJobTerm(row) +{ + if (row[1] < 0) { + return '... parcourir les résultats dans un arbre ...'; + } + return row[0]; +} + +/** + * Function called when a job term has been selected from autocompletion + * in search + * @param li is the list item (
  • ) that has been clicked + * The context is the jsquery autocomplete object. + */ +function selectJobTerm(li) +{ + var jobid = this.extraParams.jobid; + if (li.extra[0] >= 0) { + addJobTerm(jobid,li.extra[0],$(li).text()); + } + var search_input; + if (jobid < 0) { + search_input = $('.term_search')[0]; + } else { + search_input = $('#jobs_'+jobid+' .term_search')[0]; + } + if (li.extra[0] >= 0) { + search_input.value = ''; + search_input.focus(); + } else { + search_input.value = li.selectValue.replace(/%$/,''); + toggleJobTermsTree(jobid, li.selectValue); + } +} + +/** + * Function to show or hide a terms tree in job edition + * @param jobid is the id of the job currently edited + */ +function toggleJobTermsTree(jobid, textfilter) +{ + $('#term_tree_comment').toggle(); + + var treepath; + if (jobid < 0) { + treepath = ''; + } else { + treepath = '#jobs_'+jobid+' '; + } + treepath += '.term_tree'; + if ($(treepath + ' ul').length > 0) { + $(treepath).empty().removeClass().addClass('term_tree'); + if (!textfilter) { + return; + } + } + createJobTermsTree(treepath, 'profile/ajax/tree/jobterms/all', 'job' + jobid, 'chooseJobTerm', textfilter); +} + +/** + * Function called when a job term is chosen from terms tree + * @param treeid is the full id of the tree (must look like job3) + * @param jtid is the id of the job term chosen + * @param fullname is the complete name (understandable without context) of the term + */ +function chooseJobTerm(treeid, jtid, fullname) +{ + addJobTerm(treeid.replace(/^job(.*)$/, '$1'), jtid, fullname); +} + // {{{1 Skills function addSkill(cat) { var val = $('#' + cat + '_table').find('[name=' + cat + '_sel]').val(); var text = $('#' + cat + '_table').find('[name=' + cat + '_sel] :selected').text(); - $.get(platal_baseurl + 'profile/ajax/skill/' + cat + '/' + val, + $.xget('profile/ajax/skill/' + cat + '/' + val, function(data) { $('#' + cat).append(data); $('#' + cat + '_' + val + '_title').text(text); @@ -522,7 +688,7 @@ function addCountry() var val = $('#countries_table').find('[name=countries_sel] :selected').val(); var text = $('#countries_table').find('[name=countries_sel] :selected').text(); var html = '
    ' - + ' ' + + ' ' + ' ' + ' ' + '
    ' + text + '
    ' @@ -532,64 +698,12 @@ function addCountry() updateElement('countries'); } -function updateSubSector() -{ - var s = $('#secteur_sel').find('[name=secteur_sel]').val(); - var ss = $('#ss_secteur_sel').find("[name='jobs[-1][ss_secteur]']").val(); - if ((s == '' || ss == '') || $('#secteurs_' + s + '_' + ss).length != 0) { - $('#secteurs_add').hide(); - } else { - $('#secteurs_add').show(); - } -} - -function removeSector(s, ss) -{ - $('#secteurs_' + s + '_' + ss).remove(); - updateSubSector(); -} - -function updateSector() -{ - var secteur = $('#secteur_sel').find('[name=secteur_sel]').val(); - if (secteur == '') { - secteur = '-1'; - $('#ss_secteur_sel').html(''); - return; - } - $.get(platal_baseurl + 'profile/ajax/secteur/-1/0/0/' + secteur, - function(data) { - data = '' + data; - $('#ss_secteur_sel').html(data); - $('#ss_secteur_sel').find("[name='jobs[-1][ss_secteur]']").change(updateSubSector); - }); -} - -function addSector() -{ - var s = $('#secteur_sel').find('[name=secteur_sel]').val(); - var ss = $('#ss_secteur_sel').find("[name='jobs[-1][ss_secteur]']").val(); - var sst = $('#ss_secteur_sel').find("[name='jobs[-1][ss_secteur]'] :selected").text(); - - var html = '
    ' - + ' ' - + ' ' - + ' ' - + ' ' - + ' ' + sst - + '
    '; - $('#secteurs').append(html); - updateSubSector(); -} - function registerEnterpriseAutocomplete(id) { - $(".enterprise_name").each( + $(".enterpriseName").each( function() { if (id == -1 || this.name == "jobs[" + id + "][name]") { - $(this).autocomplete(platal_baseurl + "search/autocomplete/entreprise", + $(this).autocomplete($.plURL("search/autocomplete/entreprise"), { selectOnly:1, field:this.name, @@ -599,10 +713,10 @@ function registerEnterpriseAutocomplete(id) } }); - $(".sector_name").each( + $(".sectorName").each( function() { - if (id == -1 || this.name == "jobs[" + id + "][sss_secteur_name]") { - $(this).autocomplete(platal_baseurl + "search/autocomplete/sss_secteur", + if (id == -1 || this.name == "jobs[" + id + "][subSubSectorName]") { + $(this).autocomplete($.plURL("search/autocomplete/subSubSector"), { selectOnly:1, field:this.name, @@ -631,4 +745,42 @@ function removeElement(cat, id) updateElement(cat); } +function updateSubPublicity(subFieldId, name, mainPub) +{ + var subPub = $(subFieldId).find("[name='" + name + "']:checked").val(); + if (publicity[subPub] > publicity[mainPub]) { + $(subFieldId).find("[name='" + name + "']:checked").removeAttr('checked'); + $(subFieldId).find('[value=' + mainPub + ']').attr('checked', 'checked'); + } +} + +function updatePublicity(mainField, mainId, subField, subId) +{ + var mainFieldId = '#' + mainField + '_' + mainId; + var mainPub = $(mainFieldId).find("[name='" + mainField + "[" + mainId + "][pub]']:checked").val(); + if (subId == -1) { + var subFields = subField.split(','); + for (var i =0; i < subFields.length; ++i) { + var subFieldBaseId = mainFieldId + '_' + subFields[i]; + var name = mainField + '[' + mainId + '][' + subFields[i] + ']'; + if ($(subFieldBaseId).length != 0) { + updateSubPublicity(subFieldBaseId, name + '[pub]', mainPub); + updateSubPublicity(subFieldBaseId, mainField + '[' + mainId + '][' + subFields[i] + '_pub]', mainPub); + } + subId = 0; + while ($(subFieldBaseId + '_' + subId).length != 0) { + updateSubPublicity(subFieldBaseId + '_' + subId, name + '[' + subId + '][pub]', mainPub); + ++subId; + } + } + } else { + if (subId == '') { + updateSubPublicity(mainFieldId + '_' + subField, mainField + '[' + mainId + '][' + subField + '_pub]', mainPub); + updateSubPublicity(mainFieldId + '_' + subField, mainField + '[' + mainId + '][' + subField + '][pub]', mainPub); + } else { + updateSubPublicity(mainFieldId + '_' + subField + '_' + subId, mainField + '[' + mainId + '][' + subField + '][' + subId + '][pub]', mainPub); + } + } +} + // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: