]> git.plutz.net Git - bookman/commitdiff
bookmark creation dialog
authorpaul <paul@plutz.net>
Sat, 9 Dec 2017 18:24:53 +0000 (18:24 +0000)
committerpaul <paul@plutz.net>
Sat, 9 Dec 2017 18:24:53 +0000 (18:24 +0000)
svn path=/trunk/; revision=14

bookmarks.css
index.cgi

index 6c6b54b1f8f79d98e7d4634db9a3a11472be1cbd..e37d70af0e3ad306e0aae0a348c7f1c67d3a05e3 100644 (file)
@@ -45,8 +45,7 @@ html, body {
   color: #333;
 }
 
   color: #333;
 }
 
-.modbookmark,
-.modfolder {
+.dialog {
   display: block;
   position: fixed;
   width: 30em;
   display: block;
   position: fixed;
   width: 30em;
@@ -55,15 +54,14 @@ html, body {
   left: 50%; top: 20%;
   margin: -3em -15em;
   text-align: center;
   left: 50%; top: 20%;
   margin: -3em -15em;
   text-align: center;
-  z-index: 3;
+  z-index: 10;
   border-radius: .5em;
   border: 1px solid black;
   padding: .125em 0;
   background-color: #ACF;
   word-spacing: -.5ex;
 }
   border-radius: .5em;
   border: 1px solid black;
   padding: .125em 0;
   background-color: #ACF;
   word-spacing: -.5ex;
 }
-.modbookmark:before,
-.modfolder:before {
+.dialog:before {
   display: block;
   content: '';
   border: 1px solid black;
   display: block;
   content: '';
   border: 1px solid black;
@@ -74,69 +72,61 @@ html, body {
   background-color: white;
   z-index: -1;
 }
   background-color: white;
   z-index: -1;
 }
-.modbookmark + *:after,
-.modfolder + *:after {
+.newbookmark:before { border-top: 1px solid; }
+.dialog + *:after {
   content: ' ';
   position: fixed;
   top: 0; bottom: 0; left: 0; right: 0;
   background-color: rgba(0,0,0,.5);
 }
   content: ' ';
   position: fixed;
   top: 0; bottom: 0; left: 0; right: 0;
   background-color: rgba(0,0,0,.5);
 }
-.modbookmark > *,
-.modfolder > * { word-spacing: 0; }
+.dialog > * { word-spacing: 0; }
 
 
-.modbookmark > h1,
-.modfolder > h1 {
+.dialog > h1 {
   background-color: transparent;
   text-align: left;
   font-weight: bold;
   padding-left: .25em;
 }
 
   background-color: transparent;
   text-align: left;
   font-weight: bold;
   padding-left: .25em;
 }
 
-.modbookmark > .tab,
-.modfolder > .tab {
+.dialog > .tab {
   display: inline-block;
   width: 33%;
   padding: .25em;
   border: 1px solid black;
   border-radius: .5em .5em 0 0;
 }
   display: inline-block;
   width: 33%;
   padding: .25em;
   border: 1px solid black;
   border-radius: .5em .5em 0 0;
 }
-.modbookmark > .tab {
+.dialog.modbookmark > .tab {
   width: 49.5%;
 }
   width: 49.5%;
 }
-.modbookmark > label.tab,
-.modfolder > label.tab { border-bottom: 0px; }
-.modbookmark > a.tab,
-.modfolder > a.tab { background-color: #EEE; }
+.dialog > label.tab { border-bottom: 0px; }
+.dialog > a.tab { background-color: #EEE; }
 
 
-.modbookmark > label:nth-of-type(2),
-.modbookmark > label:nth-of-type(3),
-.modbookmark > select,
-.modfolder > label:nth-of-type(2),
-.modfolder > select,
+.newbookmark > label,
+.dialog > label:nth-of-type(2),
+.dialog > label:nth-of-type(3),
+.dialog > select,
 .modfolder > input {
   display: block;
   float: left;
   text-align: left;
   margin: 1em 0 0 1em;
 }
 .modfolder > input {
   display: block;
   float: left;
   text-align: left;
   margin: 1em 0 0 1em;
 }
-.modbookmark > label:nth-of-type(2),
-.modbookmark > label:nth-of-type(3),
-.modfolder > label:nth-of-type(2) {
+.newbookmark > label,
+.dialog > label:nth-of-type(3),
+.dialog > label:nth-of-type(2) {
+  clear: left;
   font-weight: bold;
 }
   font-weight: bold;
 }
-.modbookmark > select,
-.modfolder > select {
+.dialog > select {
   width: 10em;
   max-width: 95%;
 }
   width: 10em;
   max-width: 95%;
 }
-.modbookmark > input,
-.modfolder > input {
+.dialog > input {
   width: 28em;
   max-width: 95%;
 }
   width: 28em;
   max-width: 95%;
 }
-.modbookmark > button,
 .modbookmark > select,
 .modbookmark > select,
-.modfolder > button {
+.dialog > button {
   display: inline-block;
   float: right;
   margin: 1.5em .5em .5em .5em;
   display: inline-block;
   float: right;
   margin: 1.5em .5em .5em .5em;
@@ -181,7 +171,3 @@ html, body {
   margin: 0 .5ex;
 }
 
   margin: 0 .5ex;
 }
 
-form.newbookmark {
-  margin: .5em 1em;
-  break-inside: avoid;
-}
index 4f24149bd8f53024b5903c7e4a1ed37196185b22..911e5eed684715e6e67cf5413617b33752f831d9 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -173,7 +173,10 @@ case "$(GET action)" in
     file="${BDB}/${fid}.bm"
     tfile="${BDB}/${target}.bm"
     if [ "$(POST control)" = confirm -a -f "$file" ]; then
     file="${BDB}/${fid}.bm"
     tfile="${BDB}/${target}.bm"
     if [ "$(POST control)" = confirm -a -f "$file" ]; then
-      if [ "$target" = "____________" ] || tail -n+2 "$file" >>"$tfile"; then
+      if [ "$target" = "____________" ]; then
+        rm -f "$file" >&-
+        git -C "${BDB}" commit -m "Deleted folder ${fid}" -- "${fid}.bm" >&-
+      elif tail -n+2 "$file" >>"$tfile"; then
         rm -f "$file" >&-
         git -C "${BDB}" commit -m "Deleted folder ${fid}" -- "${fid}.bm" "${target}.bm" >&-
       fi
         rm -f "$file" >&-
         git -C "${BDB}" commit -m "Deleted folder ${fid}" -- "${fid}.bm" "${target}.bm" >&-
       fi
@@ -202,12 +205,19 @@ case "$(GET action)" in
     url="$(POST url |head -n1)"
     file="${BDB}/${fid}.bm"
     bid="$(timeid)"
     url="$(POST url |head -n1)"
     file="${BDB}/${fid}.bm"
     bid="$(timeid)"
-    if [ -n "$name" -a -f "${file}" ]; then
+    ctl="$(POST control)"
+    [ "$url" = "${url#*://}" ] && url="http://$url"
+
+    if [ -n "$name" -a -n "$url" -a -f "${file}" -a "$ctl" = "confirm" ]; then
       printf '%s\t%s\t%s\n' "$bid" "$(HTML "$name")" "$url" >>"${file}"
       git -C "${BDB}" commit -m "New Bookmark: ${name} in ${fid}" -- "${fid}.bm" >&-
       printf '%s\t%s\t%s\n' "$bid" "$(HTML "$name")" "$url" >>"${file}"
       git -C "${BDB}" commit -m "New Bookmark: ${name} in ${fid}" -- "${fid}.bm" >&-
+      getFavicon "$url" "$bid"
+      REDIRECT "${SCRIPT_NAME}#${fid}"
+    elif [ "$ctl" = "confirm" ]; then
+      REDIRECT "${SCRIPT_NAME}?newbm=${fid}&nbmurl=${url}&nbmname=${name}"
+    else
+      REDIRECT "${SCRIPT_NAME}#${fid}"
     fi
     fi
-    getFavicon "$url" "$bid"
-    REDIRECT "${SCRIPT_NAME}#${fid}"
     ;;
   modbookmark)
     bid="$(POST bid | checkid)"
     ;;
   modbookmark)
     bid="$(POST bid | checkid)"
@@ -272,6 +282,44 @@ case "$(GET action)" in
     ;;
 esac
 
     ;;
 esac
 
+bookmarkgen(){
+  fid="$(GET newbm |checkid)"
+  name="$(GET nbmname)"
+  url="$(GET nbmurl)"
+  file="${BDB}/${fid}.bm"
+
+  [ "$url" = "${url#*://}" ] && url="http://$url"
+  if [ -z "$name" -a -n "$url" ]; then
+    name="$(wget -O- "$url" \
+            | head -c4096 \
+            | sed -rn ':X;$bY;N;bX;:Y; s;^.*<title[^>]*>([^<]+)<.*$;\1;p;'
+          )"
+  fi
+
+  if [ -n "$fid" -o -n "$name" -o -n "$url" ]; then
+    cat <<-EOF
+       <form class="dialog newbookmark" method="POST" action="${SCRIPT_NAME}?action=newbookmark">
+          <h1>New Bookmark</h1>
+         <label>Folder:</label>
+         <select name="fid">
+           $(list_folders |while read id n; do
+             [ "$id" = "$fid" ] \
+             && printf '<option value="%s" selected="selected">%s</option>' "$id" "$n" \
+             || printf '<option value="%s">%s</option>' "$id" "$n"
+           done)
+           $(printf '<option value="%s">%s</option>' $(list_folders))
+         </select>
+         <label>Name:</label>
+         <input type="text" name="name" value="$(HTML ${name})")" placeholder="Name" />
+         <label>URL:</label>
+         <input type="text" name="url"  value="$(HTML "${url}")")" placeholder="URL" />
+         <button type="submit" name="control" value="confirm">OK</button>
+         <button type="submit" name="control" value="cancel">Cancel</button>
+       </form>
+       EOF
+  fi
+}
+
 bookmarkmod(){
   bmod="$(GET bmodify |checkid)"
   bmove="$(GET bmove |checkid)"
 bookmarkmod(){
   bmod="$(GET bmodify |checkid)"
   bmove="$(GET bmove |checkid)"
@@ -282,7 +330,7 @@ bookmarkmod(){
        $(grep -m1 "^${bmod}" "$file")
        EOF
     cat <<-EOF
        $(grep -m1 "^${bmod}" "$file")
        EOF
     cat <<-EOF
-       <form class="modbookmark" method="POST" action="${SCRIPT_NAME}?action=modbookmark">
+       <form class="dialog modbookmark" method="POST" action="${SCRIPT_NAME}?action=modbookmark">
          <input type="hidden" name="bid" value="${bid}" />
          <h1>Modify: ${name}</h1>
          <label class="tab">Modify</label>
          <input type="hidden" name="bid" value="${bid}" />
          <h1>Modify: ${name}</h1>
          <label class="tab">Modify</label>
@@ -301,7 +349,7 @@ bookmarkmod(){
        $(grep -m1 "^${bmove}" "$file")
        EOF
     cat <<-EOF
        $(grep -m1 "^${bmove}" "$file")
        EOF
     cat <<-EOF
-       <form class="modbookmark" method="POST" action="${SCRIPT_NAME}?action=movebookmark">
+       <form class="dialog modbookmark" method="POST" action="${SCRIPT_NAME}?action=movebookmark">
          <input type="hidden" name="bid" value="${bid}" />
          <h1>Move: ${name}</h1>
          <a class="tab" href="${SCRIPT_NAME}?bmodify=${bid}">Modify</a>
          <input type="hidden" name="bid" value="${bid}" />
          <h1>Move: ${name}</h1>
          <a class="tab" href="${SCRIPT_NAME}?bmodify=${bid}">Modify</a>
@@ -358,7 +406,7 @@ foldermod(){
   if [ -n "$fmodify" ]; then
     read fid fname order <"${BDB}/${fmodify}.bm"
     cat <<-EOF
   if [ -n "$fmodify" ]; then
     read fid fname order <"${BDB}/${fmodify}.bm"
     cat <<-EOF
-       <form class="modfolder rename" method="POST" action="${SCRIPT_NAME}?action=modfolder">
+       <form class="dialog modfolder rename" method="POST" action="${SCRIPT_NAME}?action=modfolder">
           <h1>Rename Folder: ${fname}</h1>
          <input type="hidden" name="fid" value="${fid}" />
          <label class="tab">Rename</label>
           <h1>Rename Folder: ${fname}</h1>
          <input type="hidden" name="fid" value="${fid}" />
          <label class="tab">Rename</label>
@@ -374,7 +422,7 @@ foldermod(){
   elif [ -n "$fdelete" ]; then
     read fid fname order <"${BDB}/${fdelete}.bm"
     cat <<-EOF
   elif [ -n "$fdelete" ]; then
     read fid fname order <"${BDB}/${fdelete}.bm"
     cat <<-EOF
-       <form class="modfolder delete" method="POST" action="${SCRIPT_NAME}?action=delfolder">
+       <form class="dialog modfolder delete" method="POST" action="${SCRIPT_NAME}?action=delfolder">
           <h1>Delete Folder: ${fname}</h1>
          <input type="hidden" name="fid" value="${fid}" />
          <a class="tab" href="${SCRIPT_NAME}?fmodify=${fid}">Rename</a>
           <h1>Delete Folder: ${fname}</h1>
          <input type="hidden" name="fid" value="${fid}" />
          <a class="tab" href="${SCRIPT_NAME}?fmodify=${fid}">Rename</a>
@@ -393,7 +441,7 @@ foldermod(){
   elif [ -n "$fmove" ]; then
     read fid fname order <"${BDB}/${fmove}.bm"
     cat <<-EOF
   elif [ -n "$fmove" ]; then
     read fid fname order <"${BDB}/${fmove}.bm"
     cat <<-EOF
-       <form class="modfolder move" method="POST" action="${SCRIPT_NAME}?action=movefolder">
+       <form class="dialog modfolder move" method="POST" action="${SCRIPT_NAME}?action=movefolder">
           <h1>Move Folder: ${fname}</h1>
          <input type="hidden" name="fid" value="${fid}" />
          <a class="tab" href="${SCRIPT_NAME}?fmodify=${fid}">Rename</a>
           <h1>Move Folder: ${fname}</h1>
          <input type="hidden" name="fid" value="${fid}" />
          <a class="tab" href="${SCRIPT_NAME}?fmodify=${fid}">Rename</a>
@@ -416,7 +464,7 @@ show_folders(){
   | while read fid fname order; do
     file="${BDB}/${fid}.bm"
     cache="${BDB}/${fid}.cache"
   | while read fid fname order; do
     file="${BDB}/${fid}.bm"
     cache="${BDB}/${fid}.cache"
-    if [ "${cache}" -nt "${file}" ]; then
+    if [ "${cache}" -nt "${file}" -a "${cache}" -nt "$0" ]; then
       cat "$cache"
     else
       tee "$cache" <<-EOF
       cat "$cache"
     else
       tee "$cache" <<-EOF
@@ -424,12 +472,7 @@ show_folders(){
          <h1>${fname}</h1>
          <a class="modify" href="${SCRIPT_NAME}?fmodify=${fid}">Modify folder "${fname}"</a>
          $(show_bookmarks "$fid")
          <h1>${fname}</h1>
          <a class="modify" href="${SCRIPT_NAME}?fmodify=${fid}">Modify folder "${fname}"</a>
          $(show_bookmarks "$fid")
-          <form class="newbookmark" method="POST" action="${SCRIPT_NAME}?action=newbookmark">
-           <input type="hidden" name="fid" value="${fid}" />
-           <input type="text" name="name" value="" placeholder="Name" />
-           <input type="text" name="url"  value="" placeholder="URL" />
-           <button type="submit">New Bookmark</button>
-          </form>
+          <a class="new bookmark" href="${SCRIPT_NAME}?newbm=${fid}">New Bookmark</a>
        </section>
        EOF
     fi
        </section>
        EOF
     fi
@@ -447,6 +490,7 @@ cat <<EOF
 </head><body id="collection">
   $(foldermod)
   $(bookmarkmod)
 </head><body id="collection">
   $(foldermod)
   $(bookmarkmod)
+  $(bookmarkgen)
   $(show_folders)
   <form class="newfolder" method="POST" action="${SCRIPT_NAME}?action=newfolder">
     <input type="text" name="name" value="" placeholder="New Folder" />
   $(show_folders)
   <form class="newfolder" method="POST" action="${SCRIPT_NAME}?action=newfolder">
     <input type="text" name="name" value="" placeholder="New Folder" />