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': | |
6505acf7 | 48 | for (var i = 0 ; $('#job_' + i).length != 0; ++i) { |
541e8d03 | 49 | updateJobSector(i, $('#job_' + i).find("[name='jobs[" + i + "][subSector]']").val()); |
2992a284 | 50 | updateJobSubSector(i, $('#job_' + i).find("[name='jobs[" + i + "][subSubSector]']").val()); |
07e72582 | 51 | updateJobAlternates(i); |
46ae38a9 FB |
52 | } |
53 | break; | |
54 | } | |
55 | } | |
56 | ||
f711b03f SJ |
57 | var educationDegree; |
58 | var educationDegreeAll; | |
59 | var educationDegreeName; | |
46ae38a9 FB |
60 | var subgrades; |
61 | var names; | |
8c7ac79e | 62 | |
8c7ac79e SJ |
63 | // Names {{{1 |
64 | ||
e1082e20 | 65 | function toggleNamesAdvanced() |
6e32823c | 66 | { |
e1082e20 | 67 | $('.names_advanced').toggle(); |
6e32823c SJ |
68 | } |
69 | ||
b04882ff PC |
70 | function addSearchName() |
71 | { | |
6e32823c SJ |
72 | var i = 0; |
73 | while ($('#search_name_' + i).length != 0) { | |
74 | i++; | |
75 | } | |
76 | Ajax.update_html('search_name_' + i, 'profile/ajax/searchname/' + i, function(data){ | |
77 | $('#searchname').before(data); | |
78 | changeNameFlag(i); | |
79 | }); | |
b04882ff | 80 | } |
46ae38a9 | 81 | |
b04882ff PC |
82 | function removeSearchName(i) |
83 | { | |
6e32823c SJ |
84 | $('#search_name_' + i).remove(); |
85 | updateNameDisplay(); | |
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 | ||
107 | function updateNameDisplay() | |
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 | } | |
116 | Ajax.update_html(null, 'profile/ajax/buildnames/' + searchnames, 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 | |
09f9ebea SJ |
123 | function toggleParticle(id) |
124 | { | |
125 | if ($('#search_name_' + id).find("[name*='[particle]']").val() == '') { | |
126 | $('#search_name_' + id).find("[name*='[particle]']").val(1); | |
127 | } else { | |
128 | $('#search_name_' + id).find("[name*='[particle]']").val(''); | |
129 | } | |
130 | } | |
131 | ||
8c7ac79e SJ |
132 | // Nationalities {{{1 |
133 | ||
8450c2aa SJ |
134 | function delNationality(i) |
135 | { | |
136 | $('#nationalite' + i).hide().find('select').val(''); | |
137 | } | |
138 | ||
139 | function addNationality() | |
140 | { | |
141 | var i = 0; | |
142 | if ($('#nationalite2').find('select').val() == "") { | |
143 | i = 2; | |
144 | } else if ($('#nationalite3').find('select').val() == "") { | |
145 | i = 3; | |
146 | } | |
147 | if ((i == 2) || (i == 3)) { | |
148 | $('#nationalite' + i).show(); | |
149 | } | |
150 | } | |
151 | ||
6505acf7 SJ |
152 | // Education {{{1 |
153 | ||
154 | function prepareType(id) | |
155 | { | |
156 | var edu = $('.edu_' + id).find("[name='edus[" + id + "][eduid]']").val() - 1; | |
157 | var sel = $('.edu_' + id).find('[name=edu_' + id + '_tmp]').val(); | |
158 | var html = ''; | |
159 | var length = educationDegree[edu].length; | |
160 | for (i = 0; i < length; ++i) { | |
161 | html += '<option value="' + educationDegree[edu][i] + '"'; | |
162 | if (sel == educationDegree[edu][i]) { | |
163 | html += ' selected="selected"'; | |
164 | } | |
165 | html += '>' + educationDegreeName[educationDegree[edu][i] - 1] + '</option>'; | |
166 | } | |
167 | $('.edu_' + id).find("[name='edus[" + id + "][degreeid]']").html(html); | |
168 | } | |
169 | ||
170 | function addEdu() | |
171 | { | |
172 | var i = 0; | |
173 | var j = 0; | |
174 | var prefix = 'edu_'; | |
175 | var class_parity; | |
176 | ||
177 | while (!$('#edu_add').hasClass(prefix + i)) { | |
178 | if ($('.' + prefix + i).length != 0) { | |
179 | j++; | |
180 | } | |
181 | i++; | |
182 | } | |
183 | if (j % 2) { | |
184 | class_parity = 'pair'; | |
185 | } else { | |
186 | class_parity = 'impair'; | |
187 | } | |
188 | $('#edu_add').removeClass(prefix + i); | |
189 | i++; | |
190 | $('#edu_add').addClass(prefix + i); | |
191 | i--; | |
192 | $.get(platal_baseurl + 'profile/ajax/edu/' + i + '/' + class_parity, | |
193 | function(data) { | |
194 | $('#edu_add').before(data); | |
195 | prepareType(i); | |
196 | }); | |
197 | } | |
198 | ||
199 | function removeEdu(i) | |
200 | { | |
201 | var prefix = 'edu_'; | |
202 | $('.' + prefix + i).remove(); | |
203 | while (!$('#edu_add').hasClass(prefix + i)) { | |
204 | $('.' + prefix + i).toggleClass('pair'); | |
205 | $('.' + prefix + i).toggleClass('impair'); | |
206 | i++; | |
207 | } | |
208 | } | |
209 | ||
8c7ac79e SJ |
210 | // Networking {{{1 |
211 | ||
d1a2252a GB |
212 | function addNetworking() |
213 | { | |
214 | var i = 0; | |
6505acf7 | 215 | while ($('#networking_' + i).length != 0) { |
d1a2252a GB |
216 | i++; |
217 | } | |
92c3f9e5 | 218 | var namefirst = ''; |
d1a2252a | 219 | var html = '<tr id="networking_' + i + '">' |
92c3f9e5 GB |
220 | + ' <td colspan="2">' |
221 | + ' <div style="float: left; width: 200px;">' | |
222 | + ' <span class="flags">' | |
223 | + ' <input type="checkbox" name="networking[' + i + '][pub]"/>' | |
224 | + ' <img src="images/icons/flag_green.gif" alt="site public" title="site public">' | |
225 | + ' </span> ' | |
6505acf7 | 226 | + ' <select name="networking[' + i + '][type]" onchange="javascript:updateNetworking(' + i + ');">'; |
92c3f9e5 GB |
227 | for (nw in nw_list) { |
228 | if (namefirst == '') { | |
229 | namefirst = nw; | |
230 | } | |
231 | html += ' <option value="' + nw_list[nw] + '">' + nw + '</option>'; | |
232 | } | |
233 | html += '</select>' | |
6505acf7 | 234 | + ' <input type="hidden" name="networking[' + i + '][name]" value="' + namefirst + '"/>' |
92c3f9e5 GB |
235 | + ' </div>' |
236 | + ' <div style="float: left">' | |
237 | + ' <input type="text" name="networking[' + i + '][address]" value="" size="30"/>' | |
238 | + ' <a href="javascript:removeNetworking(' + i + ')">' | |
239 | + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer cet élément"/>' | |
240 | + ' </a>' | |
241 | + ' </div>' | |
d1a2252a GB |
242 | + ' </td>' |
243 | + '</tr>'; | |
244 | ||
92c3f9e5 | 245 | $('#networking').before(html); |
d1a2252a GB |
246 | } |
247 | ||
248 | function removeNetworking(id) | |
249 | { | |
250 | $('#networking_' + id).remove(); | |
251 | } | |
252 | ||
92c3f9e5 | 253 | function updateNetworking(i) |
d1a2252a | 254 | { |
6505acf7 | 255 | $('#networking_' + i).find("[name='networking[" + i + "][name]']").val($('#networking_' + i).find('select option:selected').text()); |
d1a2252a GB |
256 | } |
257 | ||
8c7ac79e | 258 | // Addresses {{{1 |
46ae38a9 | 259 | |
041a5cec | 260 | function toggleAddress(id, val) |
46ae38a9 | 261 | { |
041a5cec SJ |
262 | $('#addresses_' + id + '_grayed').toggle(); |
263 | $('#addresses_' + id).toggle(); | |
264 | $('#addresses_' + id + '_cont').find('[name*=removed]').val(val); | |
265 | checkCurrentAddress(); | |
46ae38a9 FB |
266 | } |
267 | ||
041a5cec | 268 | function checkCurrentAddress(id) |
46ae38a9 | 269 | { |
041a5cec | 270 | var hasCurrentAddress = id ? true : false; |
46ae38a9 | 271 | var i = 0; |
041a5cec SJ |
272 | while ($('#addresses_' + i + '_cont').length != 0) { |
273 | if ($('#addresses_' + i + '_cont').find('[name*=removed]').val() == 1) { | |
274 | $('#addresses_' + i + '_cont').find('[name*=current]').attr('checked', false); | |
275 | } | |
276 | if (!hasCurrentAddress && $('#addresses_' + i + '_cont').find('[name*=current]:checked').length != 0) { | |
277 | hasCurrentAddress = true; | |
278 | } else { | |
279 | $('#addresses_' + i + '_cont').find('[name*=current]').attr('checked', false); | |
46ae38a9 FB |
280 | } |
281 | i++; | |
282 | } | |
041a5cec | 283 | if (!hasCurrentAddress) { |
46ae38a9 | 284 | i = 0; |
041a5cec SJ |
285 | while ($('#addresses_' + i + '_cont').length != 0) { |
286 | if ($('#addresses_' + i + '_cont').find('[name*=removed]').val() == 0) { | |
287 | $('#addresses_' + i + '_cont').find('[name*=current]').attr('checked', 'checked'); | |
288 | break; | |
289 | } | |
290 | i++; | |
46ae38a9 FB |
291 | } |
292 | } | |
041a5cec SJ |
293 | if (id) { |
294 | $('#addresses_' + id + '_cont').find('[name*=current]').attr('checked', 'checked'); | |
46ae38a9 FB |
295 | } |
296 | } | |
297 | ||
46ae38a9 FB |
298 | function addAddress() |
299 | { | |
300 | var i = 0; | |
041a5cec | 301 | while ($('#addresses_' + i + '_cont').length != 0) { |
46ae38a9 FB |
302 | i++; |
303 | } | |
041a5cec SJ |
304 | $('#add_address').before('<div id="addresses_' + i + '_cont"></div>'); |
305 | Ajax.update_html('addresses_' + i + '_cont', 'profile/ajax/address/' + i, checkCurrentAddress()); | |
46ae38a9 FB |
306 | } |
307 | ||
541e8d03 | 308 | function addressChanged(prefid) |
043bbacf | 309 | { |
541e8d03 | 310 | $('#' + prefid + '_cont').find('[name*=changed]').val("1"); |
043bbacf SJ |
311 | } |
312 | ||
541e8d03 | 313 | function validGeoloc(prefid, id, geoloc) |
043bbacf | 314 | { |
041a5cec | 315 | if (geoloc == 1) { |
541e8d03 SJ |
316 | $('#' + prefid + '_cont').find('[name*=text]').val($('#' + prefid + '_cont').find('[name*=geoloc]').val()); |
317 | $('#' + prefid + '_cont').find('[name*=postalText]').val($('#' + prefid + '_cont').find('[name*=geocodedPostalText]').val()); | |
041a5cec | 318 | } |
5112531d | 319 | if (geoloc > 0) { |
541e8d03 | 320 | $('#' + prefid + '_cont').find("[name*='[geoloc]']").remove(); |
5112531d | 321 | } |
541e8d03 SJ |
322 | $('#' + prefid + '_cont').find('[name*=text]').removeClass('error'); |
323 | $('#' + prefid + '_cont').find('[name*=geoloc_choice]').val(geoloc); | |
324 | $('.' + prefid + '_geoloc').remove(); | |
043bbacf SJ |
325 | } |
326 | ||
8c7ac79e SJ |
327 | // {{{1 Phones |
328 | ||
bde2be3b | 329 | function addTel(prefid, prefname) |
46ae38a9 FB |
330 | { |
331 | var i = 0; | |
bde2be3b | 332 | var prefix = prefid + '_'; |
6505acf7 | 333 | while ($('#' + prefix + i).length != 0) { |
46ae38a9 FB |
334 | i++; |
335 | } | |
bde2be3b GB |
336 | $('#' + prefix + 'add').before('<div id="' + prefix + i + '" style="clear: both; padding-top: 4px; padding-bottom: 4px"></div>'); |
337 | Ajax.update_html(prefix + i, 'profile/ajax/tel/' + prefid + '/' + prefname + '/' + i); | |
46ae38a9 FB |
338 | } |
339 | ||
bde2be3b GB |
340 | function removeTel(id) |
341 | { | |
342 | $('#' + id).remove(); | |
343 | } | |
344 | ||
6505acf7 | 345 | function addPhoneComment(id) |
bde2be3b | 346 | { |
3cd815ca SJ |
347 | $('#' + id + '_comment').show(); |
348 | $('#' + id + '_addComment').hide(); | |
bde2be3b GB |
349 | } |
350 | ||
351 | function removePhoneComment(id, pref) | |
352 | { | |
3cd815ca SJ |
353 | $('#' + id + '_comment').hide(); |
354 | $('#' + id + '_comment').find("[name='" + pref + "[comment]']").val(''); | |
355 | $('#' + id + '_addComment').show(); | |
bde2be3b | 356 | } |
46ae38a9 | 357 | |
6505acf7 | 358 | // {{{1 Groups |
46ae38a9 | 359 | |
6505acf7 | 360 | function addBinet() |
46ae38a9 | 361 | { |
6505acf7 SJ |
362 | var id = $('#binets_table').find('[name=binets_sel]').val(); |
363 | var text = $('#binets_table').find('select option:selected').text(); | |
364 | var html = '<tr id="binets_' + id + '">' | |
365 | + ' <td>' | |
366 | + ' <input type="hidden" name="binets[' + id + ']" value="' + text + '" />' | |
367 | + ' </td>' | |
368 | + ' <td>' | |
369 | + ' <div style="float: left; width: 70%">' | |
370 | + text | |
371 | + ' </div>' | |
372 | + ' <a href="javascript:removeElement(\'binets\', ' + id + ')">' | |
373 | + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer ce groupe" />' | |
374 | + ' </a>' | |
375 | + ' </td>' | |
376 | + '</tr>'; | |
377 | $('#binets_table').after(html); | |
378 | updateElement('binets'); | |
46ae38a9 FB |
379 | } |
380 | ||
6505acf7 | 381 | function updateGroupSubLink() |
46ae38a9 | 382 | { |
6505acf7 SJ |
383 | var href = $('[name*=groupesx_sub]').val() ? $('[name*=groupesx_sub]').val() : 'http://www.polytechnique.net'; |
384 | $('#groupesx_sub').attr('href', href); | |
46ae38a9 FB |
385 | } |
386 | ||
6505acf7 | 387 | // {{{1 Medals |
46ae38a9 FB |
388 | |
389 | function updateMedal() | |
390 | { | |
6505acf7 SJ |
391 | var val = $('#medals').find('[name*=medal_sel]').val(); |
392 | if (val && ($('#medal_' + val).length == 0)) { | |
393 | $('#medal_add').show(); | |
46ae38a9 | 394 | } else { |
6505acf7 | 395 | $('#medal_add').hide(); |
46ae38a9 FB |
396 | } |
397 | } | |
398 | ||
399 | function getMedalName(id) | |
400 | { | |
6505acf7 | 401 | $('#medal_name_' + id).html(names[id]); |
46ae38a9 FB |
402 | } |
403 | ||
404 | function buildGrade(id, current) | |
405 | { | |
406 | var grade; | |
407 | var subg = subgrades[id]; | |
408 | var obj = $('#medal_grade_' + id); | |
409 | if (!subg) { | |
410 | obj.prepend('<input type="hidden" name="medals[' + id + '][grade]" value="0" />'); | |
411 | } else { | |
412 | var html = 'Agrafe : <select name="medals[' + id + '][grade]">'; | |
413 | html += '<option value="0">Non précisée</option>'; | |
414 | for (grade = 0 ; grade < subg.length ; grade++) { | |
415 | html += '<option value="' + subg[grade][0] + '"'; | |
416 | if (subg[grade][0] == current) { | |
417 | html += ' selected="selected"'; | |
418 | } | |
419 | html += '>' + subg[grade][1] + '</option>'; | |
420 | } | |
421 | ||
422 | html += '</select>'; | |
423 | obj.prepend(html); | |
424 | } | |
425 | } | |
426 | ||
427 | function makeAddProcess(id) | |
428 | { | |
429 | return function(data) | |
430 | { | |
431 | $('#medals').after(data); | |
432 | updateMedal(); | |
433 | getMedalName(id); | |
434 | buildGrade(id, 0); | |
435 | }; | |
436 | } | |
437 | ||
438 | function addMedal() | |
439 | { | |
6505acf7 | 440 | var id = $('#medals').find('[name=medal_sel]').val(); |
46ae38a9 FB |
441 | $.get(platal_baseurl + 'profile/ajax/medal/' + id, makeAddProcess(id)); |
442 | } | |
443 | ||
444 | function removeMedal(id) | |
445 | { | |
446 | $("#medal_" + id).remove(); | |
447 | updateMedal(); | |
448 | } | |
449 | ||
8c7ac79e | 450 | // Jobs {{{1 |
46ae38a9 FB |
451 | |
452 | function removeJob(id, pref) | |
453 | { | |
6505acf7 | 454 | $('#' + id + '_cont').hide(); |
00ca8c09 | 455 | if ($('#' + id).find("[name='" + pref + "[new]']").val() == '0') { |
6505acf7 | 456 | $('#' + id + '_grayed').show(); |
00ca8c09 | 457 | $('#' + id + '_grayed_name').html($('#' + id).find("[name='" + pref + "[name]']").val()); |
46ae38a9 | 458 | } |
00ca8c09 | 459 | $('#' + id).find("[name='" + pref + "[removed]']").val('1'); |
46ae38a9 FB |
460 | } |
461 | ||
462 | function restoreJob(id, pref) | |
463 | { | |
6505acf7 SJ |
464 | $('#' + id + '_cont').show(); |
465 | $('#' + id + '_grayed').hide(); | |
00ca8c09 | 466 | $('#' + id).find("[name='" + pref + "[removed]']").val('0'); |
46ae38a9 FB |
467 | } |
468 | ||
6505acf7 | 469 | function updateJobSector(id, sel) |
46ae38a9 | 470 | { |
541e8d03 | 471 | var sector = $('#job_' + id).find("[name='jobs[" + id + "][sector]']").val(); |
6505acf7 SJ |
472 | if (sector == '') { |
473 | sector = '-1'; | |
46ae38a9 | 474 | } |
541e8d03 | 475 | Ajax.update_html('job_' + id + '_subSector', 'profile/ajax/sector/' + id + '/job_' + id + '/jobs[' + id + ']/' + sector + '/' + sel); |
c7139c07 SJ |
476 | } |
477 | ||
6505acf7 | 478 | function updateJobSubSector(id, sel) |
c7139c07 | 479 | { |
541e8d03 | 480 | var subSector = $('#job_' + id).find("[name='jobs[" + id + "][subSector]']").val(); |
6505acf7 SJ |
481 | if (subSector == '') { |
482 | subSector = '-1'; | |
c7139c07 | 483 | } |
541e8d03 | 484 | Ajax.update_html('job_' + id + '_subSubSector', 'profile/ajax/sub_sector/' + id + '/' + subSector + '/' + sel); |
c7139c07 SJ |
485 | } |
486 | ||
07e72582 SJ |
487 | function updateJobAlternates(id) |
488 | { | |
489 | var subSubSector = $('#job_' + id).find("[name='jobs[" + id + "][subSubSector]']").val(); | |
490 | if (subSubSector != '') { | |
491 | Ajax.update_html('job_' + id + '_alternates', 'profile/ajax/alternates/' + id + '/' + subSubSector); | |
492 | } | |
493 | } | |
494 | ||
b814a8b8 | 495 | function displayAllSector(id) |
c7139c07 | 496 | { |
b814a8b8 SJ |
497 | $('.sector_text_' + id).remove(); |
498 | $('.sector_' + id).show(); | |
46ae38a9 FB |
499 | } |
500 | ||
501 | function makeAddJob(id) | |
502 | { | |
503 | return function(data) | |
504 | { | |
505 | $('#add_job').before(data); | |
16594a1a | 506 | registerEnterpriseAutocomplete(id); |
46ae38a9 FB |
507 | }; |
508 | } | |
509 | ||
510 | function addJob() | |
511 | { | |
512 | var i = 0; | |
6505acf7 | 513 | while ($('#job_' + i).length != 0) { |
46ae38a9 FB |
514 | ++i; |
515 | } | |
516 | $.get(platal_baseurl + 'profile/ajax/job/' + i, makeAddJob(i)); | |
517 | } | |
518 | ||
b814a8b8 SJ |
519 | function addEntreprise(id) |
520 | { | |
521 | $('.entreprise_' + id).toggle(); | |
522 | } | |
46ae38a9 | 523 | |
8c7ac79e | 524 | // {{{1 Skills |
46ae38a9 | 525 | |
46ae38a9 FB |
526 | function addSkill(cat) |
527 | { | |
6505acf7 SJ |
528 | var val = $('#' + cat + '_table').find('[name=' + cat + '_sel]').val(); |
529 | var text = $('#' + cat + '_table').find('[name=' + cat + '_sel] :selected').text(); | |
46ae38a9 FB |
530 | $.get(platal_baseurl + 'profile/ajax/skill/' + cat + '/' + val, |
531 | function(data) { | |
6505acf7 SJ |
532 | $('#' + cat).append(data); |
533 | $('#' + cat + '_' + val + '_title').text(text); | |
534 | updateElement(cat); | |
46ae38a9 FB |
535 | }); |
536 | } | |
537 | ||
6505acf7 | 538 | // {{{1 Mentor |
46ae38a9 FB |
539 | |
540 | function addCountry() | |
541 | { | |
6505acf7 SJ |
542 | var val = $('#countries_table').find('[name=countries_sel] :selected').val(); |
543 | var text = $('#countries_table').find('[name=countries_sel] :selected').text(); | |
46ae38a9 | 544 | var html = '<div id="countries_' + val + '" style="clear: both; margin-bottom: 0.7em">' |
6505acf7 | 545 | + ' <a href="javascript:removeElement(\'countries\', \'' + val + '\')" style="display: block; float:right">' |
46ae38a9 FB |
546 | + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce pays" />' |
547 | + ' </a>' | |
1d414e12 PC |
548 | + ' <div style="float: left; width: 50%">' + text + '</div>' |
549 | + ' <input type="hidden" name="countries[' + val + ']" value="' + text + '" />' | |
46ae38a9 FB |
550 | + '</div>'; |
551 | $('#countries').append(html); | |
6505acf7 | 552 | updateElement('countries'); |
46ae38a9 FB |
553 | } |
554 | ||
6505acf7 | 555 | function updateSubSector() |
46ae38a9 | 556 | { |
541e8d03 | 557 | var s = $('#sectorSelection').find('[name=sectorSelection]').val(); |
bdc3d2e9 | 558 | var ss = $('#subSectorSelection').find("[name='jobs[-1][subSector]']").val(); |
541e8d03 SJ |
559 | if ((s == '' || ss == '') || $('#sectors_' + s + '_' + ss).length != 0) { |
560 | $('#addSector').hide(); | |
6505acf7 | 561 | } else { |
541e8d03 | 562 | $('#addSector').show(); |
6505acf7 | 563 | } |
46ae38a9 | 564 | } |
6505acf7 SJ |
565 | |
566 | function removeSector(s, ss) | |
46ae38a9 | 567 | { |
541e8d03 | 568 | $('#sectors_' + s + '_' + ss).remove(); |
6505acf7 | 569 | updateSubSector(); |
46ae38a9 FB |
570 | } |
571 | ||
6505acf7 | 572 | function updateSector() |
46ae38a9 | 573 | { |
541e8d03 SJ |
574 | var sector = $('#sectorSelection').find('[name=sectorSelection]').val(); |
575 | if (sector == '') { | |
576 | sector = '-1'; | |
bdc3d2e9 | 577 | $('#subSectorSelection').html(''); |
76a2858c | 578 | return; |
46ae38a9 | 579 | } |
541e8d03 | 580 | $.get(platal_baseurl + 'profile/ajax/sector/-1/0/0/' + sector, |
46ae38a9 | 581 | function(data) { |
541e8d03 | 582 | data = '<a href="javascript:addSector()" style="display: none; float: right" id="addSector">' |
bdc3d2e9 | 583 | + ' <img src="images/icons/add.gif" alt="Ajouter ce secteur" title="Ajouter ce secteur" />' |
6505acf7 | 584 | + '</a>' + data; |
bdc3d2e9 SJ |
585 | $('#subSectorSelection').html(data); |
586 | $('#subSectorSelection').find("[name='jobs[-1][subSector]']").change(updateSubSector); | |
46ae38a9 FB |
587 | }); |
588 | } | |
589 | ||
6505acf7 | 590 | function addSector() |
46ae38a9 | 591 | { |
541e8d03 | 592 | var s = $('#sectorSelection').find('[name=sectorSelection]').val(); |
bdc3d2e9 SJ |
593 | var ss = $('#subSectorSelection').find("[name='jobs[-1][subSector]']").val(); |
594 | var sst = $('#subSectorSelection').find("[name='jobs[-1][subSector]'] :selected").text(); | |
46ae38a9 | 595 | |
541e8d03 | 596 | var html = '<div id="sectors_' + s + '_' + ss + '" style="clear: both; margin-top: 0.5em" class="titre">' |
6505acf7 SJ |
597 | + ' <a href="javascript:removeSector(\'' + s + '\', \'' + ss + '\')" style="display: block; float: right">' |
598 | + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce secteur" />' | |
599 | + ' </a>' | |
541e8d03 | 600 | + ' <input type="hidden" name="sectors[' + s + '][' + ss + ']" value="' + sst + '" />' |
6505acf7 SJ |
601 | + ' ' + sst |
602 | + '</div>'; | |
541e8d03 | 603 | $('#sectors').append(html); |
6505acf7 | 604 | updateSubSector(); |
46ae38a9 FB |
605 | } |
606 | ||
16594a1a FB |
607 | function registerEnterpriseAutocomplete(id) |
608 | { | |
f3b2736f | 609 | $(".enterpriseName").each( |
16594a1a | 610 | function() { |
16594a1a FB |
611 | if (id == -1 || this.name == "jobs[" + id + "][name]") { |
612 | $(this).autocomplete(platal_baseurl + "search/autocomplete/entreprise", | |
613 | { | |
6505acf7 SJ |
614 | selectOnly:1, |
615 | field:this.name, | |
616 | matchSubset:0, | |
617 | width:$(this).width() | |
16594a1a FB |
618 | }); |
619 | } | |
6505acf7 | 620 | }); |
c7139c07 | 621 | |
f3b2736f | 622 | $(".sectorName").each( |
c7139c07 | 623 | function() { |
f3b2736f | 624 | if (id == -1 || this.name == "jobs[" + id + "][subSubSectorName]") { |
541e8d03 | 625 | $(this).autocomplete(platal_baseurl + "search/autocomplete/subSubSector", |
c7139c07 | 626 | { |
6505acf7 SJ |
627 | selectOnly:1, |
628 | field:this.name, | |
629 | matchSubset:0, | |
630 | width:$(this).width() | |
c7139c07 SJ |
631 | }); |
632 | } | |
6505acf7 SJ |
633 | }); |
634 | } | |
635 | ||
636 | // {{{1 Multiusage functions | |
637 | ||
638 | function updateElement(cat) | |
639 | { | |
640 | var val = $('#' + cat + '_table').find('[name=' + cat + '_sel]').val(); | |
641 | if (val == '' || $('#' + cat + '_' + val).length != 0) { | |
642 | $('#' + cat + '_add').hide(); | |
643 | } else { | |
644 | $('#' + cat + '_add').show(); | |
645 | } | |
646 | } | |
647 | ||
648 | function removeElement(cat, id) | |
649 | { | |
650 | $('#' + cat + '_' + id).remove(); | |
651 | updateElement(cat); | |
16594a1a FB |
652 | } |
653 | ||
46ae38a9 | 654 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |