Replace sectors by job terms in profile and search (job and mentoring).
[platal.git] / htdocs / javascript / profile.js
CommitLineData
46ae38a9 1/***************************************************************************
9f5bd98e 2 * Copyright (C) 2003-2010 Polytechnique.org *
46ae38a9
FB
3 * http://opensource.polytechnique.org/ *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., *
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19 ***************************************************************************/
20
8c7ac79e 21// Page initialization {{{1
46ae38a9
FB
22
23function wizPage_onLoad(id)
24{
25 switch (id) {
26 case 'general':
6505acf7
SJ
27 var i = 1;
28 while ($('.edu_' + i).length != 0) {
29 prepareType(i - 1);
30 ++i;
043bbacf 31 }
46ae38a9 32 break;
041a5cec
SJ
33 case 'adresses':
34 checkCurrentAddress();
35 break;
46ae38a9 36 case 'poly':
6505acf7 37 updateGroupSubLink();
46ae38a9
FB
38 break;
39 case 'deco':
40 for (var i in names) {
6505acf7
SJ
41 if ($('#medal_' + i).length != 0) {
42 getMedalName(i);
43 buildGrade(i, $('#medal_' + i).find('[name*=medal_' + i + '_grade]').val());
46ae38a9
FB
44 }
45 }
46 break;
47 case 'emploi':
6505acf7 48 for (var i = 0 ; $('#job_' + i).length != 0; ++i) {
541e8d03 49 updateJobSector(i, $('#job_' + i).find("[name='jobs[" + i + "][subSector]']").val());
2992a284 50 updateJobSubSector(i, $('#job_' + i).find("[name='jobs[" + i + "][subSubSector]']").val());
07e72582 51 updateJobAlternates(i);
46ae38a9
FB
52 }
53 break;
54 }
55}
56
f711b03f
SJ
57var educationDegree;
58var educationDegreeAll;
59var educationDegreeName;
46ae38a9
FB
60var subgrades;
61var names;
8c7ac79e 62
8c7ac79e
SJ
63// Names {{{1
64
e1082e20 65function toggleNamesAdvanced()
6e32823c 66{
e1082e20 67 $('.names_advanced').toggle();
6e32823c
SJ
68}
69
04e200e0 70function addSearchName(isFemale)
b04882ff 71{
6e32823c
SJ
72 var i = 0;
73 while ($('#search_name_' + i).length != 0) {
74 i++;
75 }
04e200e0 76 Ajax.update_html('search_name_' + i, 'profile/ajax/searchname/' + i + '/' + isFemale, function(data){
6e32823c
SJ
77 $('#searchname').before(data);
78 changeNameFlag(i);
79 });
b04882ff 80}
46ae38a9 81
e8a7cf31 82function removeSearchName(i, isFemale)
b04882ff 83{
6e32823c 84 $('#search_name_' + i).remove();
e8a7cf31 85 updateNameDisplay(isFemale);
6e32823c
SJ
86}
87
88function changeNameFlag(i)
89{
90 $('#flag_' + i).remove();
91 var typeid = $('#search_name_' + i).find('select').val();
92 var type = $('#search_name_' + i).find('select :selected').text();
6505acf7 93 if ($('[name=sn_type_' + typeid + '_' + i + ']').val() > 0) {
6e32823c
SJ
94 $('#flag_cb_' + i).after('<span id="flag_' + i + '">&nbsp;' +
95 '<img src="images/icons/flag_green.gif" alt="site public" title="site public" />' +
96 '<input type="hidden" name="search_names[' + i + '][pub]" value="1"/>' +
97 '<input type="hidden" name="search_names[' + i + '][typeid]" value="' + typeid + '"/>' +
98 '<input type="hidden" name="search_names[' + i + '][type]" value="' + type + '"/></span>');
99 } else {
100 $('#flag_cb_' + i).after('<span id="flag_' + i + '">&nbsp;' +
101 '<img src="images/icons/flag_red.gif" alt="site privé" title="site privé" />' +
102 '<input type="hidden" name="search_names[' + i + '][typeid]" value="' + typeid + '"/>' +
103 '<input type="hidden" name="search_names[' + i + '][type]" value="' + type + '"/></span>');
104 }
105}
106
e8a7cf31 107function updateNameDisplay(isFemale)
6e32823c
SJ
108{
109 var searchnames = '';
110 for (var i = 0; i < 10; i++) {
111 if ($('#search_name_' + i).find(':text').val()) {
112 searchnames += $('#search_name_' + i).find('[name*=typeid]').val() + ';';
6e32823c
SJ
113 searchnames += $('#search_name_' + i).find(':text').val() + ';;';
114 }
115 }
e8a7cf31 116 Ajax.update_html(null, 'profile/ajax/buildnames/' + searchnames + '/' + isFemale, function(data){
6e32823c
SJ
117 var name = data.split(';');
118 $('#public_name').html(name[0]);
119 $('#private_name').html(name[0] + name[1]);
120 });
b04882ff 121}
46ae38a9 122
09f9ebea
SJ
123function toggleParticle(id)
124{
125 if ($('#search_name_' + id).find("[name*='[particle]']").val() == '') {
126 $('#search_name_' + id).find("[name*='[particle]']").val(1);
127 } else {
128 $('#search_name_' + id).find("[name*='[particle]']").val('');
129 }
130}
131
7e233317
SJ
132// Promotions {{{1
133
134function togglePromotionEdition()
135{
136 $(".promotion_edition").toggle();
137}
138
8c7ac79e
SJ
139// Nationalities {{{1
140
8450c2aa
SJ
141function delNationality(i)
142{
7996ae8c 143 $('#nationality' + i).hide().find('select').val('');
8450c2aa
SJ
144}
145
146function addNationality()
147{
148 var i = 0;
323b972d 149 if ($('#nationality2').find('select').val() == "") {
8450c2aa 150 i = 2;
323b972d 151 } else if ($('#nationality3').find('select').val() == "") {
8450c2aa
SJ
152 i = 3;
153 }
154 if ((i == 2) || (i == 3)) {
323b972d 155 $('#nationality' + i).show();
8450c2aa
SJ
156 }
157}
158
6505acf7
SJ
159// Education {{{1
160
161function prepareType(id)
162{
163 var edu = $('.edu_' + id).find("[name='edus[" + id + "][eduid]']").val() - 1;
164 var sel = $('.edu_' + id).find('[name=edu_' + id + '_tmp]').val();
165 var html = '';
166 var length = educationDegree[edu].length;
167 for (i = 0; i < length; ++i) {
168 html += '<option value="' + educationDegree[edu][i] + '"';
169 if (sel == educationDegree[edu][i]) {
170 html += ' selected="selected"';
171 }
172 html += '>' + educationDegreeName[educationDegree[edu][i] - 1] + '</option>';
173 }
174 $('.edu_' + id).find("[name='edus[" + id + "][degreeid]']").html(html);
175}
176
177function addEdu()
178{
179 var i = 0;
180 var j = 0;
181 var prefix = 'edu_';
182 var class_parity;
183
184 while (!$('#edu_add').hasClass(prefix + i)) {
185 if ($('.' + prefix + i).length != 0) {
186 j++;
187 }
188 i++;
189 }
190 if (j % 2) {
191 class_parity = 'pair';
192 } else {
193 class_parity = 'impair';
194 }
195 $('#edu_add').removeClass(prefix + i);
196 i++;
197 $('#edu_add').addClass(prefix + i);
198 i--;
199 $.get(platal_baseurl + 'profile/ajax/edu/' + i + '/' + class_parity,
200 function(data) {
201 $('#edu_add').before(data);
202 prepareType(i);
203 });
204}
205
206function removeEdu(i)
207{
208 var prefix = 'edu_';
209 $('.' + prefix + i).remove();
210 while (!$('#edu_add').hasClass(prefix + i)) {
211 $('.' + prefix + i).toggleClass('pair');
212 $('.' + prefix + i).toggleClass('impair');
213 i++;
214 }
215}
216
8c7ac79e
SJ
217// Networking {{{1
218
d1a2252a
GB
219function addNetworking()
220{
221 var i = 0;
6505acf7 222 while ($('#networking_' + i).length != 0) {
d1a2252a
GB
223 i++;
224 }
92c3f9e5 225 var namefirst = '';
d1a2252a 226 var html = '<tr id="networking_' + i + '">'
92c3f9e5
GB
227 + ' <td colspan="2">'
228 + ' <div style="float: left; width: 200px;">'
229 + ' <span class="flags">'
230 + ' <input type="checkbox" name="networking[' + i + '][pub]"/>'
231 + ' <img src="images/icons/flag_green.gif" alt="site public" title="site public">'
232 + ' </span>&nbsp;'
6505acf7 233 + ' <select name="networking[' + i + '][type]" onchange="javascript:updateNetworking(' + i + ');">';
92c3f9e5
GB
234 for (nw in nw_list) {
235 if (namefirst == '') {
236 namefirst = nw;
237 }
238 html += ' <option value="' + nw_list[nw] + '">' + nw + '</option>';
239 }
240 html += '</select>'
6505acf7 241 + ' <input type="hidden" name="networking[' + i + '][name]" value="' + namefirst + '"/>'
92c3f9e5
GB
242 + ' </div>'
243 + ' <div style="float: left">'
244 + ' <input type="text" name="networking[' + i + '][address]" value="" size="30"/>'
245 + ' <a href="javascript:removeNetworking(' + i + ')">'
246 + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer cet élément"/>'
247 + ' </a>'
248 + ' </div>'
d1a2252a
GB
249 + ' </td>'
250 + '</tr>';
251
92c3f9e5 252 $('#networking').before(html);
d1a2252a
GB
253}
254
255function removeNetworking(id)
256{
257 $('#networking_' + id).remove();
258}
259
92c3f9e5 260function updateNetworking(i)
d1a2252a 261{
6505acf7 262 $('#networking_' + i).find("[name='networking[" + i + "][name]']").val($('#networking_' + i).find('select option:selected').text());
d1a2252a
GB
263}
264
8c7ac79e 265// Addresses {{{1
46ae38a9 266
041a5cec 267function toggleAddress(id, val)
46ae38a9 268{
041a5cec
SJ
269 $('#addresses_' + id + '_grayed').toggle();
270 $('#addresses_' + id).toggle();
271 $('#addresses_' + id + '_cont').find('[name*=removed]').val(val);
272 checkCurrentAddress();
46ae38a9
FB
273}
274
041a5cec 275function checkCurrentAddress(id)
46ae38a9 276{
041a5cec 277 var hasCurrentAddress = id ? true : false;
46ae38a9 278 var i = 0;
041a5cec
SJ
279 while ($('#addresses_' + i + '_cont').length != 0) {
280 if ($('#addresses_' + i + '_cont').find('[name*=removed]').val() == 1) {
281 $('#addresses_' + i + '_cont').find('[name*=current]').attr('checked', false);
282 }
283 if (!hasCurrentAddress && $('#addresses_' + i + '_cont').find('[name*=current]:checked').length != 0) {
284 hasCurrentAddress = true;
285 } else {
286 $('#addresses_' + i + '_cont').find('[name*=current]').attr('checked', false);
46ae38a9
FB
287 }
288 i++;
289 }
041a5cec 290 if (!hasCurrentAddress) {
46ae38a9 291 i = 0;
041a5cec
SJ
292 while ($('#addresses_' + i + '_cont').length != 0) {
293 if ($('#addresses_' + i + '_cont').find('[name*=removed]').val() == 0) {
294 $('#addresses_' + i + '_cont').find('[name*=current]').attr('checked', 'checked');
295 break;
296 }
297 i++;
46ae38a9
FB
298 }
299 }
041a5cec
SJ
300 if (id) {
301 $('#addresses_' + id + '_cont').find('[name*=current]').attr('checked', 'checked');
46ae38a9
FB
302 }
303}
304
46ae38a9
FB
305function addAddress()
306{
307 var i = 0;
041a5cec 308 while ($('#addresses_' + i + '_cont').length != 0) {
46ae38a9
FB
309 i++;
310 }
041a5cec
SJ
311 $('#add_address').before('<div id="addresses_' + i + '_cont"></div>');
312 Ajax.update_html('addresses_' + i + '_cont', 'profile/ajax/address/' + i, checkCurrentAddress());
46ae38a9
FB
313}
314
541e8d03 315function addressChanged(prefid)
043bbacf 316{
541e8d03 317 $('#' + prefid + '_cont').find('[name*=changed]').val("1");
043bbacf
SJ
318}
319
541e8d03 320function validGeoloc(prefid, id, geoloc)
043bbacf 321{
041a5cec 322 if (geoloc == 1) {
541e8d03
SJ
323 $('#' + prefid + '_cont').find('[name*=text]').val($('#' + prefid + '_cont').find('[name*=geoloc]').val());
324 $('#' + prefid + '_cont').find('[name*=postalText]').val($('#' + prefid + '_cont').find('[name*=geocodedPostalText]').val());
041a5cec 325 }
5112531d 326 if (geoloc > 0) {
541e8d03 327 $('#' + prefid + '_cont').find("[name*='[geoloc]']").remove();
5112531d 328 }
541e8d03
SJ
329 $('#' + prefid + '_cont').find('[name*=text]').removeClass('error');
330 $('#' + prefid + '_cont').find('[name*=geoloc_choice]').val(geoloc);
331 $('.' + prefid + '_geoloc').remove();
043bbacf
SJ
332}
333
8c7ac79e
SJ
334// {{{1 Phones
335
bde2be3b 336function addTel(prefid, prefname)
46ae38a9
FB
337{
338 var i = 0;
bde2be3b 339 var prefix = prefid + '_';
6505acf7 340 while ($('#' + prefix + i).length != 0) {
46ae38a9
FB
341 i++;
342 }
bde2be3b
GB
343 $('#' + prefix + 'add').before('<div id="' + prefix + i + '" style="clear: both; padding-top: 4px; padding-bottom: 4px"></div>');
344 Ajax.update_html(prefix + i, 'profile/ajax/tel/' + prefid + '/' + prefname + '/' + i);
46ae38a9
FB
345}
346
c8023e61 347function removeTel(prefname, prefid, id)
bde2be3b 348{
ed01acac 349 var total = 0;
c8023e61 350 while ($('#' + prefid + '_' + total).length != 0) {
ed01acac
SJ
351 ++total;
352 }
c8023e61 353 $('#' + prefid + '_' + id).remove();
ed01acac 354 for (var i = parseInt(id) + 1; i < total; ++i) {
c8023e61 355 renumberPhone(prefname, prefid, i);
ed01acac 356 }
bde2be3b
GB
357}
358
6505acf7 359function addPhoneComment(id)
bde2be3b 360{
3cd815ca
SJ
361 $('#' + id + '_comment').show();
362 $('#' + id + '_addComment').hide();
bde2be3b
GB
363}
364
365function removePhoneComment(id, pref)
366{
3cd815ca
SJ
367 $('#' + id + '_comment').hide();
368 $('#' + id + '_comment').find("[name='" + pref + "[comment]']").val('');
369 $('#' + id + '_addComment').show();
bde2be3b 370}
46ae38a9 371
c8023e61 372function renumberPhone(prefname, prefid, i)
ed01acac
SJ
373{
374 var telid = i - 1;
c8023e61
SJ
375 var telprefOld = prefname + '[' + i + ']';
376 var telpref = prefname + '[' + telid + ']';
377 var idOld = prefid + '_' + i;
378 var id = prefid + '_' + telid;
379
380 $('#' + idOld).attr('id', id);
381 $('#' + id).find('div.titre').html('N°' + i);
382 $('#' + id).find('a.removeTel').attr('href', 'javascript:removeTel(\'' + prefname + '\',\'' + prefid + '\',' + telid + ')');
383 $('#' + id).find('select').attr('name', telpref + '[type]');
0b6c8b36 384 $('#' + id).find("[name='" + telprefOld + "[display]']").attr('name', telpref + '[display]');
c8023e61
SJ
385 $('#' + id).find("[name='" + telprefOld + "[comment]']").attr('name', telpref + '[comment]');
386 $('#' + id).find('a.removePhoneComment').attr('href', 'javascript:removePhoneComment(' + id + ',' + telpref + ')');
387 $('#' + id).find('#' + idOld + '_addComment').attr('id', id + '_addComment');
388 $('#' + id).find('#' + id + '_addComment').attr('href', 'javascript:addPhoneComment(' + id + ')');
389 $('#' + id).find('#' + idOld + '_comment').attr('id', id + '_comment');
390 $('#' + id).find("[name='" + telprefOld + "[pub]']").attr('name', telpref + '[pub]');
ed01acac
SJ
391}
392
6505acf7 393// {{{1 Groups
46ae38a9 394
6505acf7 395function addBinet()
46ae38a9 396{
6505acf7
SJ
397 var id = $('#binets_table').find('[name=binets_sel]').val();
398 var text = $('#binets_table').find('select option:selected').text();
399 var html = '<tr id="binets_' + id + '">'
400 + ' <td>'
401 + ' <input type="hidden" name="binets[' + id + ']" value="' + text + '" />'
402 + ' </td>'
403 + ' <td>'
404 + ' <div style="float: left; width: 70%">'
405 + text
406 + ' </div>'
9fce7016 407 + ' <a href="javascript:removeElement(\'binets\',' + id + ')">'
6505acf7
SJ
408 + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer ce groupe" />'
409 + ' </a>'
410 + ' </td>'
411 + '</tr>';
412 $('#binets_table').after(html);
413 updateElement('binets');
46ae38a9
FB
414}
415
6505acf7 416function updateGroupSubLink()
46ae38a9 417{
6505acf7
SJ
418 var href = $('[name*=groupesx_sub]').val() ? $('[name*=groupesx_sub]').val() : 'http://www.polytechnique.net';
419 $('#groupesx_sub').attr('href', href);
46ae38a9
FB
420}
421
6505acf7 422// {{{1 Medals
46ae38a9
FB
423
424function updateMedal()
425{
6505acf7
SJ
426 var val = $('#medals').find('[name*=medal_sel]').val();
427 if (val && ($('#medal_' + val).length == 0)) {
428 $('#medal_add').show();
46ae38a9 429 } else {
6505acf7 430 $('#medal_add').hide();
46ae38a9
FB
431 }
432}
433
434function getMedalName(id)
435{
6505acf7 436 $('#medal_name_' + id).html(names[id]);
46ae38a9
FB
437}
438
439function buildGrade(id, current)
440{
441 var grade;
442 var subg = subgrades[id];
443 var obj = $('#medal_grade_' + id);
444 if (!subg) {
445 obj.prepend('<input type="hidden" name="medals[' + id + '][grade]" value="0" />');
446 } else {
447 var html = 'Agrafe : <select name="medals[' + id + '][grade]">';
448 html += '<option value="0">Non précisée</option>';
449 for (grade = 0 ; grade < subg.length ; grade++) {
450 html += '<option value="' + subg[grade][0] + '"';
451 if (subg[grade][0] == current) {
452 html += ' selected="selected"';
453 }
454 html += '>' + subg[grade][1] + '</option>';
455 }
456
457 html += '</select>';
458 obj.prepend(html);
459 }
460}
461
462function makeAddProcess(id)
463{
464 return function(data)
465 {
466 $('#medals').after(data);
467 updateMedal();
468 getMedalName(id);
469 buildGrade(id, 0);
470 };
471}
472
473function addMedal()
474{
6505acf7 475 var id = $('#medals').find('[name=medal_sel]').val();
46ae38a9
FB
476 $.get(platal_baseurl + 'profile/ajax/medal/' + id, makeAddProcess(id));
477}
478
479function removeMedal(id)
480{
481 $("#medal_" + id).remove();
482 updateMedal();
483}
484
8c7ac79e 485// Jobs {{{1
46ae38a9
FB
486
487function removeJob(id, pref)
488{
6505acf7 489 $('#' + id + '_cont').hide();
00ca8c09 490 if ($('#' + id).find("[name='" + pref + "[new]']").val() == '0') {
6505acf7 491 $('#' + id + '_grayed').show();
00ca8c09 492 $('#' + id + '_grayed_name').html($('#' + id).find("[name='" + pref + "[name]']").val());
46ae38a9 493 }
00ca8c09 494 $('#' + id).find("[name='" + pref + "[removed]']").val('1');
46ae38a9
FB
495}
496
497function restoreJob(id, pref)
498{
6505acf7
SJ
499 $('#' + id + '_cont').show();
500 $('#' + id + '_grayed').hide();
00ca8c09 501 $('#' + id).find("[name='" + pref + "[removed]']").val('0');
46ae38a9
FB
502}
503
6505acf7 504function updateJobSector(id, sel)
46ae38a9 505{
541e8d03 506 var sector = $('#job_' + id).find("[name='jobs[" + id + "][sector]']").val();
6505acf7
SJ
507 if (sector == '') {
508 sector = '-1';
46ae38a9 509 }
541e8d03 510 Ajax.update_html('job_' + id + '_subSector', 'profile/ajax/sector/' + id + '/job_' + id + '/jobs[' + id + ']/' + sector + '/' + sel);
c7139c07
SJ
511}
512
6505acf7 513function updateJobSubSector(id, sel)
c7139c07 514{
541e8d03 515 var subSector = $('#job_' + id).find("[name='jobs[" + id + "][subSector]']").val();
6505acf7
SJ
516 if (subSector == '') {
517 subSector = '-1';
c7139c07 518 }
541e8d03 519 Ajax.update_html('job_' + id + '_subSubSector', 'profile/ajax/sub_sector/' + id + '/' + subSector + '/' + sel);
c7139c07
SJ
520}
521
07e72582
SJ
522function updateJobAlternates(id)
523{
524 var subSubSector = $('#job_' + id).find("[name='jobs[" + id + "][subSubSector]']").val();
525 if (subSubSector != '') {
526 Ajax.update_html('job_' + id + '_alternates', 'profile/ajax/alternates/' + id + '/' + subSubSector);
527 }
528}
529
4018b8ab
SJ
530function emptyJobSubSector(id)
531{
532 Ajax.update_html('job_' + id + '_subSubSector', 'profile/ajax/sub_sector/' + id + '/-1/-1');
533}
534
535function emptyJobAlternates(id)
536{
537 Ajax.update_html('job_' + id + '_alternates', 'profile/ajax/alternates/' + id + '/-1');
538}
539
b814a8b8 540function displayAllSector(id)
c7139c07 541{
b814a8b8
SJ
542 $('.sector_text_' + id).remove();
543 $('.sector_' + id).show();
46ae38a9
FB
544}
545
546function makeAddJob(id)
547{
548 return function(data)
549 {
550 $('#add_job').before(data);
16594a1a 551 registerEnterpriseAutocomplete(id);
46ae38a9
FB
552 };
553}
554
555function addJob()
556{
557 var i = 0;
6505acf7 558 while ($('#job_' + i).length != 0) {
46ae38a9
FB
559 ++i;
560 }
561 $.get(platal_baseurl + 'profile/ajax/job/' + i, makeAddJob(i));
562}
563
b814a8b8
SJ
564function addEntreprise(id)
565{
566 $('.entreprise_' + id).toggle();
567}
46ae38a9 568
3ac45f10
PC
569/**
570 * Adds a job term in job profile page
571 * @param jobid id of profile's job among his different jobs
572 * @param jtid id of job term to add
573 * @param full_name full text of job term
574 * @return false if the term already exist for this job, true otherwise
575 */
576function addJobTerm(jobid, jtid, full_name)
577{
578 var termid = 0;
579 var parentpath;
580 var formvarname;
581 if (jobid < 0) {
582 parentpath = '';
583 jobid = '';
584 formvarname = 'terms';
585 } else {
586 parentpath = '#job_'+jobid+' ';
587 formvarname = 'jobs['+jobid+'][terms]';
588 }
589 var lastJobTerm = $(parentpath + '.job_term:last');
590 if (lastJobTerm.length != 0) {
591 termid = parseInt(lastJobTerm.children('input').attr('name').replace(/^(jobs\[[0-9]+\]\[terms\]|terms)\[([0-9]+)\]\[jtid\]/, '$2')) + 1;
592 if ($('#job'+jobid+'_term'+jtid).length > 0) {
593 return false;
594 }
595 }
596 var newdiv = '<div class="job_term" id="job'+jobid+'_term'+jtid+'">'+
597 '<span>'+full_name+'</span>'+
598 '<input type="hidden" name="'+formvarname+'['+termid+'][jtid]" value="'+jtid+'" />'+
599 '<img title="Retirer ce mot-clef" alt="retirer" src="images/icons/cross.gif" />'+
600 '</div>';
601 if (lastJobTerm.length == 0) {
602 $(parentpath + '.job_terms').prepend(newdiv);
603 } else {
604 lastJobTerm.after(newdiv);
605 }
606 $('#job'+jobid+'_term'+jtid+' img').css('cursor','pointer').click(removeJobTerm);
607 return true;
608}
609
610/**
611 * Remove a job term in job profile page.
612 * Must be called from a button in a div containing the term
613 */
614function removeJobTerm()
615{
616 $(this).parent().remove();
617}
618
619/**
620 * Prepare display for autocomplete suggestions in job terms
621 * @param row an array of (title of term, id of term)
622 * @return text to display
623 * If id is negative, it is because there are too much terms to
624 * be displayed.
625 */
626function displayJobTerm(row)
627{
628 if (row[1] < 0) {
629 return '... <em>précise ta recherche</em> ...';
630 }
631 return row[0];
632}
633
634/**
635 * Function called when a job term has been selected from autocompletion
636 * in search
637 * @param li is the list item (<li>) that has been clicked
638 * The context is the jsquery autocomplete object.
639 */
640function selectJobTerm(li)
641{
642 if (li.extra[0] < 0) {
643 return;
644 }
645 var jobid = this.extraParams.jobid;
646 addJobTerm(jobid,li.extra[0],$(li).text());
647 var search_input;
648 if (jobid < 0) {
649 search_input = $('.term_search')[0];
650 } else {
651 search_input = $('#job_'+jobid+' .term_search')[0];
652 }
653 search_input.value = '';
654 search_input.focus();
655}
656
657/**
658 * Function to show or hide a terms tree in job edition
659 * @param jobid is the id of the job currently edited
660 */
661function toggleJobTermsTree(jobid)
662{
663 var treepath;
664 if (jobid < 0) {
665 treepath = '';
666 } else {
667 treepath = '#job_'+jobid+' ';
668 }
669 treepath += '.term_tree';
670 if ($(treepath + ' ul').length > 0) {
671 $(treepath).empty().removeClass().addClass('term_tree');
672 return;
673 }
674 createJobTermsTree(treepath, 'profile/ajax/tree/jobterms/all', 'job' + jobid, 'chooseJobTerm');
675}
676
677/**
678 * Function called when a job term is chosen from terms tree
679 * @param treeid is the full id of the tree (must look like job3)
680 * @param jtid is the id of the job term chosen
681 * @param fullname is the complete name (understandable without context) of the term
682 */
683function chooseJobTerm(treeid, jtid, fullname)
684{
685 addJobTerm(treeid.replace(/^job(.*)$/, '$1'), jtid, fullname);
686}
687
8c7ac79e 688// {{{1 Skills
46ae38a9 689
46ae38a9
FB
690function addSkill(cat)
691{
6505acf7
SJ
692 var val = $('#' + cat + '_table').find('[name=' + cat + '_sel]').val();
693 var text = $('#' + cat + '_table').find('[name=' + cat + '_sel] :selected').text();
46ae38a9
FB
694 $.get(platal_baseurl + 'profile/ajax/skill/' + cat + '/' + val,
695 function(data) {
6505acf7
SJ
696 $('#' + cat).append(data);
697 $('#' + cat + '_' + val + '_title').text(text);
698 updateElement(cat);
46ae38a9
FB
699 });
700}
701
6505acf7 702// {{{1 Mentor
46ae38a9
FB
703
704function addCountry()
705{
6505acf7
SJ
706 var val = $('#countries_table').find('[name=countries_sel] :selected').val();
707 var text = $('#countries_table').find('[name=countries_sel] :selected').text();
46ae38a9 708 var html = '<div id="countries_' + val + '" style="clear: both; margin-bottom: 0.7em">'
9fce7016 709 + ' <a href="javascript:removeElement(\'countries\',\'' + val + '\')" style="display: block; float:right">'
46ae38a9
FB
710 + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce pays" />'
711 + ' </a>'
1d414e12
PC
712 + ' <div style="float: left; width: 50%">' + text + '</div>'
713 + ' <input type="hidden" name="countries[' + val + ']" value="' + text + '" />'
46ae38a9
FB
714 + '</div>';
715 $('#countries').append(html);
6505acf7 716 updateElement('countries');
46ae38a9
FB
717}
718
6505acf7 719function updateSubSector()
46ae38a9 720{
541e8d03 721 var s = $('#sectorSelection').find('[name=sectorSelection]').val();
bdc3d2e9 722 var ss = $('#subSectorSelection').find("[name='jobs[-1][subSector]']").val();
541e8d03
SJ
723 if ((s == '' || ss == '') || $('#sectors_' + s + '_' + ss).length != 0) {
724 $('#addSector').hide();
6505acf7 725 } else {
541e8d03 726 $('#addSector').show();
6505acf7 727 }
46ae38a9 728}
6505acf7
SJ
729
730function removeSector(s, ss)
46ae38a9 731{
541e8d03 732 $('#sectors_' + s + '_' + ss).remove();
6505acf7 733 updateSubSector();
46ae38a9
FB
734}
735
6505acf7 736function updateSector()
46ae38a9 737{
541e8d03
SJ
738 var sector = $('#sectorSelection').find('[name=sectorSelection]').val();
739 if (sector == '') {
740 sector = '-1';
bdc3d2e9 741 $('#subSectorSelection').html('');
76a2858c 742 return;
46ae38a9 743 }
541e8d03 744 $.get(platal_baseurl + 'profile/ajax/sector/-1/0/0/' + sector,
46ae38a9 745 function(data) {
541e8d03 746 data = '<a href="javascript:addSector()" style="display: none; float: right" id="addSector">'
bdc3d2e9 747 + ' <img src="images/icons/add.gif" alt="Ajouter ce secteur" title="Ajouter ce secteur" />'
6505acf7 748 + '</a>' + data;
bdc3d2e9
SJ
749 $('#subSectorSelection').html(data);
750 $('#subSectorSelection').find("[name='jobs[-1][subSector]']").change(updateSubSector);
46ae38a9
FB
751 });
752}
753
6505acf7 754function addSector()
46ae38a9 755{
541e8d03 756 var s = $('#sectorSelection').find('[name=sectorSelection]').val();
bdc3d2e9
SJ
757 var ss = $('#subSectorSelection').find("[name='jobs[-1][subSector]']").val();
758 var sst = $('#subSectorSelection').find("[name='jobs[-1][subSector]'] :selected").text();
46ae38a9 759
541e8d03 760 var html = '<div id="sectors_' + s + '_' + ss + '" style="clear: both; margin-top: 0.5em" class="titre">'
9fce7016 761 + ' <a href="javascript:removeSector(\'' + s + '\',\'' + ss + '\')" style="display: block; float: right">'
6505acf7
SJ
762 + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce secteur" />'
763 + ' </a>'
541e8d03 764 + ' <input type="hidden" name="sectors[' + s + '][' + ss + ']" value="' + sst + '" />'
6505acf7
SJ
765 + ' ' + sst
766 + '</div>';
541e8d03 767 $('#sectors').append(html);
6505acf7 768 updateSubSector();
46ae38a9
FB
769}
770
16594a1a
FB
771function registerEnterpriseAutocomplete(id)
772{
f3b2736f 773 $(".enterpriseName").each(
16594a1a 774 function() {
16594a1a
FB
775 if (id == -1 || this.name == "jobs[" + id + "][name]") {
776 $(this).autocomplete(platal_baseurl + "search/autocomplete/entreprise",
777 {
6505acf7
SJ
778 selectOnly:1,
779 field:this.name,
780 matchSubset:0,
781 width:$(this).width()
16594a1a
FB
782 });
783 }
6505acf7 784 });
c7139c07 785
f3b2736f 786 $(".sectorName").each(
c7139c07 787 function() {
f3b2736f 788 if (id == -1 || this.name == "jobs[" + id + "][subSubSectorName]") {
541e8d03 789 $(this).autocomplete(platal_baseurl + "search/autocomplete/subSubSector",
c7139c07 790 {
6505acf7
SJ
791 selectOnly:1,
792 field:this.name,
793 matchSubset:0,
794 width:$(this).width()
c7139c07
SJ
795 });
796 }
6505acf7
SJ
797 });
798}
799
800// {{{1 Multiusage functions
801
802function updateElement(cat)
803{
804 var val = $('#' + cat + '_table').find('[name=' + cat + '_sel]').val();
805 if (val == '' || $('#' + cat + '_' + val).length != 0) {
806 $('#' + cat + '_add').hide();
807 } else {
808 $('#' + cat + '_add').show();
809 }
810}
811
812function removeElement(cat, id)
813{
814 $('#' + cat + '_' + id).remove();
815 updateElement(cat);
16594a1a
FB
816}
817
46ae38a9 818// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: