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