Remove deprecated stuff, cleanup code.
[platal.git] / htdocs / javascript / profile.js
index 4b3c470..42921df 100644 (file)
@@ -29,6 +29,7 @@ function wizPage_onLoad(id)
         while ($('.' + prefix + i).length != 0) {
             i++;
         }
+        i--;
         for (var j = 0; j < i; j++) {
             prepareType(j);
         }
@@ -50,8 +51,10 @@ function wizPage_onLoad(id)
         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);
+            updateJobSousSecteur(i, 'job_' + i, 'jobs[' + i + ']',
+                             document.forms.prof_annu["jobs[" + i + "][sss_secteur]"].value);
         }
-        registerEnterpriseAutocomplete(-1);
+        setTimeout('registerEnterpriseAutocomplete(-1)', 100);
         break;
     }
 }
@@ -273,17 +276,25 @@ function addAddress()
 function addEdu()
 {
     var i = 0;
+    var j = 0;
     var prefix  = 'edu_';
     var class_parity;
 
-    while ($('.' + prefix + i).length != 0) {
+    while (!$('#edu_add').hasClass(prefix + i)) {
+        if ($('.' + prefix + i).length != 0) {
+            j++;
+        }
         i++;
     }
-    if (i % 2) {
+    if (j % 2) {
         class_parity = 'pair';
     } else {
         class_parity = 'impair';
     }
+    $('#edu_add').removeClass(prefix + i);
+    i++;
+    $('#edu_add').addClass(prefix + i);
+    i--;
     $.get(platal_baseurl + 'profile/ajax/edu/' + i + '/' + class_parity,
           function(data) {
               $('#edu_add').before(data);
@@ -291,9 +302,15 @@ function addEdu()
           });
 }
 
-function removeEdu(id)
+function removeEdu(i)
 {
-    $('.' + id).remove();
+    var prefix  = 'edu_';
+    $('.' + prefix + i).remove();
+    while (!$('#edu_add').hasClass(prefix + i)) {
+        $('.' + prefix + i).toggleClass('pair');
+        $('.' + prefix + i).toggleClass('impair');
+        i++;
+    }
 }
 
 function addTel(prefid, prefname)
@@ -335,8 +352,7 @@ function validGeoloc(id, pref)
     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;
-    attachEvent(document.forms.prof_annu[pref + "[text]"], "click",
-                function() { document.forms.prof_annu[pref + "[text]"].blur(); });
+    $(document.forms.prof_annu[pref + "[text]"]).click(function() { document.forms.prof_annu[pref + "[text]"].blur(); });
     document.forms.prof_annu[pref + "[text]"].className = '';
 }
 
@@ -346,8 +362,7 @@ function validAddress(id, pref)
     document.getElementById(id + '_geoloc_error').style.display = 'none';
     document.getElementById(id + '_geoloc_valid').style.display = 'none';
     document.forms.prof_annu[pref + "[parsevalid]"].value = "1";
-    attachEvent(document.forms.prof_annu[pref + "[text]"], "click",
-                function() { document.forms.prof_annu[pref + "[text]"].blur(); });
+    $(document.forms.prof_annu[pref + "[text]"]).click(function() { document.forms.prof_annu[pref + "[text]"].blur(); });
     document.forms.prof_annu[pref + "[text]"].className = '';
 }
 
@@ -489,7 +504,22 @@ function updateJobSecteur(nb, id, pref, sel)
     if (secteur == '') {
         secteur = '-1';
     }
-    Ajax.update_html(id + '_ss_secteur', 'profile/ajax/secteur/' +nb + '/' + secteur + '/' + sel);
+    Ajax.update_html(id + '_ss_secteur', 'profile/ajax/secteur/' + nb + '/' + id + '/' + pref + '/' + secteur + '/' + sel);
+}
+
+function updateJobSousSecteur(nb, id, pref, sel)
+{
+    var ssecteur = document.forms.prof_annu[pref + '[ss_secteur]'].value;
+    if (ssecteur == '') {
+        ssecteur = '-1';
+    }
+    Ajax.update_html(id + '_sss_secteur', 'profile/ajax/ssecteur/' + nb + '/' + ssecteur + '/' + sel);
+}
+
+function displayAllSector(id)
+{
+    $('.sector_text_' + id).remove();
+    $('.sector_' + id).show();
 }
 
 function makeAddJob(id)
@@ -511,6 +541,10 @@ function addJob()
     $.get(platal_baseurl + 'profile/ajax/job/' + i, makeAddJob(i));
 }
 
+function addEntreprise(id)
+{
+    $('.entreprise_' + id).toggle();
+}
 
 // Skills
 
@@ -605,13 +639,13 @@ function updateSecteur()
         document.getElementById('ss_secteur_sel').innerHTML = '';
         return;
     }
-    $.get(platal_baseurl + 'profile/ajax/secteur/-1/' + secteur,
+    $.get(platal_baseurl + 'profile/ajax/secteur/-1/0/0/' + secteur,
           function(data) {
-          data = '<a href="javascript:addSecteur()" style="display: none; float: right" id="secteurs_add">'
-          +  '  <img src="images/icons/add.gif" alt="" title="Ajouter ce secteur" />'
-          +  '</a>' + data;
-          document.getElementById('ss_secteur_sel').innerHTML = data;
-          attachEvent(document.forms.prof_annu['jobs[-1][ss_secteur]'], 'change', updateSSecteur);
+              data = '<a href="javascript:addSecteur()" style="display: none; float: right" id="secteurs_add">'
+                     +  '  <img src="images/icons/add.gif" alt="" title="Ajouter ce secteur" />'
+                     +  '</a>' + data;
+              document.getElementById('ss_secteur_sel').innerHTML = data;
+              $(document.forms.prof_annu['jobs[-1][ss_secteur]']).change(updateSSecteur);
           });
 }
 
@@ -657,6 +691,20 @@ function registerEnterpriseAutocomplete(id)
         }
       }
     );
+
+    $(".sector_name").each(
+      function() {
+        if (id == -1 || this.name == "jobs[" + id + "][sss_secteur_name]") {
+            $(this).autocomplete(platal_baseurl + "search/autocomplete/sss_secteur",
+                                 {
+                                   selectOnly:1,
+                                   field:this.name,
+                                   matchSubset:0,
+                                   width:$(this).width()
+                                 });
+        }
+      }
+    );
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: