X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=htdocs%2Fjavascript%2Fprofile.js;h=d4899ecd2fbd1e5b404e62fa351436a63bef2f14;hb=e1e112b3e153c4f4a923676e6ea6024f48b5c62f;hp=067845a2529cb9fb99739301c0de75c4932b09dc;hpb=c3c43c0ebe734e2b43b5d5fdb6010d08358bc34b;p=platal.git
diff --git a/htdocs/javascript/profile.js b/htdocs/javascript/profile.js
index 067845a..d4899ec 100644
--- a/htdocs/javascript/profile.js
+++ b/htdocs/javascript/profile.js
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2003-2009 Polytechnique.org *
+ * Copyright (C) 2003-2011 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -18,330 +18,535 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
-// Page initialization
+// Page initialization {{{1
function wizPage_onLoad(id)
{
switch (id) {
case 'general':
- fillType(document.forms.prof_annu['appli1[type]'], document.forms.prof_annu['appli1[id]'].selectedIndex-1);
- selectType(document.forms.prof_annu['appli1[type]'], document.forms.prof_annu['appli1_tmp'].value);
- fillType(document.forms.prof_annu['appli2[type]'], document.forms.prof_annu['appli2[id]'].selectedIndex-1);
- selectType(document.forms.prof_annu['appli2[type]'], document.forms.prof_annu['appli2_tmp'].value);
+ var i = 1;
+ while ($('.edu_' + i).length != 0) {
+ prepareType(i - 1);
+ ++i;
+ }
+ break;
+ case 'adresses':
+ checkCurrentAddress();
break;
case 'poly':
- updateGroupSubLink(document.forms.prof_annu.groupesx_sub);
+ updateGroupSubLink();
break;
case 'deco':
- for (var i in names) {
- if (typeof names[i] != 'function') {
- if (document.getElementById("medal_" + i) != null) {
- getMedalName(i);
- buildGrade(i, document.forms.prof_annu["medal_" + i + "_grade"].value);
- }
- }
+ var i = 0;
+ while ($('#medal_' + i).length != 0) {
+ prepareMedal(i);
+ ++i;
}
break;
case 'emploi':
- for (var i = 0 ; document.getElementById('job_' + i) != null ; ++i) {
- updateJobSecteur(i, 'job_' + i, 'jobs[' + i + ']',
- document.forms.prof_annu["jobs[" + i + "][ss_secteur]"].value);
+ if ($('#jobs_0').find("[name='jobs[0][name]']").val() == '') {
+ registerEnterpriseAutocomplete(0);
}
- setTimeout('registerEnterpriseAutocomplete(-1)', 100);
break;
}
}
-var applisType;
-var applisTypeAll;
-
-// General
-
+var educationDegree;
+var educationDegreeAll;
+var educationDegreeName;
var subgrades;
var names;
-function fillType(selectCtrl, appli, fill)
+var multiples;
+
+// Publicity follows the following ordering: private < ax < public.
+var publicity = [];
+publicity['private'] = 0;
+publicity['ax'] = 1;
+publicity['public'] = 2;
+
+// Names {{{1
+
+function toggleNamesAdvanced()
{
- var i;
- var i0=0;
+ $('.names_advanced').toggle();
+}
- for (i = selectCtrl.options.length; i >=0; i--) {
- selectCtrl.options[i] = null;
+function addSearchName(isFemale)
+{
+ var i = 0;
+ while ($('#search_name_' + i).length != 0) {
+ i++;
}
+ $('#search_name_' + i)
+ .updateHtml('profile/ajax/searchname/' + i + '/' + isFemale,
+ function(data) {
+ $('#searchname').before(data);
+ changeNameFlag(i);
+ });
+}
+
+function removeSearchName(i, isFemale)
+{
+ $('#search_name_' + i).remove();
+ updateNameDisplay(isFemale);
+}
- if (fill || appli <0) {
- selectCtrl.options[0] = new Option(' ');
- i0=1;
+function changeNameFlag(i)
+{
+ $('#flag_' + i).remove();
+ var typeid = $('#search_name_' + i).find('select').val();
+ var type = $('#search_name_' + i).find('select :selected').text();
+ if ($('[name=sn_type_' + typeid + '_' + i + ']').val() > 0) {
+ $('#flag_cb_' + i).after(' ' +
+ '' +
+ '' +
+ '' +
+ '');
+ } else {
+ $('#flag_cb_' + i).after(' ' +
+ '' +
+ '' +
+ '');
}
- if (appli>=0)
- for (i=0; i < applisType[appli].length; i++)
- selectCtrl.options[i0+i] = new Option(applisType[appli][i]);
- else if (fill)
- for (i=0; i < applisTypeAll.length; i++)
- selectCtrl.options[i0+i] = new Option(applisTypeAll[i]);
}
+function updateNameDisplay(isFemale)
+{
+ var searchnames = '';
+ for (var i = 0; i < 10; i++) {
+ if ($('#search_name_' + i).find(':text').val()) {
+ searchnames += $('#search_name_' + i).find('[name*=typeid]').val() + ';';
+ searchnames += $('#search_name_' + i).find(':text').val() + ';;';
+ }
+ }
+ $.xget('profile/ajax/buildnames/' + searchnames + '/' + isFemale,
+ function(data){
+ var name = data.split(';');
+ $('#public_name').html(name[0]);
+ $('#private_name').html(name[0] + name[1]);
+ });
+}
-function selectType(selectCtrl, type)
+function toggleParticle(id)
{
- for (i = 0; i < selectCtrl.options.length; i++) {
- if (selectCtrl.options[i].text == type)
- selectCtrl.selectedIndex=i;
+ if ($('#search_name_' + id).find("[name*='[particle]']").val() == '') {
+ $('#search_name_' + id).find("[name*='[particle]']").val(1);
+ } else {
+ $('#search_name_' + id).find("[name*='[particle]']").val('');
}
}
+// Promotions {{{1
+function togglePromotionEdition()
+{
+ $(".promotion_edition").toggle();
+}
-// Addresses
+// Nationalities {{{1
-function removeObject(id, pref)
+function delNationality(i)
{
- document.getElementById(id).style.display = "none";
- document.forms.prof_annu[pref + "[removed]"].value = "1";
+ $('#nationality' + i).hide().find('select').val('');
}
-function restoreObject(id, pref)
+function addNationality()
{
- document.getElementById(id).style.display = '';
- document.forms.prof_annu[pref + "[removed]"].value = "0";
+ var i = 0;
+ if ($('#nationality2').find('select').val() == "") {
+ i = 2;
+ } else if ($('#nationality3').find('select').val() == "") {
+ i = 3;
+ }
+ if ((i == 2) || (i == 3)) {
+ $('#nationality' + i).show();
+ }
}
-function getAddressElement(adrid, adelement)
+// Education {{{1
+
+function prepareType(id)
{
- return document.forms.prof_annu["addresses[" + adrid + "][" + adelement + "]"];
+ var edu = $('.edu_' + id).find("[name='edus[" + id + "][eduid]']").val() - 1;
+ var sel = $('.edu_' + id).find('[name=edu_' + id + '_tmp]').val();
+ var html = '';
+ if (educationDegree[edu]) {
+ var length = educationDegree[edu].length;
+ } else {
+ var length = 0;
+ }
+ for (i = 0; i < length; ++i) {
+ html += '';
+ }
+ // XXX: to be removed once SQL table profile_merge_issues is.
+ if (sel != '' && html == '') {
+ html += '';
+ }
+ $('.edu_' + id).find("[name='edus[" + id + "][degreeid]']").html(html);
}
-function checkCurrentAddress(newCurrent)
+function addEdu()
{
- var hasCurrent = false;
var i = 0;
- while (getAddressElement(i, 'pub') != null) {
- var radio = getAddressElement(i, 'current');
- var removed = getAddressElement(i, 'removed');
- if (removed.value == "1" && radio.checked) {
- radio.checked = false;
- } else if (radio.checked && radio != newCurrent) {
- radio.checked = false;
- } else if (radio.checked) {
- hasCurrent = true;
+ var j = 0;
+ var prefix = 'edu_';
+ var class_parity;
+
+ while (!$('#edu_add').hasClass(prefix + i)) {
+ if ($('.' + prefix + i).length != 0) {
+ j++;
}
i++;
}
- if (!hasCurrent) {
- i = 0;
- while (getAddressElement(i, 'pub') != null) {
- var radio = getAddressElement(i, 'current');
- var removed = getAddressElement(i, 'removed');
- if (removed.value != "1") {
- radio.checked= true;
- return;
- }
- i++;
- }
+ if (j % 2) {
+ class_parity = 'pair';
+ } else {
+ class_parity = 'impair';
}
+ $('#edu_add').removeClass(prefix + i);
+ i++;
+ $('#edu_add').addClass(prefix + i);
+ i--;
+ $.xget('profile/ajax/edu/' + i + '/' + class_parity,
+ function(data) {
+ $('#edu_add').before(data);
+ prepareType(i);
+ });
}
-function removeAddress(id, pref)
+function removeEdu(i)
{
- removeObject(id, pref);
- checkCurrentAddress(null);
- if (document.forms.prof_annu[pref + '[datemaj]'].value != '') {
- document.getElementById(id + '_grayed').style.display = '';
+ var prefix = 'edu_';
+ $('.' + prefix + i).remove();
+ while (!$('#edu_add').hasClass(prefix + i)) {
+ $('.' + prefix + i).toggleClass('pair');
+ $('.' + prefix + i).toggleClass('impair');
+ i++;
}
}
-function restoreAddress(id, pref)
+// Networking {{{1
+
+function addNetworking()
{
- document.getElementById(id + '_grayed').style.display = 'none';
- checkCurrentAddress(null);
- restoreObject(id, pref);
+ var i = 0;
+ while ($('#networking_' + i).length != 0) {
+ i++;
+ }
+ var namefirst = '';
+ var html = '
'
+ + ' '
+ + ' '
+ + ' '
+ + ' '
+ + ' '
+ + ' '
+ + ' '
+ + ' '
+ + ' '
+ + ' '
+ + ' | '
+ + '
';
+
+ $('#networking').before(html);
}
-function addAddress()
+function removeNetworking(id)
+{
+ $('#networking_' + id).remove();
+}
+
+function updateNetworking(i)
{
+ $('#networking_' + i).find("[name='networking[" + i + "][name]']").val($('#networking_' + i).find('select option:selected').text());
+}
+
+// Addresses {{{1
+
+function toggleAddress(id, val)
+{
+ $('#addresses_' + id + '_grayed').toggle();
+ $('#addresses_' + id).toggle();
+ $('#addresses_' + id + '_cont').find('[name*=removed]').val(val);
+ checkCurrentAddress();
+}
+
+function checkCurrentAddress(id)
+{
+ var hasCurrentAddress = id ? true : false;
var i = 0;
- while (getAddressElement(i, 'pub') != null) {
+ while ($('#addresses_' + i + '_cont').length != 0) {
+ if ($('#addresses_' + i + '_cont').find('[name*=removed]').val() == 1) {
+ $('#addresses_' + i + '_cont').find('[name*=current]').attr('checked', false);
+ }
+ if (!hasCurrentAddress && $('#addresses_' + i + '_cont').find('[name*=current]:checked').length != 0) {
+ hasCurrentAddress = true;
+ } else {
+ $('#addresses_' + i + '_cont').find('[name*=current]').attr('checked', false);
+ }
i++;
}
- $("#add_adr").before('');
- Ajax.update_html('addresses_' + i + '_cont', 'profile/ajax/address/' + i, checkCurrentAddress);
+ if (!hasCurrentAddress) {
+ i = 0;
+ while ($('#addresses_' + i + '_cont').length != 0) {
+ if ($('#addresses_' + i + '_cont').find('[name*=removed]').val() == 0) {
+ $('#addresses_' + i + '_cont').find('[name*=current]').attr('checked', 'checked');
+ break;
+ }
+ i++;
+ }
+ }
+ if (id) {
+ $('#addresses_' + id + '_cont').find('[name*=current]').attr('checked', 'checked');
+ }
}
-function addTel(id)
+function addAddress()
{
var i = 0;
- var adid = 'addresses_' + id;
- var tel = adid + '_tel_';
- while (document.getElementById(tel + i) != null) {
+ while ($('#addresses_' + i + '_cont').length != 0) {
i++;
}
- $('#' + adid + '_add_tel').before('');
- Ajax.update_html(tel + i, 'profile/ajax/tel/' + id + '/' + i);
+ $('#add_address').before('');
+ $('#addresses_' + i + '_cont').updateHtml('profile/ajax/address/' + i,
+ checkCurrentAddress());
}
-
-// Geoloc
-
-function validGeoloc(id, pref)
+function addressChanged(prefid)
{
- document.getElementById(id + '_geoloc').style.display = 'none';
- document.getElementById(id + '_geoloc_error').style.display = 'none';
- document.getElementById(id + '_geoloc_valid').style.display = 'none';
- document.forms.prof_annu[pref + "[parsevalid]"].value = "1";
- document.forms.prof_annu[pref + "[text]"].value = document.forms.prof_annu[pref + "[geoloc]"].value;
- document.forms.prof_annu[pref + "[cityid]"].value = document.forms.prof_annu[pref + "[geoloc_cityid]"].value;
- $(document.forms.prof_annu[pref + "[text]"]).click(function() { document.forms.prof_annu[pref + "[text]"].blur(); });
- document.forms.prof_annu[pref + "[text]"].className = '';
+ $('#' + prefid + '_cont').find('[name*=changed]').val("1");
}
-function validAddress(id, pref)
+function validGeoloc(prefid, id, geoloc)
{
- document.getElementById(id + '_geoloc').style.display = 'none';
- document.getElementById(id + '_geoloc_error').style.display = 'none';
- document.getElementById(id + '_geoloc_valid').style.display = 'none';
- document.forms.prof_annu[pref + "[parsevalid]"].value = "1";
- $(document.forms.prof_annu[pref + "[text]"]).click(function() { document.forms.prof_annu[pref + "[text]"].blur(); });
- document.forms.prof_annu[pref + "[text]"].className = '';
+ if (geoloc == 1) {
+ $('#' + prefid + '_cont').find('[name*=text]').val($('#' + prefid + '_cont').find('[name*=geocodedText]').val());
+ $('#' + prefid + '_cont').find('[name*=postalText]').val('');
+ }
+ if (geoloc > 0) {
+ $('#' + prefid + '_cont').find("[name*='[geocodedText]']").remove();
+ }
+ $('#' + prefid + '_cont').find('[name*=text]').removeClass('error');
+ $('#' + prefid + '_cont').find('[name*=geocodeChosen]').val(geoloc);
+ $('.' + prefid + '_geoloc').remove();
}
+// {{{1 Phones
-// Groups
+function addTel(prefid, prefname, subField, mainField, mainId)
+{
+ var i = 0;
+ var prefix = prefid + '_';
+ while ($('#' + prefix + i).length != 0) {
+ i++;
+ }
+ $('#' + prefix + 'add').before('');
+ $('#' + prefix + i).updateHtml('profile/ajax/tel/' + prefid + '/' + prefname + '/' + i + '/' + subField + '/' + mainField + '/' + mainId);
+}
-function updateGroup(type)
+function removeTel(prefname, prefid, id)
{
- var val = document.forms.prof_annu[type + '_sel'].value;
- if (val == '0' || document.getElementById(type + '_' + val) != null) {
- document.getElementById(type + '_add').style.display = 'none';
- } else {
- document.getElementById(type + '_add').style.display = '';
+ var total = 0;
+ while ($('#' + prefid + '_' + total).length != 0) {
+ ++total;
+ }
+ $('#' + prefid + '_' + id).remove();
+ for (var i = parseInt(id) + 1; i < total; ++i) {
+ renumberPhone(prefname, prefid, i);
}
}
-function removeGroup(cat, id)
+function addPhoneComment(id)
{
- $('#' + cat + '_' + id).remove();
- updateGroup(cat);
+ $('#' + id + '_comment').show();
+ $('#' + id + '_addComment').hide();
}
-function addGroup(cat)
+function removePhoneComment(id, pref)
{
- var cb = document.forms.prof_annu[cat + '_sel'];
- var id = cb.value;
- var text = cb.options[cb.selectedIndex].text;
- var html = ''
- + ' '
- + ' '
- + ' | '
- + ' '
- + ' '
- + text
- + ' '
- + ' '
- + ' '
- + ' '
- + ' | '
- + '
';
- $('#' + cat).after(html);
- updateGroup(cat);
+ $('#' + id + '_comment').hide();
+ $('#' + id + '_comment').find("[name='" + pref + "[comment]']").val('');
+ $('#' + id + '_addComment').show();
}
-function updateGroupSubLink(cb)
+function renumberPhone(prefname, prefid, i)
{
- var href = cb.value ? cb.value : "http://www.polytechnique.net";
- document.getElementById("groupesx_sub").href = href;
+ var telid = i - 1;
+ var telprefOld = prefname + '[' + i + ']';
+ var telpref = prefname + '[' + telid + ']';
+ var idOld = prefid + '_' + i;
+ var id = prefid + '_' + telid;
+
+ $('#' + idOld).attr('id', id);
+ $('#' + id).find('div.titre').html('N°' + i);
+ $('#' + id).find('a.removeTel').attr('href', 'javascript:removeTel(\'' + prefname + '\',\'' + prefid + '\',' + telid + ')');
+ $('#' + id).find('select').attr('name', telpref + '[type]');
+ $('#' + id).find("[name='" + telprefOld + "[display]']").attr('name', telpref + '[display]');
+ $('#' + id).find("[name='" + telprefOld + "[comment]']").attr('name', telpref + '[comment]');
+ $('#' + id).find('a.removePhoneComment').attr('href', 'javascript:removePhoneComment(' + id + ',' + telpref + ')');
+ $('#' + id).find('#' + idOld + '_addComment').attr('id', id + '_addComment');
+ $('#' + id).find('#' + id + '_addComment').attr('href', 'javascript:addPhoneComment(' + id + ')');
+ $('#' + id).find('#' + idOld + '_comment').attr('id', id + '_comment');
+ $('#' + id).find("[name='" + telprefOld + "[pub]']").attr('name', telpref + '[pub]');
}
+// {{{1 Groups
-// Medals
+function addBinet()
+{
+ var id = $('#binets_table').find('[name=binets_sel]').val();
+ var text = $('#binets_table').find('select option:selected').text();
+ var html = ''
+ + ' '
+ + ' '
+ + ' | '
+ + ' '
+ + ' '
+ + text
+ + ' '
+ + ' '
+ + ' '
+ + ' '
+ + ' | '
+ + '
';
+ $('#binets_table').after(html);
+ updateElement('binets');
+}
+
+function updateGroupSubLink()
+{
+ var href = $('[name*=groupesx_sub]').val() ? $('[name*=groupesx_sub]').val() : 'http://www.polytechnique.net';
+ $('#groupesx_sub').attr('href', href);
+}
+
+// {{{1 Medals
+
+function prepareMedal(i)
+{
+ getMedalName($('#medal_' + i).find('[name="medals[' + i + '][id]"]').val());
+ buildGrade(i);
+}
function updateMedal()
{
- var val = document.forms.prof_annu['medal_sel'].value;
- if (val == '' || document.getElementById('medal_' + val) != null) {
- document.getElementById('medal_add').style.display = 'none';
+ var val = $('#medals').find('[name*=medal_sel]').val();
+
+ if ((multiple[val] && subgrades[val]) || $('.medal_name_' + val).length == 0) {
+ $('#medal_add').show();
} else {
- document.getElementById('medal_add').style.display = '';
+ $('#medal_add').hide();
}
}
function getMedalName(id)
{
- document.getElementById('medal_name_' + id).innerHTML = names[id];
+ $('.medal_name_' + id).html(names[id]);
}
-function buildGrade(id, current)
+function buildGrade(i)
{
- var grade;
- var subg = subgrades[id];
- var obj = $('#medal_grade_' + id);
+ var id = $('#medal_' + i).find('[name="medals[' + i + '][id]"]').val();
+ var current = $('#medal_' + i).find('[name="medals_' + i + '_grade"]').val();
+ var subg = subgrades[id];
+ var obj = $('#medal_grade_' + i);
if (!subg) {
- obj.prepend('');
+ obj.prepend('');
} else {
- var html = 'Agrafe :