X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=htdocs%2Fjavascript%2Fprofile.js;h=a173e4b96a2ef4208bedb4cb99f2aa55a0a3b237;hb=2d89ec936167033886ae76b153605d7ccf19bc20;hp=cafaba92b6af7c93bf90b248784d5beeb70e1acd;hpb=ed92ea696e042eb9b2d0efcc4731fdf89fb17924;p=platal.git
diff --git a/htdocs/javascript/profile.js b/htdocs/javascript/profile.js
index cafaba9..a173e4b 100644
--- a/htdocs/javascript/profile.js
+++ b/htdocs/javascript/profile.js
@@ -45,10 +45,8 @@ function wizPage_onLoad(id)
}
break;
case 'emploi':
- for (var i = 0 ; $('#job_' + i).length != 0; ++i) {
- updateJobSector(i, $('#job_' + i).find("[name='jobs[" + i + "][subSector]']").val());
- updateJobSubSector(i, $('#job_' + i).find("[name='jobs[" + i + "][subSubSector]']").val());
- updateJobAlternates(i);
+ if ($('#jobs_0').find("[name='jobs[0][name]']").val() == '') {
+ registerEnterpriseAutocomplete(0);
}
break;
}
@@ -60,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()
@@ -163,7 +167,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 += '';
}
+ // XXX: to be removed once SQL table profile_merge_issues is.
+ if (sel != '' && html == '') {
+ html += '';
+ }
$('.edu_' + id).find("[name='edus[" + id + "][degreeid]']").html(html);
}
@@ -320,20 +332,20 @@ function addressChanged(prefid)
function validGeoloc(prefid, id, geoloc)
{
if (geoloc == 1) {
- $('#' + prefid + '_cont').find('[name*=text]').val($('#' + prefid + '_cont').find('[name*=geoloc]').val());
- $('#' + prefid + '_cont').find('[name*=postalText]').val($('#' + prefid + '_cont').find('[name*=geocodedPostalText]').val());
+ $('#' + prefid + '_cont').find('[name*=text]').val($('#' + prefid + '_cont').find('[name*=geocodedText]').val());
+ $('#' + prefid + '_cont').find('[name*=postalText]').val('');
}
if (geoloc > 0) {
- $('#' + prefid + '_cont').find("[name*='[geoloc]']").remove();
+ $('#' + prefid + '_cont').find("[name*='[geocodedText]']").remove();
}
$('#' + prefid + '_cont').find('[name*=text]').removeClass('error');
- $('#' + prefid + '_cont').find('[name*=geoloc_choice]').val(geoloc);
+ $('#' + 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 + '_';
@@ -341,7 +353,7 @@ function addTel(prefid, prefname)
i++;
}
$('#' + prefix + 'add').before('
');
- Ajax.update_html(prefix + i, 'profile/ajax/tel/' + prefid + '/' + prefname + '/' + i);
+ Ajax.update_html(prefix + i, 'profile/ajax/tel/' + prefid + '/' + prefname + '/' + i + '/' + subField + '/' + mainField + '/' + mainId);
}
function removeTel(prefname, prefid, id)
@@ -501,69 +513,152 @@ function restoreJob(id, pref)
$('#' + id).find("[name='" + pref + "[removed]']").val('0');
}
-function updateJobSector(id, sel)
+function makeAddJob(id)
{
- var sector = $('#job_' + id).find("[name='jobs[" + id + "][sector]']").val();
- if (sector == '') {
- sector = '-1';
- }
- Ajax.update_html('job_' + id + '_subSector', 'profile/ajax/sector/' + id + '/job_' + id + '/jobs[' + id + ']/' + sector + '/' + sel);
+ return function(data)
+ {
+ $('#add_job').before(data);
+ registerEnterpriseAutocomplete(id);
+ };
}
-function updateJobSubSector(id, sel)
+function addJob()
{
- var subSector = $('#job_' + id).find("[name='jobs[" + id + "][subSector]']").val();
- if (subSector == '') {
- subSector = '-1';
+ var i = 0;
+ while ($('#jobs_' + i).length != 0) {
+ ++i;
}
- Ajax.update_html('job_' + id + '_subSubSector', 'profile/ajax/sub_sector/' + id + '/' + subSector + '/' + sel);
+ $.get(platal_baseurl + 'profile/ajax/job/' + i, makeAddJob(i));
}
-function updateJobAlternates(id)
+function addEntreprise(id)
{
- var subSubSector = $('#job_' + id).find("[name='jobs[" + id + "][subSubSector]']").val();
- if (subSubSector != '') {
- Ajax.update_html('job_' + id + '_alternates', 'profile/ajax/alternates/' + id + '/' + subSubSector);
- }
+ $('.entreprise_' + id).toggle();
}
-function emptyJobSubSector(id)
-{
- Ajax.update_html('job_' + id + '_subSubSector', 'profile/ajax/sub_sector/' + id + '/-1/-1');
+/**
+ * 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 ce mot-clef retirer](images/icons/cross.gif)
'+
+ '
';
+ 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;
}
-function emptyJobAlternates(id)
+/**
+ * Remove a job term in job profile page.
+ * Must be called from a button in a div containing the term
+ */
+function removeJobTerm()
{
- Ajax.update_html('job_' + id + '_alternates', 'profile/ajax/alternates/' + id + '/-1');
+ $(this).parent().remove();
}
-function displayAllSector(id)
+/**
+ * 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)
{
- $('.sector_text_' + id).remove();
- $('.sector_' + id).show();
+ if (row[1] < 0) {
+ return '... parcourir les résultats dans un arbre ...';
+ }
+ return row[0];
}
-function makeAddJob(id)
+/**
+ * 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)
{
- return function(data)
- {
- $('#add_job').before(data);
- registerEnterpriseAutocomplete(id);
- };
+ 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 addJob()
+/**
+ * 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)
{
- var i = 0;
- while ($('#job_' + i).length != 0) {
- ++i;
+ var treepath;
+ if (jobid < 0) {
+ treepath = '';
+ } else {
+ treepath = '#jobs_'+jobid+' ';
}
- $.get(platal_baseurl + 'profile/ajax/job/' + i, makeAddJob(i));
+ 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 addEntreprise(id)
+/**
+ * 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)
{
- $('.entreprise_' + id).toggle();
+ addJobTerm(treeid.replace(/^job(.*)$/, '$1'), jtid, fullname);
}
// {{{1 Skills
@@ -597,58 +692,6 @@ function addCountry()
updateElement('countries');
}
-function updateSubSector()
-{
- var s = $('#sectorSelection').find('[name=sectorSelection]').val();
- var ss = $('#subSectorSelection').find("[name='jobs[-1][subSector]']").val();
- if ((s == '' || ss == '') || $('#sectors_' + s + '_' + ss).length != 0) {
- $('#addSector').hide();
- } else {
- $('#addSector').show();
- }
-}
-
-function removeSector(s, ss)
-{
- $('#sectors_' + s + '_' + ss).remove();
- updateSubSector();
-}
-
-function updateSector()
-{
- var sector = $('#sectorSelection').find('[name=sectorSelection]').val();
- if (sector == '') {
- sector = '-1';
- $('#subSectorSelection').html('');
- return;
- }
- $.get(platal_baseurl + 'profile/ajax/sector/-1/0/0/' + sector,
- function(data) {
- data = ''
- + '
'
- + '' + data;
- $('#subSectorSelection').html(data);
- $('#subSectorSelection').find("[name='jobs[-1][subSector]']").change(updateSubSector);
- });
-}
-
-function addSector()
-{
- var s = $('#sectorSelection').find('[name=sectorSelection]').val();
- var ss = $('#subSectorSelection').find("[name='jobs[-1][subSector]']").val();
- var sst = $('#subSectorSelection').find("[name='jobs[-1][subSector]'] :selected").text();
-
- var html = '';
- $('#sectors').append(html);
- updateSubSector();
-}
-
function registerEnterpriseAutocomplete(id)
{
$(".enterpriseName").each(
@@ -696,4 +739,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: