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