]> git.plutz.net Git - lobster/commitdiff
basic editing functions for new view
authorpaul <paul@plutz.net>
Thu, 28 Nov 2013 04:13:49 +0000 (04:13 +0000)
committerpaul <paul@plutz.net>
Thu, 28 Nov 2013 04:13:49 +0000 (04:13 +0000)
svn path=/trunk/; revision=23

templates/attendees.html.sh
templates/edit_attendee.sh

index 337de1019fc45b7270eafdbd8ba9788c93ef1148..a237d3eea8ea85da6896762878eb6734025402f6 100644 (file)
@@ -43,13 +43,6 @@ $(listcards |while read card; do
     <form action="/?action=update_attendee" method="POST">
       <input type="hidden" name="card" value="${id}"/>
       $(edit_attendee "$id")
-      <br /><select name="newfield">
-       <option value="" disabled="disabled" selected="selected">$(l10n edit_addfieldtext)</option>
-       $(for f in $VCF_FIELDS; do echo "<option value=\"$f\">$(l10n $f)</option>"; done)
-      </select>
-      <button type="submit" name="action" value="addfield">$(l10n edit_addfield)</button>
-      <br /><button type="submit" name="action" value="update">$(l10n edit_update)</button>
-      <br /><button type="submit" name="action" value="cancel">$(l10n edit_cancel)</button>
     </form>
   </div>
 x_EOF
index cb0b5b17010afbbf8f0ddf2f3477aa256cfc001f..13b550a407ee446482203f9668b3050ca3d31a7a 100755 (executable)
@@ -1,39 +1,92 @@
-edit_card_item() {
-  case "$key" in
-    BEGIN|VERSION|END|FN);;
-    PHOTO)
-      echo "<img class=\"PHOTO\" src=\"data:image/$tag[TYPE];base64,$value\"/>"
-      ;;
-    *)
-      echo -n "<span class=\"item\"><span class=\"KEY\">$(l10n "$key")"
-      [ -n "$tag[TYPE]" ] && echo -n "($tag[TYPE])"
-      echo ":</span>"
-      ;|
-    N)
-      n_last="$(echo "$value" |sed -r 's:^([^;]*;){0} *([^;]*);.*$:\2:')"
-      n_first="$(echo "$value" |sed -r 's:^([^;]*;){1} *([^;]*);.*$:\2:')"
-      n_middle="$(echo "$value" |sed -r 's:^([^;]*;){2} *([^;]*);.*$:\2:')"
-      n_pre="$(echo "$value" |sed -r 's:^([^;]*;){3} *([^;]*);.*$:\2:')"
-      n_post="$(echo "$value" |sed -r 's:^([^;]*;){4} *([^;]*);*$:\2:')"
-      echo "<input class=\"VALUE\" name=\"3$key\" value=\"$n_pre\" placeholder=\"$(l10n n_pre)\" />"
-      echo "<input class=\"VALUE\" name=\"1$key\" value=\"$n_first\" placeholder=\"$(l10n n_first)\" />"
-      echo "<input class=\"VALUE\" name=\"2$key\" value=\"$n_middle\" placeholder=\"$(l10n n_middle)\" />"
-      echo "<input class=\"VALUE\" name=\"0$key\" value=\"$n_last\" placeholder=\"$(l10n n_last)\" />"
-      echo "<input class=\"VALUE\" name=\"4$key\" value=\"$n_post\" placeholder=\"$(l10n n_post)\" /></span>"
-      echo "<button name=\"deletefield\" value=\"$key $value\">$(l10n edit_deletefield)</button>"
-      ;;
-    *)
-      echo "<input class=\"VALUE\" name=\"$key\" value=\"$value\" /></span>"
-      echo "<button name=\"deletefield\" value=\"$key $value\">$(l10n edit_deletefield)</button>"
-      ;;
-  esac
+edit_card() {
+  n_last="$(echo "$values[N]" |sed -r 's:^([^;]*;){0} *([^;]*);.*$:\2:')"
+  n_first="$(echo "$values[N]" |sed -r 's:^([^;]*;){1} *([^;]*);.*$:\2:')"
+  n_middle="$(echo "$values[N]" |sed -r 's:^([^;]*;){2} *([^;]*);.*$:\2:')"
+  n_pre="$(echo "$values[N]" |sed -r 's:^([^;]*;){3} *([^;]*);.*$:\2:')"
+  n_post="$(echo "$values[N]" |sed -r 's:^([^;]*;){4} *([^;]*);*$:\2:')"
+
+
+  echo '  <div class="section basic">'
+  echo '    <span class="sectitle">'$(l10n NAME)'</span>'
+  echo '    <input class="item N" name="3N" placeholder="'$(l10n n_pre)'" value="'$n_pre'" />'
+  echo '    <input class="item N" name="1N" placeholder="'$(l10n n_first)'" value="'$n_first'" />'
+  echo '    <input class="item N" name="2N" placeholder="'$(l10n n_middle)'" value="'$n_middle'" />'
+  echo '    <input class="item N" name="0N" placeholder="'$(l10n n_last)'" value="'$n_last'" />'
+  echo '    <input class="item N" name="4N" placeholder="'$(l10n n_post)'" value="'$n_post'" />'
+  [ -n "$value[GENDER]" ] && \
+    echo '    <span class="item GENDER">'$(l10n $values[GENDER])'</span>'
+  for n in NICKNAME NICKNAME{0..10}; do [ -n "$values[$n]" ] &&\
+    echo '    <span class="item NICKNAME">aka. '$values[$n]'</span>'
+  done
+  [ -n "$values[BDAY]" ] &&\
+    echo '    <span class="item BDAY"><b>*:</b> '$values[BDAY]'</span>'
+  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
+  [ -n "$values[PHOTO]" ] &&\
+    echo '    <img class="item PHOTO" src="data:image/'$tags[PHOTO_TYPE]';base64,'$values[PHOTO]'" />'
+  [ -n "$values[LOGO]" ] &&\
+    echo '    <img class="item LOGO" src="data:image/'$tags[LOGO_TYPE]';base64,'$values[LOGO]'" />'
+  echo '  </div>'
+  echo ''
+  echo '  <div class="section phone">'
+  echo '    <span class="sectitle">'$(l10n TEL)'</span>'
+  for n in TEL TEL{0..10}; do [ -n "$values[$n]" ] &&\
+    echo '    <span class="item TEL">'$tags[${n}_TYPE]' '$values[$n]'</span>'
+  done
+  echo '  </div>'
+  echo ''
+  echo '  <div class="section message">'
+  echo '    <span class="sectitle">'$(l10n EMAIL)'</span>'
+  for n in EMAIL EMAIL{0..10}; do [ -n "$values[$n]" ] &&\
+    echo '    <span class="item EMAIL"><a href="mailto:'$values[$n]'">'$values[$n]'</a></span>'
+  done
+  [ -n "$values[IMPP]" ] && \
+    echo '    <span class="sectitle">'$(l10n IMPP)'</span>'
+  for n in IMPP IMPP{0..10}; do [ -n "$values[$n]" ] &&\
+    echo '    <span class="item IMPP">'$tags[${n}_TYPE]' <a href="'$values[$n]'">'$values[$n]'</a></span>'
+  done
+  echo '  </div>'
+  echo ''
+  echo '  <div class="section address">'
+  echo '    <span class="sectitle">'$(l10n ADR)'</span>'
+  for n in ADR ADR{0..10}; do [ -n "$values[$n]" ] &&\
+    echo '    <span class="item ADR">'$values[$n]'</span>'
+  done
+  [ -n "$values[URL]" ] && \
+    echo '    <span class="sectitle">'$(l10n URL)'</span>'
+  for n in URL URL{0..10}; do [ -n "$values[$n]" ] &&\
+    echo '    <span class="item URL"><a href="'$values[$n]'">'$values[$n]'</a></span>'
+  done
+  echo '  </div>'
+  echo ''
+  echo '  <div class="section note">'
+  echo '    <span class="sectitle">'$(l10n NOTE)'</span>'
+  for n in NOTE NOTE{0..10}; do [ -n "$values[$n]" ] &&\
+    echo '    <span class="item IMPP">'$values[$n]'</span>'
+  done
+  echo '  </div>'
+  echo ''
+  echo '  <div class="section control">'
+  echo '    <select class="item control" name="newfield">'
+  echo '      <option value="" disabled="disabled" selected="selected">'$(l10n edit_addfieldtext)'</option>'
+              for f in $VCF_FIELDS; do echo "<option value=\"$f\">$(l10n $f)</option>"; done
+  echo '    </select>'
+  echo '    <button class="item control" type="submit" name="action" value="addfield">'$(l10n edit_addfield)'</button>'
+  echo '    <button class="item control" type="submit" name="action" value="update">'$(l10n edit_update)'</button>'
+  echo '    <button class="item control" type="submit" name="action" value="cancel">'$(l10n edit_cancel)'</button>'
+  echo '  </div>'
 }
 
-edit_attendee() {
-  cardfile="vcard/$1"
-  tempfile="temp/$1"
-  [ -f "$tempfile" ] && cardfile="$tempfile"
+edit_attendee() {  #Parameter: Cardfile
+  id="$1"
+  cardfile="vcard/$id"
   unset key
+
+  declare -A tags
+  declare -A values
   vcf_parse "$cardfile" |while read -r line; do
     declare -A tag
     case "$line" in
@@ -43,12 +96,21 @@ edit_attendee() {
         if [ -z "$key" ]; then
           eval "$line"
         else
-          edit_card_item
+          values[$key]="$value"
+          for t in ${(k)tag}; do
+            tags[${key}_$t]="$tag[$t]"
+          done
           eval "$line"
-         unset value
-         unset tag
+          if [ -n "$values[$key]" ]; then
+            n=0
+            while [ -n "$values[$key$n]" ]; do n=$(($n + 1)); done
+            key=$key$n
+          fi
+           unset value
+           unset tag
         fi
       ;;
     esac
   done
+  edit_card
 }