]> git.plutz.net Git - lobster/commitdiff
unification of card editing functions
authorpaul <paul@plutz.net>
Mon, 14 Nov 2016 09:59:37 +0000 (09:59 +0000)
committerpaul <paul@plutz.net>
Mon, 14 Nov 2016 09:59:37 +0000 (09:59 +0000)
svn path=/trunk/; revision=145

pages/cards.sh
templates/edit_attendee.sh
templates/edit_client.sh

index f6142dfd4f3acaa01de1e1577f845cda0cc2a6c0..2d1d4e29e112c825e6e5652e50e44bf5ca0a2d31 100755 (executable)
 BR='
 '
 
+force_items(){
+  for each in "$@"; do
+    [ -z "${values[$each]+x}" ] && values[${each}]=''
+  done
+}
+
 case $PROFILE in
 medical)
+  SUP_FIELDS=(N NICKNAME GENDER BDAY ADR TEL EMAIL X-HEALTH-INSURANCE X-HEALTH-INSURANCE-NOCONTRIB IMPP URL NOTE X-CLIENT-REFERRAL)
+  FORCE_ITEMS=(ADR TEL EMAIL NOTE X-CLIENT-REFERRAL)
   view_card="$_EXEC/templates/view_client.sh"
   edit_card="$_EXEC/templates/edit_client.sh"
   _GET[order]="${_GET[order]:-lastname}"
@@ -29,6 +37,8 @@ medical)
   profile_medical=x
 ;;
 circus)
+  SUP_FIELDS=(N NICKNAME GENDER BDAY X-ZACK-JOINDATE X-ZACK-LEAVEDATE EMAIL TEL IMPP ADR URL NOTE)
+  FORCE_ITEMS=(BDAY X-ZACK-JOINDATE TEL EMAIL ADR NOTE)
   view_card="$_EXEC/templates/view_attendee.sh"
   edit_card="$_EXEC/templates/edit_attendee.sh"
   _GET[order]="${_GET[order]:-firstname}"
@@ -258,5 +268,6 @@ edit_card() {  #Parameter: Cardfile
 
   declare -A values
   vcf_parse "$cardfile"
+  force_items $FORCE_ITEMS
   . $edit_card
 }
index e27592c6d9b32da57a39e7ec266cf6e74f521bec..820bce8334e54fae795bb50304092e476c15b3ff 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/>. 
 
+setchecked() {
+  printf 'checked="checked"'
+}
+setselected() {
+  printf 'selected="selected"'
+}
 check_gen() {
-  [ "$values[GENDER]" = "$1" ] && echo 'selected="selected"'
+  [ "$values[GENDER]" = "$1" ] && setselected
 }
 check_a() {
-  egrep -q "^${1}.${id}$" "$_DATA/mappings/attendance" && echo 'checked="checked"'
+  egrep -q "^${1}.${id}$" "$_DATA/mappings/attendance" && setchecked
+}
+teltype() {
+  cat <<-EOF
+       <select class="item phonetype" name="phonetype">
+         <option value="" disabled="disabled" $([ -z "$1" ] && setselected )>$(l10n phone_typeselect)</option>
+         <option value=""></option>
+         <option value="HOME" $([ "$1" = HOME ] && setselected)>$(l10n phone_home)</option>
+         <option value="CELL" $([ "$1" = CELL ] && setselected)>$(l10n phone_cell)</option>
+         <option value="WORK" $([ "$1" = WORK ] && setselected)>$(l10n phone_work)</option>
+         <option value="FAX"  $([ "$1" = FAX  ] && setselected)>$(l10n phone_fax )</option>
+       </select>
+       EOF
 }
 
-SUP_FIELDS=(N NICKNAME GENDER BDAY X-ZACK-JOINDATE X-ZACK-LEAVEDATE EMAIL TEL IMPP ADR URL NOTE)
+list_items(){
+  item="$1"
+  placeholder="$2"
+  [ -n "${values[$item]+x}" ] && printf '<h3>%s</h3>\n' "$(l10n $item)"
+  for n in "$item" "$item"{0..100}; do
+    if [ -n "${values[$n]+x}" ]; then
+      case "$item" in
+        (ADR|NOTE)
+          printf '<textarea class="item %s" name="%s">%s</textarea>\n' \
+            "$item" "$item" "$(htmlsafe ${values[$n]})"
+          ;;
+        (TEL)
+          teltype "${values[${n}_TYPE]}"
+          printf '<input class="item %s" name="%s" value="%s" />\n' \
+            "$item" "$item" "$(attribsafe ${values[$n]})"
+          ;;
+        (*)
+          printf '<input class="item %s" name="%s" value="%s" placeholder="%s"/>\n' \
+            "$item" "$item" "$(attribsafe ${values[$n]})" "$placeholder"
+          ;;
+      esac
+    else
+      break
+    fi
+  done
+}
+
+list_section(){
+  printf '<div class="section %s">' "$1"
+  shift 1
+  for each in $@; do
+    list_items "$each"
+  done
+  printf '</div>'
+}
+
+hi_company="${values[X-HEALTH-INSURANCE+1]}"
+ hi_number="${values[X-HEALTH-INSURANCE+2]}"
+ hi_status="${values[X-HEALTH-INSURANCE+3]}"
 
 [ -z "$values[UID]" ] && values[UID]="$(uuidgenerator)"
 
@@ -44,82 +100,78 @@ cat <<END_HTML
       <option value="other" $(check_gen other)>$(l10n gender_other)</option>
       <option value="none" $(check_gen none)>$(l10n gender_none)</option>
     </select>
+END_HTML
 
-    $(for n in NICKNAME NICKNAME{0..10}; do
-      echo "${values[$n]+<input class="item NICKNAME" name="NICKNAME" placeholder="$(l10n NICKNAME)" value="$values[$n]" />}"
-    done)
-
-    <h3>$(l10n BDAY)</h3>
-    <input class="item BDAY" name="BDAY" value="$values[BDAY]" />
-
-    <h3>$(l10n X-ZACK-JOINDATE)</h3>
-    <input class="item X-ZACK-LEAVEDATE" name="X-ZACK-JOINDATE" value="$values[X-ZACK-JOINDATE]" />
-    $(if [ -n "$values[X-ZACK-LEAVEDATE]" ]; then
-      echo '    <h3>'$(l10n X-ZACK-LEAVEDATE)'</h3>'
-      echo '    <input class="item X-ZACK-LEAVEDATE" name="X-ZACK-LEAVEDATE" value="'$values[X-ZACK-LEAVEDATE]'" />'
-    fi)
-
-    $(if [ -n "$values[SOUND]" ]; then
-      echo '    <audio controls="controls" class="item SOUND">'
-      echo '      <source type="audio/ogg" src="data:audio/ogg;base64,'$values[SOUND]'" />'
-      echo '    </audio>'
-    fi)
-    ${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>
+    for n in NICKNAME NICKNAME{0..100}; do
+      [ -z "${values[$n]+x}" ] && break \
+      || printf '
+          <input class="item NICKNAME" name="NICKNAME" value="%s" placeholder="%s"/>
+      ' "$(attribsafe ${values[$n]})" "$(l10n NICKNAME)"
+    done
 
-  <div class="section phone">
-    <h3>$(l10n TEL)</h3>
-    <input class="item TEL" name="TEL" value="$values[TEL]" />
-    $(for n in TEL{0..10}; do
-      echo "${values[$n]+<input class="item TEL" name="TEL" value="'$values[$n]'" />}"
-    done)
-  </div>
+    list_items BDAY YYYY-MM-DD
+    list_items X-ZACK-JOINDATE YYYY-MM-DD
+    list_items X-ZACK-LEAVEDATE YYYY-MM-DD
 
-  <div class="section message">
-    <h3>$(l10n EMAIL)</h3>
-    <input class="item EMAIL" name="EMAIL" value="$values[EMAIL]" />
-    $(for n in EMAIL{0..10}; do
-      echo "${values[$n]+<input class="item EMAIL" name="EMAIL" value="$values[$n]" />}"
-    done)
-    ${values[IMPP]+<h3>$(l10n IMPP)</h3>}
-    $(for n in IMPP IMPP{0..10}; do
-      echo "${values[$n]+<input class="item IMPP" name="IMPP" value="$values[$n]" />}"
-    done)
-  </div>
+    [ -n "$values[SOUND]" ] && printf '
+      <audio controls="controls" class="item SOUND">
+        <source type="audio/ogg" src="data:audio/ogg;base64,%s" />
+      </audio>' "$values[SOUND]"
 
-  <div class="section address">
-    <h3>$(l10n ADR)</h3>
-    <textarea class="item ADR" name="ADR">$values[ADR]</textarea>
-    $(for n in ADR{0..10}; do
-      echo "${values[$n]+<textarea class="item ADR" name="ADR">$values[$n]</textarea>}"
-    done)
-    ${values[URL]+<h3>$(l10n URL)</h3>}
-    $(for n in URL URL{0..10}; do
-      echo "${values[$n]+<input class="item URL" name="URL" value="$values[$n]" />}"
-    done)
-  </div>
+    [ -n "$values[PHOTO]" ] && printf '
+      <img class="item PHOTO" src="data:image/%s;base64,%s" />
+      ' "${values[PHOTO_TYPE]}" "${values[PHOTO]}"
 
-  <div class="section note">
-    <h3>$(l10n NOTE)</h3>
-    <textarea class="item NOTE" name="NOTE">$values[NOTE]</textarea>
-    $(for n in NOTE{0..10}; do
-      echo "${values[$n]+<textarea class="item NOTE" name="NOTE">$values[$n]</textarea>}"
-    done)
-  </div>
+    [ -n "$values[LOGO]" ] && printf '
+      <img class="item PHOTO" src="data:image/%s;base64,%s" />
+      ' "${values[LOGO_TYPE]}" "${values[LOGO]}"
 
-  <div class="section attendance">
-    <h3>$(l10n course_attendance)</h3>
-    $(listcourses |while read each; do
-      cname="$(sed -rn 's:^SUMMARY\:(.*)$:\1:p' "$_DATA/ical/$each")"
-      echo '<label><input type="checkbox" name="attendance" value="'$each'" '$(check_a "$each")'/>'$cname'</label>'
-    done)
-  </div>
+printf '</div>'
+
+if [ "$PROFILE" = circus ]; then
+  list_section phone TEL
+  list_section message EMAIL IMPP URL
+  list_section address ADR
+  list_section note NOTE X-CLIENT-REFERRAL
+  cat <<-END_HTML
+       <div class="section attendance">
+         <h3>$(l10n course_attendance)</h3>
+         $(listcourses |while read each; do
+           cname="$(sed -rn 's:^SUMMARY\:(.*)$:\1:p' "$_DATA/ical/$each")"
+           printf '<label><input type="checkbox" name="attendance" value="%s" %s/>%s</label>' \
+             "$(attribsafe "$each")" "$(check_a "$each")" "$(htmlsafe "$cname")"
+         done)
+       </div>
+       END_HTML
+elif [ "$PROFILE" = medical ]; then
+  list_section address ADR
+  list_section phone TEL EMAIL IMPP URL
+  cat <<-END_HTML
+       <div class="section insurance">
+         <h3>$(l10n X-HEALTH-INSURANCE)</h3>
+         <input type="radio" name="hi_select" value="list" id="hi_select_list" checked /><label for="hi_select_list">$(l10n hi_from_list)</label
+         ><input type="radio" name="hi_select" value="other" id="hi_other"><label for="hi_other">$(l10n hi_other)</label>
+         <select class="item" name="hi_company">
+           <option value="" disabled="disabled" ${hi_company:-selected}>$(l10n hi_company)</option>
+           $(list_hi_companies |while read -r f; do
+             printf '<option value="%s" %s>%s</option>
+             '  "$(attribsafe "$f")" "$([ "$f" = "$hi_company" ] && setselected )" "$(htmlsafe "$f")"
+           done)
+         </select>
+         <input type="text" name="hi_other" value="$hi_company" placeholder="$(l10n hi_company)" />
+         <input name="hi_number" value="$hi_number" placeholder="$(l10n hi_number)" />
+         <input name="hi_status" value="$hi_status" placeholder="$(l10n hi_status)" />
+       </div>
+       END_HTML
+  list_section note NOTE X-CLIENT-REFERRAL
+fi
 
+
+cat <<END_HTML
   <div class="control">
     <select class="item" name="newfield">
       <option value="" disabled="disabled" selected="selected">$(l10n edit_addfieldtext)</option>
-      $(for f in $SUP_FIELDS; do echo "<option value=\"$f\">$(l10n $f)</option>"; done)
+      $(for f in $SUP_FIELDS; do printf '<option value="%s">%s</option>\n' "$f" "$(l10n "$f")"; done)
     </select
     ><button class="item" type="submit" name="action" value="addfield">$(l10n edit_addfield)</button>
     <button class="item" type="submit" name="action" value="update">$(l10n edit_update)</button>
index b2331aa8e9e83084eb745df411e2af8727a91cdc..f2c5afb0b1d8d05f89a090c94029056111ec7da6 100755 (executable)
@@ -40,17 +40,36 @@ teltype() {
        EOF
 }
 
-n_last="$(printf %s "$values[N]" |sed -rn 's:^([^;]*;){0} *([^;]*).*$:\2:p')"
-n_first="$(printf %s "$values[N]" |sed -rn 's:^([^;]*;){1} *([^;]*).*$:\2:p')"
-n_middle="$(printf %s "$values[N]" |sed -rn 's:^([^;]*;){2} *([^;]*).*$:\2:p')"
-n_pre="$(printf %s "$values[N]" |sed -rn 's:^([^;]*;){3} *([^;]*).*$:\2:p')"
-n_post="$(printf %s "$values[N]" |sed -rn 's:^([^;]*;){4} *([^;]*)*$:\2:p')"
-
-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)"
+list_items(){
+  item="$1"
+  placeholder="$2"
+  [ -n "${values[$item]+x}" ] && printf '<h3>%s</h3>\n' "$(l10n $item)"
+  for n in "$item" "$item"{0..100}; do
+    if [ -n "${values[$n]+x}" ]; then
+      case "$item" in
+        (ADR|NOTE)
+          printf '<textarea class="item %s" name="%s">%s</textarea>\n' \
+            "$item" "$item" "$(htmlsafe ${values[$n]})"
+          ;;
+        (TEL)
+          teltype "${values[${n}_TYPE]}"
+          printf '<input class="item %s" name="%s" value="%s" />\n' \
+            "$item" "$item" "$(attribsafe ${values[$n]})"
+          ;;
+        (*)
+          printf '<input class="item %s" name="%s" value="%s" placeholder="%s"/>\n' \
+            "$item" "$item" "$(attribsafe ${values[$n]})" "$placeholder"
+          ;;
+      esac
+    else
+      break
+    fi
+  done
+}
 
-SUP_FIELDS=(N NICKNAME GENDER BDAY ADR TEL EMAIL X-HEALTH-INSURANCE X-HEALTH-INSURANCE-NOCONTRIB IMPP URL NOTE X-CLIENT-REFERRAL)
+hi_company="${values[X-HEALTH-INSURANCE+1]}"
+hi_number= "${values[X-HEALTH-INSURANCE+2]}"
+hi_status= "${values[X-HEALTH-INSURANCE+3]}"
 
 [ -z "$values[UID]" ] && values[UID]="$(uuidgenerator)"
 
@@ -59,11 +78,11 @@ cat <<END_HTML
   <input type="hidden" name="card" value="${id}"/>
   <div class="section basic">
     <h3>$(l10n N)</h3>
-    <input class="item N" name="3N" placeholder="$(l10n n_pre)" value="$n_pre" />
-    <input class="item N" name="1N" placeholder="$(l10n n_first)" value="$n_first" />
-    <input class="item N" name="2N" placeholder="$(l10n n_middle)" value="$n_middle" />
-    <input class="item N" name="0N" placeholder="$(l10n n_last)" value="$n_last" />
-    <input class="item N" name="4N" placeholder="$(l10n n_post)" value="$n_post" />
+    <input class="item N" name="3N" placeholder="$(l10n n_pre)" value="$values[N+3]" />
+    <input class="item N" name="1N" placeholder="$(l10n n_first)" value="$values[N+1]" />
+    <input class="item N" name="2N" placeholder="$(l10n n_middle)" value="$values[N+2]" />
+    <input class="item N" name="0N" placeholder="$(l10n n_last)" value="$values[N+0]" />
+    <input class="item N" name="4N" placeholder="$(l10n n_post)" value="$values[N+4]" />
 
     <select class="item GENDER" name="GENDER">
       <option value="" disabled="disabled">$(l10n GENDER)</option>
@@ -74,49 +93,32 @@ cat <<END_HTML
     </select>
 
     $(for n in NICKNAME NICKNAME{0..10}; do
-      echo "${values[$n]:+<input class="item NICKNAME" name="NICKNAME" placeholder="$(l10n NICKNAME)" value="$values[$n]" />}"
+      printf %s\\n "${values[$n]+<input class="item NICKNAME" name="NICKNAME" placeholder="$(l10n NICKNAME)" value="$values[$n]" />}"
     done)
 
-    <h3>$(l10n BDAY)</h3>
-    <input class="item BDAY" name="BDAY" value="$values[BDAY]" placeholder="YYYY-MM-DD" />
+    $(list_items BDAY YYYY-MM-DD)
+
+    $(list_items X-ZACK-JOINDATE YYYY-MM-DD)
+    $(list_items X-ZACK-LEAVEDATE YYYY-MM-DD)
 
-    $(if [ -n "$values[SOUND]" ]; then
-      echo '    <audio controls="controls" class="item SOUND">'
-      echo '      <source type="audio/ogg" src="data:audio/ogg;base64,'$values[SOUND]'" />'
-      echo '    </audio>'
-    fi)
-    ${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[SOUND]" ] && printf '
+      <audio controls="controls" class="item SOUND">
+        <source type="audio/ogg" src="data:audio/ogg;base64,%s" />
+      </audio>' "$values[SOUND]"
+    )
+    ${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 address">
-    <h3>$(l10n ADR)</h3>
-    <textarea class="item ADR" name="ADR">$values[ADR]</textarea>
-    $(for n in ADR{0..10}; do
-      echo "${values[$n]:+<textarea class="item ADR" name="ADR">$values[$n]</textarea>}"
-    done)
-    ${values[URL]:+<h3>$(l10n URL)</h3>}
-    $(for n in URL URL{0..10}; do
-      echo "${values[$n]:+<input class="item URL" name="URL" value="$values[$n]" />}"
-    done)
+    $(list_items ADR)
   </div>
 
   <div class="section phone">
-    <h3>$(l10n TEL)</h3>
-    $(teltype "${values[TEL_TYPE]}")<input class="item TEL" name="TEL" value="$values[TEL]" />
-    $(for n in TEL{0..10}; do
-      printf "${values[$n]:+$(teltype "${values[${n}_TYPE]}")<input class="item TEL" name="TEL" value="'$values[$n]'" />}"
-    done)
-
-    <h3>$(l10n EMAIL)</h3>
-    <input class="item EMAIL" name="EMAIL" value="$values[EMAIL]" />
-    $(for n in EMAIL{0..10}; do
-      printf "${values[$n]:+<input class="item EMAIL" name="EMAIL" value="$values[$n]" />}"
-    done)
-    ${values[IMPP]:+<h3>$(l10n IMPP)</h3>}
-    $(for n in IMPP IMPP{0..10}; do
-      echo "${values[$n]:+<input class="item IMPP" name="IMPP" value="$values[$n]" />}"
-    done)
+    $(list_items TEL)
+    $(list_items EMAIL)
+    $(list_items IMPP)
+    $(list_items URL)
   </div>
 
   <div class="section insurance">
@@ -138,27 +140,19 @@ cat <<END_HTML
   </div>
 
   <div class="section note">
-    <h3>$(l10n NOTE)</h3>
-    <textarea class="item NOTE" name="NOTE">$values[NOTE]</textarea>
-    $(for n in NOTE{0..10}; do
-      echo "${values[$n]:+<textarea class="item NOTE" name="NOTE">$values[$n]</textarea>}"
-    done)
-    <h3>$(l10n X-CLIENT-REFERRAL)</h3>
-    <input class="item X-CLIENT-REFERRAL" name="X-CLIENT-REFERRAL" value="$values[X-CLIENT-REFERRAL]" />
-    $(for n in X-CLIENT-REFERRAL{0..10}; do
-      echo "${values[$n]:+<input class="item X-CLIENT-REFERRAL" name="X-CLIENT-REFERRAL" value="'$values[$n]'" />}"
-    done)
+    $(list_items NOTE)
+    $(list_items X-CLIENT-REFERRAL)
   </div>
 
   <div class="control">
     <select class="item" name="newfield">
       <option value="" disabled="disabled" selected="selected">$(l10n edit_addfieldtext)</option>
-      $(for f in $SUP_FIELDS; do echo "<option value=\"$f\">$(l10n $f)</option>"; done)
+      $(for f in $SUP_FIELDS; do printf %s\\n "<option value=\"$f\">$(l10n $f)</option>"; done)
     </select
     ><button class="item" type="submit" name="action" value="addfield">$(l10n edit_addfield)</button>
     <button class="item" type="submit" name="action" value="update">$(l10n edit_update)</button>
     <input type="checkbox" id="delete"><label class="item" for="delete">$(l10n edit_delete)</label>
-    <button class="item" type="submit" name="action" value="delete">$(l10n edit_delete)</button>
+      <button class="item" type="submit" name="action" value="delete">$(l10n edit_delete)</button>
     <button class="item" type="submit" name="action" value="cancel">$(l10n edit_cancel)</button>
   </div>
   <input type="hidden" name="UID" value="$values[UID]"/>