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