Improves education's form display (Finaly closes #209)
[platal.git] / htdocs / javascript / profile.js
index 2b615e8..4b3c470 100644 (file)
@@ -24,10 +24,14 @@ 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 = 0;
+        var prefix  = 'edu_';
+        while ($('.' + prefix + i).length != 0) {
+            i++;
+        }
+        for (var j = 0; j < i; j++) {
+            prepareType(j);
+        }
         break;
       case 'poly':
         updateGroupSubLink(document.forms.prof_annu.groupesx_sub);
@@ -52,43 +56,54 @@ function wizPage_onLoad(id)
     }
 }
 
-var applisType;
-var applisTypeAll;
+var educationDegree;
+var educationDegreeAll;
+var educationDegreeName;
 
 // General
 
 var subgrades;
 var names;
-function fillType(selectCtrl, appli, fill)
+function fillType(selectCtrl, edu, fill)
 {
     var i;
-    var i0=0;
+    var i0 = 0;
 
-    for (i = selectCtrl.options.length; i >=0; i--) {
+    for (i = selectCtrl.options.length; i >= 0; i--) {
         selectCtrl.options[i] = null;
     }
 
-    if (fill || appli <0) {
+    if (fill || edu < 0) {
         selectCtrl.options[0] = new Option(' ');
-        i0=1;
+        i0 = 1;
+    }
+    if (edu >= 0) {
+        for (i = 0; i < educationDegree[edu].length; i++) {
+            selectCtrl.options[i0 + i] = new Option(educationDegreeName[educationDegree[edu][i] - 1], educationDegree[edu][i]);
+        }
+    } else if (fill) {
+        for (i = 0; i < educationDegreeAll.length; i++) {
+            selectCtrl.options[i0 + i] = new Option(educationDegreeName[educationDegreeAll[i] - 1], educationDegreeAll[i]);
+        }
     }
-    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 selectType(selectCtrl, type)
 {
     for (i = 0; i < selectCtrl.options.length; i++) {
-        if (selectCtrl.options[i].text == type)
-            selectCtrl.selectedIndex=i;
+        if (selectCtrl.options[i].value == type) {
+            selectCtrl.selectedIndex = i;
+        }
     }
 }
 
+function prepareType(i)
+{
+    fillType(document.forms.prof_annu["edus[" + i + "][degreeid]"], document.forms.prof_annu["edus[" + i + "][eduid]"].selectedIndex - 1);
+    selectType(document.forms.prof_annu["edus[" + i + "][degreeid]"], document.forms.prof_annu["edu_" + i + "_tmp"].value);
+}
+
 function addSearchName()
 {
   var i = 0;
@@ -110,42 +125,59 @@ function removeSearchName(i)
   }
 }
 
+function delNationality(i)
+{
+    $('#nationalite' + i).hide().find('select').val('');
+}
+
+function addNationality()
+{
+    var i = 0;
+    if ($('#nationalite2').find('select').val() == "") {
+        i = 2;
+    } else if ($('#nationalite3').find('select').val() == "") {
+        i = 3;
+    }
+    if ((i == 2) || (i == 3)) {
+        $('#nationalite' + i).show();
+    }
+}
+
 function addNetworking()
 {
     var i = 0;
-    var nw = 'networking_';
-    while (document.getElementById(nw + i) != null) {
+    var nws = 'networking_';
+    while (document.getElementById(nws + i) != null) {
         i++;
     }
-    var cb   = document.forms.prof_annu['nw_type'];
-    var id   = cb.value;
-    var text = cb.options[cb.selectedIndex].text;
+    var namefirst = '';
     var html = '<tr id="networking_' + i + '">'
-        + '  <td>'
-        + '    <span class="flags">'
-        + '      <input type="checkbox" name="networking[' + i + '][pub]"/>'
-        + '      <img src="images/icons/flag_green.gif" alt="site public" title="site public">'
-        + '    </span>&nbsp;'
-        + '    <input type="hidden" name="networking[' + i + '][type]" value="' + id + '"/>'
-        + '    <input type="hidden" name="networking[' + i + '][name]" value="' + text + '"/>'
-        + '    <img src="profile/networking/' + id + '" alt="' + text + '" title="' + text + '" />'
-        + '    <span class="title">'
-        + text
-        + '    </span>'
-        + '  </td>'
-        + '  <td>'
-        + '    <input type="text" name="networking[' + i + '][address]" value="" size="30"/>'
-        + '    <a href="javascript:removeNetworking(' + i + ')">'
-        + '      <img src="images/icons/cross.gif" alt="cross" title="Supprimer cet élément"/>'
-        + '    </a>'
+        + '  <td colspan="2">'
+        + '    <div style="float: left; width: 200px;">'
+        + '      <span class="flags">'
+        + '        <input type="checkbox" name="networking[' + i + '][pub]"/>'
+        + '        <img src="images/icons/flag_green.gif" alt="site public" title="site public">'
+        + '      </span>&nbsp;'
+        + '      <select id="networking_type_' + i + '" name="networking[' + i + '][type]" onchange="javascript:updateNetworking(' + i + ');">';
+    for (nw in nw_list) {
+        if (namefirst == '') {
+            namefirst = nw;
+        }
+        html += '  <option value="' + nw_list[nw] + '">' + nw + '</option>';
+    }
+    html += '</select>'
+        + '      <input type="hidden" id="networking_name_' + i + '" name="networking[' + i + '][name]" value="' + namefirst + '"/>'
+        + '    </div>'
+        + '    <div style="float: left">'
+        + '      <input type="text" name="networking[' + i + '][address]" value="" size="30"/>'
+        + '      <a href="javascript:removeNetworking(' + i + ')">'
+        + '        <img src="images/icons/cross.gif" alt="cross" title="Supprimer cet élément"/>'
+        + '      </a>'
+        + '    </div>'
         + '  </td>'
         + '</tr>';
 
-    if (i == 0) {
-        $('#networking').after(html);
-    } else {
-        $('#networking_'+(i-1)).after(html);
-    }
+    $('#networking').before(html);
 }
 
 function removeNetworking(id)
@@ -153,14 +185,14 @@ function removeNetworking(id)
     $('#networking_' + id).remove();
 }
 
-function updateNetworking()
+function updateNetworking(i)
 {
-    var val = document.forms.prof_annu['nw_type'].value;
-    if (val == '') {
-        document.getElementById('nw_add').style.display = 'none';
-    } else {
-        document.getElementById('nw_add').style.display = '';
+    var name = document.getElementById('networking_name_' + i);
+    var type = document.getElementById('networking_type_' + i);
+    if (type != null && name != null) {
+        name.value = type.options[type.selectedIndex].text;
     }
+
 }
 
 // Addresses
@@ -238,18 +270,60 @@ function addAddress()
     Ajax.update_html('addresses_' + i + '_cont', 'profile/ajax/address/' + i, checkCurrentAddress);
 }
 
-function addTel(id)
+function addEdu()
+{
+    var i = 0;
+    var prefix  = 'edu_';
+    var class_parity;
+
+    while ($('.' + prefix + i).length != 0) {
+        i++;
+    }
+    if (i % 2) {
+        class_parity = 'pair';
+    } else {
+        class_parity = 'impair';
+    }
+    $.get(platal_baseurl + 'profile/ajax/edu/' + i + '/' + class_parity,
+          function(data) {
+              $('#edu_add').before(data);
+              prepareType(i);
+          });
+}
+
+function removeEdu(id)
+{
+    $('.' + id).remove();
+}
+
+function addTel(prefid, prefname)
 {
     var i = 0;
-    var adid = 'addresses_' + id;
-    var tel  = adid + '_tel_';
-    while (document.getElementById(tel + i) != null) {
+    var prefix  = prefid + '_';
+    while (document.getElementById(prefix + i) != null) {
         i++;
     }
-    $('#' + adid + '_add_tel').before('<div id="' + tel + i + '" style="clear: both"></div>');
-    Ajax.update_html(tel + i, 'profile/ajax/tel/' + id + '/' + i);
+    $('#' + prefix + 'add').before('<div id="' + prefix + i + '" style="clear: both; padding-top: 4px; padding-bottom: 4px"></div>');
+    Ajax.update_html(prefix + i, 'profile/ajax/tel/' + prefid + '/' + prefname + '/' + i);
+}
+
+function removeTel(id)
+{
+    $('#' + id).remove();
 }
 
+function addPhoneComment(id, pref)
+{
+    document.getElementById(id+'_comment').style.display = '';
+    document.getElementById(id+'_addComment').style.display = 'none';
+}
+
+function removePhoneComment(id, pref)
+{
+    document.getElementById(id+'_comment').style.display = 'none';
+    document.forms.prof_annu[pref+ '[comment]'].value = '';
+    document.getElementById(id+'_addComment').style.display = '';
+}
 
 // Geoloc