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