Fixes deletion of new added searchnames.
[platal.git] / htdocs / javascript / profile.js
index 70159b3..25b7214 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *  Copyright (C) 2003-2009 Polytechnique.org                              *
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -67,22 +67,22 @@ function toggleNamesAdvanced()
     $('.names_advanced').toggle();
 }
 
-function addSearchName()
+function addSearchName(isFemale)
 {
     var i = 0;
     while ($('#search_name_' + i).length != 0) {
         i++;
     }
-    Ajax.update_html('search_name_' + i, 'profile/ajax/searchname/' + i, function(data){
+    Ajax.update_html('search_name_' + i, 'profile/ajax/searchname/' + i + '/' + isFemale, function(data){
         $('#searchname').before(data);
         changeNameFlag(i);
     });
 }
 
-function removeSearchName(i)
+function removeSearchName(i, isFemale)
 {
     $('#search_name_' + i).remove();
-    updateNameDisplay();
+    updateNameDisplay(isFemale);
 }
 
 function changeNameFlag(i)
@@ -104,7 +104,7 @@ function changeNameFlag(i)
     }
 }
 
-function updateNameDisplay()
+function updateNameDisplay(isFemale)
 {
     var searchnames = '';
     for (var i = 0; i < 10; i++) {
@@ -113,30 +113,46 @@ function updateNameDisplay()
             searchnames += $('#search_name_' + i).find(':text').val() + ';;';
         }
     }
-    Ajax.update_html(null, 'profile/ajax/buildnames/' + searchnames, function(data){
+    Ajax.update_html(null, 'profile/ajax/buildnames/' + searchnames + '/' + isFemale, function(data){
         var name = data.split(';');
         $('#public_name').html(name[0]);
         $('#private_name').html(name[0] + name[1]);
     });
 }
 
+function toggleParticle(id)
+{
+    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();
+}
+
 // Nationalities {{{1
 
 function delNationality(i)
 {
-    $('#nationalite' + i).hide().find('select').val('');
+    $('#nationality' + i).hide().find('select').val('');
 }
 
 function addNationality()
 {
     var i = 0;
-    if ($('#nationalite2').find('select').val() == "") {
+    if ($('#nationality2').find('select').val() == "") {
         i = 2;
-    } else if ($('#nationalite3').find('select').val() == "") {
+    } else if ($('#nationality3').find('select').val() == "") {
         i = 3;
     }
     if ((i == 2) || (i == 3)) {
-        $('#nationalite' + i).show();
+        $('#nationality' + i).show();
     }
 }
 
@@ -335,15 +351,15 @@ function removeTel(id)
 
 function addPhoneComment(id)
 {
-    $(id + '_comment').show();
-    $(id + '_addComment').hide();
+    $('#' + id + '_comment').show();
+    $('#' + id + '_addComment').hide();
 }
 
 function removePhoneComment(id, pref)
 {
-    $(id + '_comment').hide();
-    $(id + '_comment').find("[name='" + pref + "[comment]']").val('');
-    $(id + '_addComment').show();
+    $('#' + id + '_comment').hide();
+    $('#' + id + '_comment').find("[name='" + pref + "[comment]']").val('');
+    $('#' + id + '_addComment').show();
 }
 
 // {{{1 Groups
@@ -360,7 +376,7 @@ function addBinet()
              + '    <div style="float: left; width: 70%">'
              +        text
              + '    </div>'
-             + '    <a href="javascript:removeElement(\'binets\', ' + id + ')">'
+             + '    <a href="javascript:removeElement(\'binets\',' + id + ')">'
              + '      <img src="images/icons/cross.gif" alt="cross" title="Supprimer ce groupe" />'
              + '    </a>'
              + '  </td>'
@@ -483,6 +499,16 @@ function updateJobAlternates(id)
     }
 }
 
+function emptyJobSubSector(id)
+{
+    Ajax.update_html('job_' + id + '_subSubSector', 'profile/ajax/sub_sector/' + id + '/-1/-1');
+}
+
+function emptyJobAlternates(id)
+{
+    Ajax.update_html('job_' + id + '_alternates', 'profile/ajax/alternates/' + id + '/-1');
+}
+
 function displayAllSector(id)
 {
     $('.sector_text_' + id).remove();
@@ -533,7 +559,7 @@ function addCountry()
     var val  = $('#countries_table').find('[name=countries_sel] :selected').val();
     var text = $('#countries_table').find('[name=countries_sel] :selected').text();
     var html = '<div id="countries_' + val + '" style="clear: both; margin-bottom: 0.7em">'
-        + '  <a href="javascript:removeElement(\'countries\', \'' + val + '\')" style="display: block; float:right">'
+        + '  <a href="javascript:removeElement(\'countries\',\'' + val + '\')" style="display: block; float:right">'
         + '    <img src="images/icons/cross.gif" alt="" title="Supprimer ce pays" />'
         + '  </a>'
         + '  <div style="float: left; width: 50%">' + text + '</div>'
@@ -585,7 +611,7 @@ function addSector()
     var sst = $('#subSectorSelection').find("[name='jobs[-1][subSector]'] :selected").text();
 
     var html = '<div id="sectors_' + s + '_' + ss + '" style="clear: both; margin-top: 0.5em" class="titre">'
-             + '  <a href="javascript:removeSector(\'' + s + '\', \'' + ss + '\')" style="display: block; float: right">'
+             + '  <a href="javascript:removeSector(\'' + s + '\',\'' + ss + '\')" style="display: block; float: right">'
              + '    <img src="images/icons/cross.gif" alt="" title="Supprimer ce secteur" />'
              + '  </a>'
              + '  <input type="hidden" name="sectors[' + s + '][' + ss + ']" value="' + sst + '" />'