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