From ed01acac4af9b0df4209b3e6e3e7d10284c76b9c Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Fri, 25 Jun 2010 21:18:52 +0200 Subject: [PATCH] Keeps numbering of jobs, addresses and phones between 1 and their current total (Closes #1096). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- htdocs/javascript/profile.js | 30 +++++++++++++++++++++++++++++- modules/profile/addresses.inc.php | 2 +- modules/profile/jobs.inc.php | 2 +- modules/profile/page.inc.php | 31 ++++++++++++++----------------- templates/profile/phone.tpl | 5 ++--- 5 files changed, 47 insertions(+), 23 deletions(-) diff --git a/htdocs/javascript/profile.js b/htdocs/javascript/profile.js index 25b7214..ef96031 100644 --- a/htdocs/javascript/profile.js +++ b/htdocs/javascript/profile.js @@ -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() diff --git a/modules/profile/addresses.inc.php b/modules/profile/addresses.inc.php index 6ff3f24..4e6d51b 100644 --- a/modules/profile/addresses.inc.php +++ b/modules/profile/addresses.inc.php @@ -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; diff --git a/modules/profile/jobs.inc.php b/modules/profile/jobs.inc.php index 5245a2f..f50e762 100644 --- a/modules/profile/jobs.inc.php +++ b/modules/profile/jobs.inc.php @@ -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) { diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index 8d3fb84..9d0521e 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -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; } diff --git a/templates/profile/phone.tpl b/templates/profile/phone.tpl index 056d85a..c588e84 100644 --- a/templates/profile/phone.tpl +++ b/templates/profile/phone.tpl @@ -29,9 +29,8 @@ - - + {icon name=cross title="Supprimer ce numéro de téléphone"} @@ -44,7 +43,7 @@ -- 2.1.4