From d6e018a83d2f0305b773ec01d8c27f8ce930a9b5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Tue, 6 Aug 2019 01:19:15 +0200 Subject: [PATCH] field deletion --- cards/list.sh | 6 +++--- cards/update_card.sh | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cards/list.sh b/cards/list.sh index 0ef5eba..825b683 100755 --- a/cards/list.sh +++ b/cards/list.sh @@ -131,7 +131,7 @@ edit_item(){ ADR|NOTE) printf '[h3 %s]' "$(l10n "$item")" seq 1 $cnt |while read c; do - printf '[checkbox "%s_delete" "%i" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \ + printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \ "$item" $c "$item" $c "$item" $c "$(l10n delete)" printf '' \ "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)" @@ -139,7 +139,7 @@ edit_item(){ ;; TEL) printf '[h3 %s]' "$(l10n "$item")" seq 1 $cnt |while read c; do - printf '[checkbox "%s_delete" "%i" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \ + printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \ "$item" $c "$item" $c "$item" $c "$(l10n delete)" teltype="$(pdi_attrib "$card" TEL $c TYPE)" printf '[select .item .teltype name="teltype" @@ -161,7 +161,7 @@ edit_item(){ ;; *)printf '[h3 %s]' "$(l10n "$item")" seq 1 $cnt |while read c; do - printf '[checkbox "%s_delete" "%i" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \ + printf '[checkbox "%s_delete_%i" "true" .delete #%s_delete_%i][label for="%s_delete_%i" %s]' \ "$item" $c "$item" $c "$item" $c "$(l10n delete)" printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \ "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)" "$(l10n "$item")" diff --git a/cards/update_card.sh b/cards/update_card.sh index 1975e4e..52ccfcd 100755 --- a/cards/update_card.sh +++ b/cards/update_card.sh @@ -72,6 +72,16 @@ for field in $(POST_KEYS |grep -xE '[A-Z][A-Z0-9-]*'); do esac done; done +# delete fields, first mark for deletion using delete_key +# this way the field enumeration is preserved during the process +# finally filter marked lines +delete_key="$(randomid)" +for delete in $(POST_KEYS |grep -xE '[A-Z][A-Z0-9-]*_delete_[0-9]+'); do + f="${delete%%_*}"; c="${delete##*_}"; + [ "$(POST "$delete")" = "true" ] && vcf="$(pdi_update_value "$vcf" "$f" "$c" "delete=${delete_key}")" +done +vcf="$(printf '%s\n' "$vcf" |sed -E "/^[^:]+:delete=${delete_key}\$/d")" + if [ "$action" = addfield ]; then vcf="$(pdi_update_value "$vcf" "$newfield" $(( $(pdi_count "$vcf" "$newfield") + 1 )) '')" fi -- 2.39.2