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