]> git.plutz.net Git - confetti/commitdiff
unify view functions for cards
authorpaul <paul@plutz.net>
Mon, 14 Nov 2016 17:06:51 +0000 (17:06 +0000)
committerpaul <paul@plutz.net>
Mon, 14 Nov 2016 17:06:51 +0000 (17:06 +0000)
svn path=/trunk/; revision=148

static/cards.css
templates/view_attendee.sh
templates/view_client.sh

index 5d78a0fd4e1ae975f445c81db1e8d0f77107e88e..002e66b7edd691992204d34108dcf9e90a117b1e 100644 (file)
   display: block;
   max-width: 100%;
   word-wrap: break-word;
+  white-space: pre-line;
 }
 .card .section .item label {
   font-weight: bold;
index 5966729e01611df62bb78485d186cf8ecefd1b0d..10cb06e764d9b2219665db638fd0c820fa20bf95 100755 (executable)
@@ -1,4 +1,4 @@
-# Copyright 2014, 2015 Paul Hänsch
+# Copyright 2014 - 2016 Paul Hänsch
 #
 # This file is part of Confetti.
 # 
 # You should have received a copy of the GNU Affero General Public License
 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
 
+list_items(){
+  item="$1"
+  [ -n "${values[$item]+x}" ] && \
+    printf '<h3>%s</h3>\n' "$(l10n $item)"
+  for n in "$item" "$item"{0..100}; do
+    [ -z "${values[$n]+x}" ] && break \
+    || printf '<span class="item %s">%s</span>\n' \
+         "$item" "$(htmlsafe ${values[$n]})"
+  done
+}
+
+list_section(){
+  printf '<div class="section %s">' "$1"
+  shift 1
+  for each in $@; do
+    list_items "$each"
+  done
+  printf '</div>'
+}
+
 n=$(printf %s "$values[N+3] $values[N+1] $values[N+2] $values[N+0] $values[N+4]" \
     | sed -r ':X;$!{N;bX}; s;^[\n ]+;;; s;[\n ]+$;;; s;[\r\t\n ]+; ;g;'
    )
 fullname="${n:-${values[FN]:-${values[NICKNAME]}}}"
 
-cat <<END_HTML
-  <div class="section basic">
-    <h2 class="item FN">$fullname</h2>
-    ${values[GENDER]:+<span class="item GENDER">$(l10n $values[GENDER])</span>}
-
-    $(for n in NICKNAME NICKNAME{0..10}; do
-      echo "${values[$n]:+<span class="item NICKNAME">aka. $values[$n]</span>}"
-    done)
-
-    ${values[BDAY]:+<span class="item BDAY"><b>*:</b> $values[BDAY]</span>}
-    ${values[X-ZACK-JOINDATE]:+<span class="item X-ZACK-JOINDATE"><b>$(l10n label_join):</b> $values[X-ZACK-JOINDATE]</span>}
-    ${values[X-ZACK-LEAVEDATE]:+<span class="item X-ZACK-LEAVEDATE"><b>$(l10n label_leave):</b> $values[X-ZACK-LEAVEDATE]</span>}
-    ${values[SOUND]:+<audio controls="controls" class="item SOUND"><source type="audio/ogg" src="data:audio/ogg;base64,$values[SOUND]" /></audio>}
-    ${values[PHOTO]:+<img class="item PHOTO" src="data:image/$values[PHOTO_TYPE];base64,$values[PHOTO]" />}
-    ${values[LOGO]:+<img class="item LOGO" src="data:image/$values[LOGO_TYPE];base64,$values[LOGO]" />}
-  </div><!--
-
-  --><div class="section phone">
-    <h3>$(l10n TEL)</h3>
-    $(for n in TEL TEL{0..10}; do
-      echo "${values[$n]:+<span class="item TEL">$values[${n}_TYPE] $values[$n]</span>}"
-    done)
-  </div><!--
-
-  --><div class="section message">
-    ${values[EMAIL]:+<h3>$(l10n EMAIL)</h3>}
-    $(for n in EMAIL EMAIL{0..10}; do
-      echo "${values[$n]:+<span class="item EMAIL"><a href="mailto:$values[$n]">$values[$n]</a></span>}"
-    done)
-    ${values[IMPP]:+<h3>$(l10n IMPP)</h3>}
-    $(for n in IMPP IMPP{0..10}; do
-      echo "${values[$n]:+<span class="item IMPP">$values[${n}_TYPE] <a href="$values[$n]">$values[$n]</a></span>}"
-    done)
-  </div><!--
-
-  --><div class="section address">
-    <h3>$(l10n ADR)</h3>
-    $(for n in ADR ADR{0..10}; do
-      echo "${values[$n]:+<span class="item ADR">$values[$n]</span>}"
-    done)
-    ${values[URL]:+<h3>$(l10n URL)</h3>}
-    $(for n in URL URL{0..10}; do
-      echo "${values[$n]:+<span class="item URL"><a href="$values[$n]">$values[$n]</a></span>}"
-    done)
-  </div><!--
-
-  --><div class="section note">
-    <h3>$(l10n NOTE)</h3>
-    $(for n in NOTE NOTE{0..10}; do
-      echo "${values[$n]:+<span class="item NOTE">$values[$n]</span>}"
-    done)
-  </div><!--
-
-  --><div class="section attendance">
-    <h3>$(l10n course_attendance)</h3>
-    <ul>
-    $(sed -rn 's:(.*)\t'$id'$:\1:p' "$_DATA/mappings/attendance" |while read each; do
-      cname="$(sed -rn 's:^SUMMARY\:(.*)$:\1:p' "$_DATA/ical/$each")"
-      echo '   <li><a class="item attendance" href="?p=courses#'$each'">'$cname'</a></li>'
-    done)
-    </ul>
-  </div>
-END_HTML
+hi_company="${values[X-HEALTH-INSURANCE+0]}"
+ hi_number="${values[X-HEALTH-INSURANCE+1]}"
+ hi_status="${values[X-HEALTH-INSURANCE+2]}"
+
+printf '<div class="section basic">
+    <h2 class="item FN">%s</h2>
+' "$fullname"
+[ -n "$values[GENDER]" ] && printf '
+  <span class="item GENDER">%s</span>
+  ' "$(l10n "$values[GENDER]")"
+
+for n in NICKNAME NICKNAME{0..100}; do
+  [ -z "${values[$n]+x}" ] && break \
+  || printf '
+      <span class="item NICKNAME">aka. %s</span>
+  ' "$(htmlsafe ${values[$n]})"
+done
+
+[ -n "$values[BDAY]" ] && printf '
+  <span class="item BDAY"><b>*:</b>%s</span>
+  ' "$(htmlsafe "$values[BDAY]")"
+[ -n "$values[X-ZACK-JOINDATE]" ] && printf '
+  <span class="item X-ZACK-JOINDATE"><b>%s:</b>%s</span>
+  ' "$(l10n label_join)" "$(htmlsafe "$values[X-ZACK-JOINDATE]")"
+[ -n "$values[X-ZACK-LEAVEDATE]" ] && printf '
+  <span class="item X-ZACK-LEAVEDATE"><b>%s:</b>%s</span>
+  ' "$(l10n label_leave)" "$(htmlsafe "$values[X-ZACK-LEAVEDATE]")"
+
+[ -n "$values[SOUND]" ] && printf '
+  <audio controls="controls" class="item SOUND">
+    <source type="audio/ogg" src="data:audio/ogg;base64,%s" />
+  </audio>' "$values[SOUND]"
+
+[ -n "$values[PHOTO]" ] && printf '
+  <img class="item PHOTO" src="data:image/%s;base64,%s" />
+  ' "${values[PHOTO_TYPE]}" "${values[PHOTO]}"
+
+[ -n "$values[LOGO]" ] && printf '
+  <img class="item PHOTO" src="data:image/%s;base64,%s" />
+  ' "${values[LOGO_TYPE]}" "${values[LOGO]}"
+
+if [ "$PROFILE" = circus ]; then
+  printf '</div>'
+
+  list_section phone TEL
+  list_section message EMAIL IMPP URL
+  list_section address ADR
+  list_section note NOTE
+
+  printf '<div class="section attendance"><h3>%s</h3><ul>' "$(l10n course_attendance)"
+  sed -rn 's:(.*)\t'"$id"'$:\1:p' "$_DATA/mappings/attendance" |while read each; do
+    cname="$(sed -rn 's:^SUMMARY\:(.*)$:\1:p' "$_DATA/ical/$each")"
+    printf '   <li><a class="item attendance" href="?p=courses#%s">%s</a></li>' "$each" "$(htmlsafe $cname)"
+  done
+  printf '</ul></div>'
+elif [ "$PROFILE" = medical ]; then
+  list_items ADR
+  list_items URL
+  printf '</div>'
+
+  list_section phone TEL EMAIL IMPP
+
+  printf '<div class="section insurance"><h3>%s</h3>' "$(l10n X-HEALTH-INSURANCE)"
+  [ -n "$hi_company" ] && printf '<span class="item hi_comapany">%s</span>' \
+    "$(htmlsafe "$hi_company")"
+  [ -n "$hi_number" ] && printf '<span class="item hi_number"><label>%s:</label>%s</span>' \
+    "$(l10n hi_number)" "$(htmlsafe "$hi_number")"
+  [ -n "$hi_status" ] && printf '<span class="item hi_status"><label>%s:</label>%s</span>' \
+    "$(l10n hi_status)" "$(htmlsafe "$hi_status")"
+  printf '</div>'
+
+  list_section note NOTE X-CLIENT-REFERRAL
+
+  printf '<div class="section prescriptions"><h3>%s</h3><ul>' "$(l10n prescriptions)"
+  declare -A mpx
+  find "$_DATA/prescriptions/" -name "${id%.vcf}.*.mpx" \
+  | while read pfile; do
+    mpx=(); cat "$pfile" |while read -r line; do
+      val="${line#*:}"
+      mpx[${line%%:*}]="$(htmlsafe "${val//\\n/$BR}")"
+    done
+    printf '<li><a href="?p=prescriptions&amp;client=%s#%s" >%s: %s - %s</a></li>' \
+      "${id}" "${pfile##*/}" "${mpx[date]}" "${mpx[indicator]}" \
+      "$([ -n "${mpx[remidy]}" ] && printf '%s %s' "${mpx[quantity]}" "${mpx[remidy]}" 
+         for n in {0..10}; do
+           [ -n "${mpx[remidy${n}]}" ] && printf ', %s %s' "${mpx[quantity${n}]}" "${mpx[remidy${n}]}" 
+         done
+       )"
+  done |sort -r
+  printf '</ul></div>'
+fi
index 2cb124bb71a88fa6f4f76a1a757b2115beff31ae..0fe5e983c9ee7b11814c4a239ac19b49dfc9426d 100755 (executable)
 # You should have received a copy of the GNU Affero General Public License
 # along with Confetti.  If not, see <http://www.gnu.org/licenses/>. 
 
-n=$(printf %s "$values[N]" \
-    | sed -rn 's:^([^;]*)(\;[^;]*)(\;[^;]*)?(\;[^;]*)?(\;[^;]*)?$:\4 \2 \3 \1 \5:gp' \
-    | sed -r 's:,: :;s:\;: :g;s: +: :g;s:^ $::;'
+list_items(){
+  item="$1"
+  [ -n "${values[$item]+x}" ] && \
+    printf '<h3>%s</h3>\n' "$(l10n $item)"
+  for n in "$item" "$item"{0..100}; do
+    [ -z "${values[$n]+x}" ] && break \
+    || printf '<span class="item %s">%s</span>\n' \
+         "$item" "$(htmlsafe ${values[$n]})"
+  done
+}
+
+list_section(){
+  printf '<div class="section %s">' "$1"
+  shift 1
+  for each in $@; do
+    list_items "$each"
+  done
+  printf '</div>'
+}
+
+n=$(printf %s "$values[N+3] $values[N+1] $values[N+2] $values[N+0] $values[N+4]" \
+    | sed -r ':X;$!{N;bX}; s;^[\n ]+;;; s;[\n ]+$;;; s;[\r\t\n ]+; ;g;'
    )
 fullname="${n:-${values[FN]:-${values[NICKNAME]}}}"
 
-hi_company="$(printf %s "${values[X-HEALTH-INSURANCE]}" |cut -d\; -f1)"
-hi_number="$(printf %s "${values[X-HEALTH-INSURANCE]}" |cut -d\; -f2)"
-hi_status="$(printf %s "${values[X-HEALTH-INSURANCE]}" |cut -d\; -f3)"
+hi_company="${values[X-HEALTH-INSURANCE+0]}"
+ hi_number="${values[X-HEALTH-INSURANCE+1]}"
+ hi_status="${values[X-HEALTH-INSURANCE+2]}"
+
+printf '<div class="section basic">
+    <h2 class="item FN">%s</h2>
+' "$fullname"
+[ -n "$values[GENDER]" ] && printf '
+  <span class="item GENDER">%s</span>
+  ' "$(l10n "$values[GENDER]")"
 
+for n in NICKNAME NICKNAME{0..100}; do
+  [ -z "${values[$n]+x}" ] && break \
+  || printf '
+      <span class="item NICKNAME">aka. %s</span>
+  ' "$(htmlsafe ${values[$n]})"
+done
 
-cat <<END_HTML
-  <div class="section basic">
-    <h2 class="item FN">$fullname</h2>
-    ${values[GENDER]:+<span class="\""item GENDER"\"">$(l10n $values[GENDER])</span>}
+[ -n "$values[BDAY]" ] && printf '
+  <span class="item BDAY"><b>*:</b>%s</span>
+  ' "$(htmlsafe "$values[BDAY]")"
+[ -n "$values[X-ZACK-JOINDATE]" ] && printf '
+  <span class="item X-ZACK-JOINDATE"><b>%s:</b>%s</span>
+  ' "$(l10n label_join)" "$(htmlsafe "$values[X-ZACK-JOINDATE]")"
+[ -n "$values[X-ZACK-LEAVEDATE]" ] && printf '
+  <span class="item X-ZACK-LEAVEDATE"><b>%s:</b>%s</span>
+  ' "$(l10n label_leave)" "$(htmlsafe "$values[X-ZACK-LEAVEDATE]")"
 
-    $(for n in NICKNAME NICKNAME{0..10}; do
-      echo "${values[$n]:+<span class="\""item NICKNAME"\"">aka. $values[$n]</span>}"
-    done)
+[ -n "$values[SOUND]" ] && printf '
+  <audio controls="controls" class="item SOUND">
+    <source type="audio/ogg" src="data:audio/ogg;base64,%s" />
+  </audio>' "$values[SOUND]"
 
-    ${values[BDAY]:+<span class="\""item BDAY"\""><label>*:</label> ${values[BDAY]}</span>}
-    ${values[SOUND]:+<audio controls="controls" class="\""item SOUND"\""><source type="audio/ogg" src="\""data:audio/ogg;base64,$values[SOUND]"\"" /></audio>}
-    ${values[PHOTO]:+<img class="\""item PHOTO"\"" src="\""data:image/$values[PHOTO_TYPE];base64,$values[PHOTO]"\"" />}
-    ${values[LOGO]:+<img class="\""item LOGO"\"" src="\""data:image/$values[LOGO_TYPE];base64,$values[LOGO]"\"" />}
+[ -n "$values[PHOTO]" ] && printf '
+  <img class="item PHOTO" src="data:image/%s;base64,%s" />
+  ' "${values[PHOTO_TYPE]}" "${values[PHOTO]}"
 
-    <h3>$(l10n ADR)</h3>
-    $(for n in ADR ADR{0..10}; do
-      echo "${values[$n]:+<span class="\""item ADR"\"">$values[$n]</span>}"
-    done)
-    ${values[URL]:+<h3>$(l10n URL)</h3>}
-    $(for n in URL URL{0..10}; do
-      echo "${values[$n]:+<span class="\""item URL"\""><a href="\""$values[$n]"\"">$values[$n]</a></span>}"
-    done)
-  </div><!--
+[ -n "$values[LOGO]" ] && printf '
+  <img class="item PHOTO" src="data:image/%s;base64,%s" />
+  ' "${values[LOGO_TYPE]}" "${values[LOGO]}"
 
-  --><div class="section phone">
-    <h3>$(l10n TEL)</h3>
-    $(for n in TEL TEL{0..10}; do
-      echo "${values[$n]:+<span class="\""item TEL"\"">$(l10n t${values[${n}_TYPE]}) $values[$n]</span>}"
-    done)
-    ${values[EMAIL]:+<h3>$(l10n EMAIL)</h3>}
-    $(for n in EMAIL EMAIL{0..10}; do
-      echo "${values[$n]:+<span class="\""item EMAIL"\""><a href="\""mailto:$values[$n]"\"">$values[$n]</a></span>}"
-    done)
-    ${values[IMPP]:+<h3>$(l10n IMPP)</h3>}
-    $(for n in IMPP IMPP{0..10}; do
-      echo "${values[$n]:+<span class="\""item IMPP"\"">$values[${n}_TYPE] <a href="\""$values[$n]"\"">$values[$n]</a></span>}"
-    done)
-  </div><!--
+list_items ADR
+list_items URL
+printf '</div>'
 
-  --><div class="section insurance">
+  list_section phone TEL EMAIL IMPP
+
+cat <<-END_HTML
+  <div class="section insurance">
     <h3>$(l10n X-HEALTH-INSURANCE)</h3>
     ${hi_company:+<span class="\""item hi_comapany"\"">${hi_company}</span>}
     ${hi_number:+<span class="\""item hi_number"\""><label>$(l10n hi_number):</label> ${hi_number}</span>}
     ${hi_status:+<span class="\""item hi_status"\""><label>$(l10n hi_status):</label> ${hi_status}</span>}
-  </div><!--
+  </div>
+END_HTML
 
-  --><div class="section note">
-    ${values[NOTE]:+<h3>$(l10n NOTE)</h3>}
-    $(for n in NOTE NOTE{0..10}; do
-      echo "${values[$n]:+<span class="\""item NOTE"\"">$values[$n]</span>}"
-    done)
-    ${values[X-CLIENT-REFERRAL]:+<h3>$(l10n X-CLIENT-REFERRAL)</h3>}
-    $(for n in X-CLIENT-REFERRAL X-CLIENT-REFERRAL{0..10}; do
-      echo "${values[$n]:+<span class="\""item X-CLIENT-REFERRAL"\"">$values[$n]</span>}"
-    done)
-  </div><!--
+list_section note NOTE X-CLIENT-REFERRAL
 
-  --><div class="section prescriptions">
+cat <<-END_HTML
+  <div class="section prescriptions">
     <h3>$(l10n prescriptions)</h3>
     <ul>
     $(declare -A mpx