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