From: Paul Hänsch Date: Tue, 20 Aug 2019 00:03:46 +0000 (+0200) Subject: new cards function X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=11e258b8e6cf832c96b20648aa8c9ca0288c597f;p=confetti new cards function --- diff --git a/cards/cards.css b/cards/cards.css index 9adbeca..6349f8a 100644 --- a/cards/cards.css +++ b/cards/cards.css @@ -103,10 +103,13 @@ .newcard { display: block; border: solid 1px; - border-radius: 0 0 4px 4px; - margin: .25em 2em 1em 2em; - padding: .25em 2ex .25em 2ex; - background: #EFF; + margin: 1em 2em .5em 2em; + padding: .5em; + text-align: right; + background: #EEF; +} +.newcard button { + box-shadow: 0 0 .5ex #888; } .card { @@ -129,7 +132,7 @@ height: 100%; width: 20ex; max-width: 33%; - padding: .25em 1ex; + padding: .25em .5em; } .card .control .item { display: inline-block; @@ -185,8 +188,8 @@ display: inline-block; vertical-align: top; float: left; - width: 20ex; - min-width: 16.5%; + width: 16.625%; + min-width: 10em; min-height: 6em; margin: .125em 0 .5ex 0; padding: 0 1ex .25em 1ex; diff --git a/cards/list.sh b/cards/list.sh index 8f3b720..6c0f18b 100755 --- a/cards/list.sh +++ b/cards/list.sh @@ -2,178 +2,6 @@ . "${_EXEC}"/pdiread.sh -unescape() { [ $# = 0 ] && sed -E 's;\\(.);\1;g' || printf %s "$*" |sed -E 's;\\(.);\1;g'; } -upcase=' y;abcdefghijklmnopqrstuvwxyzäöüé;ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜÉ;; ' - -card_item(){ - local card="$1" - local item cnt c - shift 1 - - for item in $@; do - cnt="$(pdi_count "$card" "$item")" - - case $item in - FN) printf '[h2 .item .FN ­%s]' "$(pdi_value "$card" FN |unescape |HTML)" - ;; - GENDER) printf '[span .item .GENDER ­%s]' "$(pdi_value "$card" GENDER |l10n)" - ;; - NICKNAME) seq 1 $cnt |while read c; do - printf '[span .item .NICKNAME ­aka. "%s"]' \ - "$(pdi_value "$card" NICKNAME $c |unescape |HTML)" - done - ;; - X-ZACK-JOINDATE|X-ZACK-LEAVEDATE) if [ $cnt -gt 0 ]; then - printf '[span .item .%s [b %s:] %s]' \ - "$item" "$(l10n "${item}_short")" \ - "$(pdi_value "$card" "$item" |HTML)" - fi - ;; - BDAY) - [ $cnt -gt 0 ] && printf '[span .item .BDAY [b *:] %s]' \ - "$(pdi_value "$card" BDAY |grep -xE '[0-9-]+')" - ;; - SOUND) - [ $cnt -gt 0 ] && printf '[audio .item .SOUND controls="controls" - [source type="audio/ogg" src="data:audio/ogg;base64,%s"] - ]' \ - "$(pdi_value "$card" SOUND |grep -xE '[a-zA-Z0-9/+=]+')" - ;; - PHOTO|LOGO) - [ $cnt -gt 0 ] && printf '[img .item .%s src="data:image/%s;base64,%s"]' "$item" \ - "$(pdi_attrib "$card" "$item" |sed -E 's;^(.*;)?TYPE="?(.+)"?(;.*)?$;\2;')" \ - "$(pdi_value "$card" "$item" |grep -xE '[a-zA-Z0-9/+=]+')" - ;; - EMAIL) - [ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n EMAIL)" - seq 1 $cnt |while read c; do - printf '[a .item .EMAIL href="mailto:%s" ­%s]' \ - "$(pdi_value "$card" EMAIL $c |unescape |HTML)" \ - "$(pdi_value "$card" EMAIL $c |unescape |HTML)" - done - ;; - TEL) - [ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n TEL)" - seq 1 $cnt |while read c; do - teltype="$(pdi_attrib "$card" TEL $c TYPE)" - [ "$teltype" ] \ - && printf '[span .item .TEL [span .type ­%s:] %s]' \ - "$(l10n "TYPE=$teltype" |HTML)" \ - "$(pdi_value "$card" TEL $c |unescape |HTML)" \ - || printf '[span .item .TEL ­%s]' \ - "$(pdi_value "$card" TEL $c |unescape |HTML)" - done - ;; - *)[ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n "$item")" - seq 1 $cnt |while read c; do - printf '[span .item .%s ­%s]' "$item" \ - "$(pdi_value "$card" "$item" $c |unescape |HTML)" - done - ;; - esac - done -} - -edit_item(){ - local card="$1" - local item cnt c - shift 1 - - for item in $@; do - cnt="$(pdi_count "$card" "$item")" - [ $cnt -lt 1 ] && cnt=1 - - case $item in - N)N="$(pdi_value "$card" N)" - if [ "$N" ]; then - IFS=\; read n1 n2 n3 n4 n5 <<-EOF - $N - EOF - else - N="$(pdi_value "$card" FN |unescape)" - n1="${N%%[a-z]*}" n1="${N#$n1}" - [ "$n1" ] || n1="${N##* }" - n2="${N%$n1}" - fi - printf ' - [h3 %s] - [input .item .N name="4N" placeholder="%s" value="%s"] - [input .item .N name="2N" placeholder="%s" value="%s"] - [input .item .N name="1N" placeholder="%s" value="%s"] - [input .item .N name="5N" placeholder="%s" value="%s"] - ' "$(l10n "$item")" \ - "$(l10n n_pre)" "$(HTML "$n4")" \ - "$(l10n n_first)" "$(HTML "$n2" "$n3")" \ - "$(l10n n_last)" "$(HTML "$n1")" \ - "$(l10n n_post)" "$(HTML "$n5")" - ;; - GENDER) - gender="$(pdi_value "$card" GENDER)" - printf ' - [select .item .GENDER name="GENDER" - [option value="" disabled="disabled" %s %s] - [option value="female" %s %s] - [option value="male" %s %s] - [option value="other" %s %s] - [option value="none" %s %s] - ]\n' \ - "$([ "$gender" = '' ] && printf 'selected="selected"')" "$(l10n GENDER)" \ - "$([ "$gender" = 'female' ] && printf 'selected="selected"')" "$(l10n gender_female)" \ - "$([ "$gender" = 'male' ] && printf 'selected="selected"')" "$(l10n gender_male)" \ - "$([ "$gender" = 'other' ] && printf 'selected="selected"')" "$(l10n gender_other)" \ - "$([ "$gender" = 'none' ] && printf 'selected="selected"')" "$(l10n gender_none)" - ;; - BDAY|X-ZACK-JOINDATE|X-ZACK-LEAVEDATE) - printf '[h3 %s] - [input .item .%s name="%s" value="%s" placeholder="YYYY-MM-DD"]' \ - "$(l10n "$item")" "$item" "$item" "$(pdi_value "$card" "$item" |grep -xE '[0-9-]+')" - ;; - ADR|NOTE) - printf '[h3 %s]' "$(l10n "$item")" - seq 1 $cnt |while read c; do - 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)" - done - printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)" - ;; - TEL) printf '[h3 %s]' "$(l10n "$item")" - seq 1 $cnt |while read c; do - 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" - [option value="" disabled="disabled" %s %s] - [option value="HOME" %s %s] - [option value="WORK" %s %s] - [option value="CELL" %s %s] - [option value="FAX" %s %s] - ]\n' \ - "$([ "$teltype" = '' ] && printf 'selected="selected"')" "$(l10n teltype)" \ - "$([ "$teltype" = 'HOME' ] && printf 'selected="selected"')" "$(l10n TYPE=HOME)" \ - "$([ "$teltype" = 'WORK' ] && printf 'selected="selected"')" "$(l10n TYPE=WORK)" \ - "$([ "$teltype" = 'CELL' ] && printf 'selected="selected"')" "$(l10n TYPE=CELL)" \ - "$([ "$teltype" = 'FAX' ] && printf 'selected="selected"')" "$(l10n TYPE=FAX)" - - printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \ - "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)" "$(l10n "$item")" - done - printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)" - ;; - *)printf '[h3 %s]' "$(l10n "$item")" - seq 1 $cnt |while read c; do - 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")" - done - printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)" - ;; - esac - done -} - edit_card(){ local cardfile="$_DATA/vcard/$1" local tempfile card diff --git a/cards/main.cgi b/cards/main.cgi index 899388d..6f44168 100755 --- a/cards/main.cgi +++ b/cards/main.cgi @@ -11,6 +11,9 @@ fi . $_EXEC/cards/widgets.sh . $_EXEC/cards/list.sh +unescape() { [ $# = 0 ] && sed -E 's;\\(.);\1;g' || printf %s "$*" |sed -E 's;\\(.);\1;g'; } +upcase=' y;abcdefghijklmnopqrstuvwxyzäöüé;ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜÉ;; ' + filter="$(GET f)" order="$(GET o)" edit="$(GET e)" @@ -19,7 +22,7 @@ edit="$(GET e)" { w_filter_diag printf ' - [form class="newcard" action="cards/new_card.sh" method="POST" + [form class="newcard" action="/cards/new_card.sh" method="POST" [button type="submit" %s] ]' "$(l10n newcard)" diff --git a/cards/new_card.sh b/cards/new_card.sh index 2d6c39b..edc7bc9 100755 --- a/cards/new_card.sh +++ b/cards/new_card.sh @@ -1,6 +1,6 @@ #!/bin/zsh -# Copyright 2014 Paul Hänsch +# Copyright 2014, 2019 Paul Hänsch # # This file is part of Confetti. # @@ -17,29 +17,31 @@ # You should have received a copy of the GNU Affero General Public License # along with Confetti. If not, see . -cgi_post -cgi_refdata +filter="$(REF f)" +order="$(REF o)" -filter="&filter=${_REF[filter]}" -filtertype="&filtertype=${_REF[filtertype]}" -order="&order=${_REF[order]}" - -uid=$(uuidgenerator) +uid="$(timeid)$(randomid)" # 32 Octets UID, starting with timestamp card="${uid}.vcf" -tempfile="$_DATA/temp/$card" - -cat >"$tempfile" <"$lockfile" <<-EOF + BEGIN:VCARD + VERSION:4.0 + N:;;;; + BDAY: + TEL: + EMAIL: + ADR: + NOTE: + UID:${uid} + END:VCARD + EOF + REDIRECT "/cards/?o=${order}&f=${filter}&e=${card}" +else + SET_COOKIE session message="EDITLOCK" + REDIRECT "/cards/?o=${order}&f=${filter}" +fi diff --git a/cards/widgets.sh b/cards/widgets.sh index 59b6a05..5fbf125 100755 --- a/cards/widgets.sh +++ b/cards/widgets.sh @@ -85,3 +85,173 @@ EOF # ENDCARD # done +#!/bin/sh + +card_item(){ + local card="$1" + local item cnt c + shift 1 + + for item in $@; do + cnt="$(pdi_count "$card" "$item")" + + case $item in + FN) printf '[h2 .item .FN ­%s]' "$(pdi_value "$card" FN |unescape |HTML)" + ;; + GENDER) printf '[span .item .GENDER ­%s]' "$(pdi_value "$card" GENDER |l10n)" + ;; + NICKNAME) seq 1 $cnt |while read c; do + printf '[span .item .NICKNAME ­aka. "%s"]' \ + "$(pdi_value "$card" NICKNAME $c |unescape |HTML)" + done + ;; + X-ZACK-JOINDATE|X-ZACK-LEAVEDATE) if [ $cnt -gt 0 ]; then + printf '[span .item .%s [b %s:] %s]' \ + "$item" "$(l10n "${item}_short")" \ + "$(pdi_value "$card" "$item" |HTML)" + fi + ;; + BDAY) + [ $cnt -gt 0 ] && printf '[span .item .BDAY [b *:] %s]' \ + "$(pdi_value "$card" BDAY |grep -xE '[0-9-]+')" + ;; + SOUND) + [ $cnt -gt 0 ] && printf '[audio .item .SOUND controls="controls" + [source type="audio/ogg" src="data:audio/ogg;base64,%s"] + ]' \ + "$(pdi_value "$card" SOUND |grep -xE '[a-zA-Z0-9/+=]+')" + ;; + PHOTO|LOGO) + [ $cnt -gt 0 ] && printf '[img .item .%s src="data:image/%s;base64,%s"]' "$item" \ + "$(pdi_attrib "$card" "$item" |sed -E 's;^(.*;)?TYPE="?(.+)"?(;.*)?$;\2;')" \ + "$(pdi_value "$card" "$item" |grep -xE '[a-zA-Z0-9/+=]+')" + ;; + EMAIL) + [ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n EMAIL)" + seq 1 $cnt |while read c; do + printf '[a .item .EMAIL href="mailto:%s" ­%s]' \ + "$(pdi_value "$card" EMAIL $c |unescape |HTML)" \ + "$(pdi_value "$card" EMAIL $c |unescape |HTML)" + done + ;; + TEL) + [ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n TEL)" + seq 1 $cnt |while read c; do + teltype="$(pdi_attrib "$card" TEL $c TYPE)" + [ "$teltype" ] \ + && printf '[span .item .TEL [span .type ­%s:] %s]' \ + "$(l10n "TYPE=$teltype" |HTML)" \ + "$(pdi_value "$card" TEL $c |unescape |HTML)" \ + || printf '[span .item .TEL ­%s]' \ + "$(pdi_value "$card" TEL $c |unescape |HTML)" + done + ;; + *)[ $cnt -gt 0 ] && printf '[h3 %s]' "$(l10n "$item")" + seq 1 $cnt |while read c; do + printf '[span .item .%s ­%s]' "$item" \ + "$(pdi_value "$card" "$item" $c |unescape |HTML)" + done + ;; + esac + done +} + +edit_item(){ + local card="$1" + local item cnt c + shift 1 + + for item in $@; do + cnt="$(pdi_count "$card" "$item")" + [ $cnt -lt 1 ] && cnt=1 + + case $item in + N)N="$(pdi_value "$card" N)" + if [ "$N" ]; then + IFS=\; read n1 n2 n3 n4 n5 <<-EOF + $N + EOF + else + N="$(pdi_value "$card" FN |unescape)" + n1="${N%%[a-z]*}" n1="${N#$n1}" + [ "$n1" ] || n1="${N##* }" + n2="${N%$n1}" + fi + printf ' + [h3 %s] + [input .item .N name="4N" placeholder="%s" value="%s"] + [input .item .N name="2N" placeholder="%s" value="%s"] + [input .item .N name="1N" placeholder="%s" value="%s"] + [input .item .N name="5N" placeholder="%s" value="%s"] + ' "$(l10n "$item")" \ + "$(l10n n_pre)" "$(HTML "$n4")" \ + "$(l10n n_first)" "$(HTML "$n2" "$n3")" \ + "$(l10n n_last)" "$(HTML "$n1")" \ + "$(l10n n_post)" "$(HTML "$n5")" + ;; + GENDER) + gender="$(pdi_value "$card" GENDER)" + printf ' + [select .item .GENDER name="GENDER" + [option value="" disabled="disabled" %s %s] + [option value="female" %s %s] + [option value="male" %s %s] + [option value="other" %s %s] + [option value="none" %s %s] + ]\n' \ + "$([ "$gender" = '' ] && printf 'selected="selected"')" "$(l10n GENDER)" \ + "$([ "$gender" = 'female' ] && printf 'selected="selected"')" "$(l10n gender_female)" \ + "$([ "$gender" = 'male' ] && printf 'selected="selected"')" "$(l10n gender_male)" \ + "$([ "$gender" = 'other' ] && printf 'selected="selected"')" "$(l10n gender_other)" \ + "$([ "$gender" = 'none' ] && printf 'selected="selected"')" "$(l10n gender_none)" + ;; + BDAY|X-ZACK-JOINDATE|X-ZACK-LEAVEDATE) + printf '[h3 %s] + [input .item .%s name="%s" value="%s" placeholder="YYYY-MM-DD"]' \ + "$(l10n "$item")" "$item" "$item" "$(pdi_value "$card" "$item" |grep -xE '[0-9-]+')" + ;; + ADR|NOTE) + printf '[h3 %s]' "$(l10n "$item")" + seq 1 $cnt |while read c; do + 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)" + done + printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)" + ;; + TEL) printf '[h3 %s]' "$(l10n "$item")" + seq 1 $cnt |while read c; do + 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" + [option value="" disabled="disabled" %s %s] + [option value="HOME" %s %s] + [option value="WORK" %s %s] + [option value="CELL" %s %s] + [option value="FAX" %s %s] + ]\n' \ + "$([ "$teltype" = '' ] && printf 'selected="selected"')" "$(l10n teltype)" \ + "$([ "$teltype" = 'HOME' ] && printf 'selected="selected"')" "$(l10n TYPE=HOME)" \ + "$([ "$teltype" = 'WORK' ] && printf 'selected="selected"')" "$(l10n TYPE=WORK)" \ + "$([ "$teltype" = 'CELL' ] && printf 'selected="selected"')" "$(l10n TYPE=CELL)" \ + "$([ "$teltype" = 'FAX' ] && printf 'selected="selected"')" "$(l10n TYPE=FAX)" + + printf '[input .item .%s name="%s" value="%s" placeholder="%s"]' \ + "$item" "$item" "$(pdi_value "$card" "$item" $c |unescape |HTML)" "$(l10n "$item")" + done + printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)" + ;; + *)printf '[h3 %s]' "$(l10n "$item")" + seq 1 $cnt |while read c; do + 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")" + done + printf '[button type="submit" name="action" value="addfield %s" %s ]' "$item" "$(l10n edit_addfield)" + ;; + esac + done +}