Adds field for sports and hobbies (Closes #1446).
[platal.git] / htdocs / javascript / profile.js
index 2057e69..6858861 100644 (file)
@@ -261,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)
@@ -301,34 +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 validGeoloc(prefid, id, geoloc)
+function deleteGeocoding(prefid)
 {
-    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();
+    if($('#' + prefid + '_geocoding_removal').find('[name*=request]:checkbox:checked').length == 0) {
+        return true;
     }
-    $('#' + prefid + '_cont').find('[name*=text]').removeClass('error');
-    $('#' + prefid + '_cont').find('[name*=geocodeChosen]').val(geoloc);
-    $('.' + prefid + '_geoloc').remove();
+
+    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. "
+        + "\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 ?");
 }
 
 // {{{1 Phones
@@ -542,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)