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