From: Paul Hänsch Date: Mon, 5 Aug 2019 23:19:15 +0000 (+0200) Subject: field deletion X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=d6e018a83d2f0305b773ec01d8c27f8ce930a9b5;p=lobster field deletion --- 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