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