Keeps numbering of jobs, addresses and phones between 1 and their current total ...
authorStéphane Jacob <sj@m4x.org>
Fri, 25 Jun 2010 19:18:52 +0000 (21:18 +0200)
committerStéphane Jacob <sj@m4x.org>
Fri, 25 Jun 2010 19:18:59 +0000 (21:18 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
htdocs/javascript/profile.js
modules/profile/addresses.inc.php
modules/profile/jobs.inc.php
modules/profile/page.inc.php
templates/profile/phone.tpl

index 25b7214..ef96031 100644 (file)
@@ -346,7 +346,14 @@ function addTel(prefid, prefname)
 
 function removeTel(id)
 {
-    $('#' + id).remove();
+    var total = 0;
+    while ($('#tels_' + total).length != 0) {
+        ++total;
+    }
+    $('#tels_' + id).remove();
+    for (var i = parseInt(id) + 1; i < total; ++i) {
+        renumberPhone(i);
+    }
 }
 
 function addPhoneComment(id)
@@ -362,6 +369,27 @@ function removePhoneComment(id, pref)
     $('#' + id + '_addComment').show();
 }
 
+function renumberPhone(i)
+{
+    var telid = i - 1;
+    var telprefOld = 'tels[' + i + ']';
+    var telpref = 'tels[' + telid + ']';
+    var idOld = 'tels_' + i;
+    var id = 'tels_' + telid;
+
+    $('#tels_' + i).attr('id', 'tels_' + telid);
+    $('#tels_' + telid).find('div.titre').html('N°' + i);
+    $('#tels_' + telid).find('a.removeTel').attr('href', 'javascript:removeTel(' + telid + ')');
+    $('#tels_' + telid).find('select').attr('name', telpref + '[type]');
+    $('#tels_' + telid).find("[name='" + telprefOld + "[tel]']").attr('name', telpref + '[tel]');
+    $('#tels_' + telid).find("[name='" + telprefOld + "[comment]']").attr('name', telpref + '[comment]');
+    $('#tels_' + telid).find('a.removePhoneComment').attr('href', 'javascript:removePhoneComment(' + id + ',' + telpref + ')');
+    $('#tels_' + telid).find('#' + idOld + '_addComment').attr('id', id + '_addComment');
+    $('#tels_' + telid).find('#' + id + '_addComment').attr('href', 'javascript:addPhoneComment(' + id + ')');
+    $('#tels_' + telid).find('#' + idOld + '_comment').attr('id', id + '_comment');
+    $('#tels_' + telid).find("[name='" + telprefOld + "[pub]']").attr('name', telpref + '[pub]');
+}
+
 // {{{1 Groups
 
 function addBinet()
index 6ff3f24..4e6d51b 100644 (file)
@@ -53,7 +53,7 @@ class ProfileSettingAddress extends ProfileSettingGeocoding
         }
         foreach ($value as $key => &$address) {
             if (isset($address['removed']) && $address['removed']) {
-                unset($value[$key]);
+                array_splice($value, $key, 1);
             }
         }
         $current = 0;
index 5245a2f..f50e762 100644 (file)
@@ -200,7 +200,7 @@ class ProfileSettingJob extends ProfileSettingGeocoding
                 $success = false;
             }
             if (isset($job['removed']) && $job['removed']) {
-                unset($value[$key]);
+                array_splice($value, $key, 1);
             }
         }
         foreach ($value as $key => &$job) {
index 8d3fb84..9d0521e 100644 (file)
@@ -153,26 +153,23 @@ class ProfileSettingPhones implements ProfileSetting
                         );
             }
         }
+
         foreach ($value as $key=>&$phone) {
-            if (isset($phone['removed']) && $phone['removed']) {
-                unset($value[$key]);
-            } else {
-                unset($phone['removed']);
-                $phone['pub'] = $this->pub->value($page, 'pub', $phone['pub'], $s);
-                $phone['tel'] = $this->tel->value($page, 'tel', $phone['tel'], $s);
-                if(!isset($phone['type']) || ($phone['type'] != 'fixed' && $phone['type'] != 'mobile' && $phone['type'] != 'fax')) {
-                    $phone['type'] = 'fixed';
-                    $s = false;
-                }
-                if (!$s) {
-                    $phone['error'] = true;
-                    $success = false;
-                }
-                if (!isset($phone['comment'])) {
-                    $phone['comment'] = '';
-                }
+            $phone['pub'] = $this->pub->value($page, 'pub', $phone['pub'], $s);
+            $phone['tel'] = $this->tel->value($page, 'tel', $phone['tel'], $s);
+            if(!isset($phone['type']) || ($phone['type'] != 'fixed' && $phone['type'] != 'mobile' && $phone['type'] != 'fax')) {
+                $phone['type'] = 'fixed';
+                $s = false;
+            }
+            if (!$s) {
+                $phone['error'] = true;
+                $success = false;
+            }
+            if (!isset($phone['comment'])) {
+                $phone['comment'] = '';
             }
         }
+
         return $value;
     }
 
index 056d85a..c588e84 100644 (file)
@@ -29,9 +29,8 @@
     <option value="mobile"{if $tel.type eq 'mobile'} selected="selected"{/if}>Mobile</option>
     <option value="fax"{if $tel.type eq 'fax'} selected="selected"{/if}>Fax</option>
   </select>
-  <input type="hidden" name="{$telpref}[removed]" value="0"/>
   <input type="text" size="19" maxlength="28" name="{$telpref}[tel]" {if $tel.error}class="error"{/if} value="{$tel.tel}" />
-  <a href="javascript:removeTel('{$id}')">
+  <a class="removeTel" href="javascript:removeTel('{$telid}')">
     {icon name=cross title="Supprimer ce numéro de téléphone"}
   </a>
   <a id="{$id}_addComment" href="javascript:addPhoneComment('{$id}')" {if $tel.comment neq ''}style="display:none" {/if}>
@@ -44,7 +43,7 @@
 <div id="{$id}_comment" style="clear: both;{if $tel.comment eq ''} display:none{/if}">
   Commentaire :
   <input type="text" size="45" maxlength="80" name="{$telpref}[comment]" {if $tel.error}class="error"{/if} value="{$tel.comment}"/>
-  <a href="javascript:removePhoneComment('{$id}','{$telpref}')">
+  <a class="removePhoneComment" href="javascript:removePhoneComment('{$id}','{$telpref}')">
     {icon name=cross title="Supprimer le commentaire"}
   </a>
 </div>