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