Adds field for sports and hobbies (Closes #1446).
[platal.git] / htdocs / javascript / profile.js
index b95aa03..6858861 100644 (file)
@@ -77,12 +77,10 @@ function addSearchName(isFemale)
     while ($('#search_name_' + i).length != 0) {
         i++;
     }
-    $('#search_name_' + i)
-        .updateHtml('profile/ajax/searchname/' + i + '/' + isFemale,
-                    function(data) {
-                        $('#searchname').before(data);
-                        changeNameFlag(i);
-                    });
+    $('#search_name_' + i).updateHtml('profile/ajax/searchname/' + i + '/' + isFemale,
+        function(data) {
+            $('#searchname').before(data);
+    });
 }
 
 function removeSearchName(i, isFemale)
@@ -91,34 +89,29 @@ function removeSearchName(i, isFemale)
     updateNameDisplay(isFemale);
 }
 
-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('<span id="flag_' + i + '">&nbsp;' +
-            '<img src="images/icons/flag_green.gif" alt="site public" title="site public" />' +
-            '<input type="hidden" name="search_names[' + i + '][pub]" value="1"/>' +
-            '<input type="hidden" name="search_names[' + i + '][typeid]" value="' + typeid + '"/>' +
-            '<input type="hidden" name="search_names[' + i + '][type]" value="' + type + '"/></span>');
-    } else {
-        $('#flag_cb_' + i).after('<span id="flag_' + i + '">&nbsp;' +
-            '<img src="images/icons/flag_red.gif" alt="site privé" title="site privé" />' +
-            '<input type="hidden" name="search_names[' + i + '][typeid]" value="' + typeid + '"/>' +
-            '<input type="hidden" name="search_names[' + i + '][type]" value="' + type + '"/></span>');
-    }
-}
-
 function updateNameDisplay(isFemale)
 {
+    var lastnames = new Array('lastname_main', 'lastname_ordinary', 'lastname_marital', 'pseudonym');
+    var firstnames = new Array('firstname_main', 'firstname_ordinary');
     var searchnames = '';
-    for (var i = 0; i < 10; i++) {
+
+    for (var i = 0; i < 4; ++i) {
+        searchnames += $('.names_advanced').find('[name*=' + lastnames[i] + ']').val() + ';';
+    }
+    searchnames += '-;'
+    for (var i = 0; i < 2; ++i) {
+        searchnames += $('.names_advanced').find('[name*=' + firstnames[i] + ']').val() + ';';
+    }
+    searchnames += '-';
+
+    var has_private = false;
+    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() + ';;';
+            searchnames += ';' + $('#search_name_' + i).find('[name*=type]').val() + ';' + $('#search_name_' + i).find(':text').val();
+            has_private = true;
         }
     }
+    searchnames += (has_private ? '' : ';');
     $.xget('profile/ajax/buildnames/' + searchnames + '/' + isFemale,
            function(data){
                var name = data.split(';');
@@ -127,15 +120,6 @@ function updateNameDisplay(isFemale)
            });
 }
 
-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()
@@ -277,6 +261,44 @@ function updateNetworking(i)
     $('#networking_' + i).find("[name='networking[" + i + "][name]']").val($('#networking_' + i).find('select option:selected').text());
 }
 
+// Hobby {{{1
+
+function addHobby()
+{
+    var i = 0;
+    while ($('#hobby_' + i).length != 0) {
+        ++i;
+    }
+    var html = '<tr id="hobby_' + i + '">'
+        + '  <td colspan="2">'
+        + '    <div style="float: left; width: 200px;">'
+        + '      <span class="flags">'
+        + '        <input type="checkbox" name="hobbies[' + i + '][pub]"/>'
+        + '        <img src="images/icons/flag_green.gif" alt="site public" title="site public">'
+        + '      </span>&nbsp;'
+        + '      <select name="hobbies[' + i + '][type]">'
+        + '        <option value="Sport">Sport</option>'
+        + '        <option value="Loisir">Loisir</option>'
+        + '        <option value="Hobby">Hobby</option>'
+        + '      </select>'
+        + '    </div>'
+        + '    <div style="float: left">'
+        + '      <input type="text" name="hobbies[' + i + '][text]" value="" size="30"/>'
+        + '      <a href="javascript:removeHobby(' + i + ')">'
+        + '        <img src="images/icons/cross.gif" alt="cross" title="Supprimer cet élément"/>'
+        + '      </a>'
+        + '    </div>'
+        + '  </td>'
+        + '</tr>';
+
+    $('#hobby').before(html);
+}
+
+function removeHobby(id)
+{
+    $('#hobby_' + id).remove();
+}
+
 // Addresses {{{1
 
 function toggleAddress(id, val)
@@ -317,35 +339,46 @@ function checkCurrentAddress(id)
     }
 }
 
-function addAddress()
+function addAddress(pid)
 {
     var i = 0;
     while ($('#addresses_' + i + '_cont').length != 0) {
         i++;
     }
     $('#add_address').before('<div id="addresses_' + i + '_cont"></div>');
-    $('#addresses_' + i + '_cont').updateHtml('profile/ajax/address/' + i,
+    $('#addresses_' + i + '_cont').updateHtml('profile/ajax/address/' + i + '/' + pid,
                                               checkCurrentAddress());
 }
 
-function addressChanged(prefid)
+function addressChanged(prefid, color)
 {
+    var text = $('#' + prefid + '_cont').find("[name*='[text]']").val();
     $('#' + prefid + '_cont').find('[name*=changed]').val("1");
+    $.xpost('map_url/', { text:text, color:color }, function(data) {
+        if (data) {
+            $('#' + prefid + '_static_map_url').show();
+            $('#' + prefid + '_static_map_url').find('img').attr('src', data);
+        } else {
+            $('#' + prefid + '_static_map_url').hide();
+            $('#' + prefid + '_geocoding_removal').find('[name*=request]:checkbox').removeAttr('checked');
+        }
+    });
 }
 
-function deleteGeocoding()
+function deleteGeocoding(prefid)
 {
-    var confirmation = confirm(
+    if($('#' + prefid + '_geocoding_removal').find('[name*=request]:checkbox:checked').length == 0) {
+        return true;
+    }
+
+    return confirm(
         "La localisation de l'adresse sert à deux choses : te placer dans "
         + "le planisphère et te faire apparaître dans la recherche avancée par "
-        + "pays, région, département, ville. La supprimer t'en fera disparaître. "
+        + "pays, région, département, ville... La supprimer t'en fera disparaître. "
         + "\nIl ne faut le faire que si cette localisation "
         + "est réellement erronée. Avant de supprimer cette localisation, l'équipe de "
         + "Polytechnique.org tentera de la réparer.\n\nConfirmes-tu ta "
         + "demande de suppression de cette localisation ?");
-    if (confirmation) {
-        alert('Warning: not implemented yet.');
-    }
 }
 
 // {{{1 Phones
@@ -559,13 +592,13 @@ function makeAddJob(id)
     };
 }
 
-function addJob()
+function addJob(pid)
 {
     var i = 0;
     while ($('#jobs_' + i).length != 0) {
         ++i;
     }
-    $.xget('profile/ajax/job/' + i, makeAddJob(i));
+    $.xget('profile/ajax/job/' + i + '/' + pid, makeAddJob(i));
 }
 
 function addEntreprise(id)