]> git.plutz.net Git - bookman/blobdiff - index.cgi
UI for folder modification
[bookman] / index.cgi
old mode 100644 (file)
new mode 100755 (executable)
index 8129b7e..3cf7e29
--- a/index.cgi
+++ b/index.cgi
@@ -72,6 +72,13 @@ getFavicon(){
   chmod a+r "$file"
 }
 
+list_folders(){
+  head -qn1 "${BDB}"/????????????.bm \
+  | sort -nk3 \
+  | cut -f1,2
+}
+
+
 QRYID="$(GET    id |checkid)"
 COKID="$(COOKIE id |checkid)"
 BDB="users/${QRYID}"
@@ -203,64 +210,83 @@ list_bookmarks(){
   done
 }
 
-list_folders(){
+foldermod(){
   fmodify="$(GET fmodify |checkid )"
   fdelete="$(GET fdelete |checkid )"
   fmove="$(GET fmove |checkid )"
 
-  head -qn1 "${BDB}"/????????????.bm \
-  | sort -nk3 \
-  | while read fid fname order; do
+  if [ -n "$fmodify" ]; then
+    read fid fname order <"${BDB}/${fmodify}.bm"
     cat <<-EOF
-       <section class="folder" id="${fid}">
-         <h1>${fname}</h1>
-         <a class="modify" href="${SCRIPT_NAME}?id=${QRYID}&fmodify=${fid}">Modify</a>
-         $(list_bookmarks "$fid")
-          <form class="newbookmark" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&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>
-       </section>
-       EOF
-    if [ "$fid" = "$fmodify" ]; then
-      cat <<-EOF
        <form class="modfolder rename" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=modfolder">
+          <h1>Rename Folder: ${fname}</h1>
          <input type="hidden" name="fid" value="${fid}" />
-          <label>Rename</label><a
-           href="${SCRIPT_NAME}?id=${QRYID}&fdelete=${fid}">Delete</a><a
+         <label class="tab">Rename</label>
+         <a class="tab"
+           href="${SCRIPT_NAME}?id=${QRYID}&fdelete=${fid}">Delete</a>
+         <a class="tab"
            href="${SCRIPT_NAME}?id=${QRYID}&fmove=${fid}">Move</a>
          <input type="text" name="name" value="${fname}" />
          <button type="submit" name="control" value="confirm">OK</button>
          <button type="submit" name="control" value="cancel">Cancel</button>
        </form>
        EOF
-    elif [ "$fid" = "$fdelete" ]; then
-      cat <<-EOF
-       <form class="modfolder delete" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=modfolder">
+  elif [ -n "$fdelete" ]; then
+    read fid fname order <"${BDB}/${fdelete}.bm"
+    cat <<-EOF
+       <form class="modfolder delete" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=delfolder">
+          <h1>Delete Folder: ${fname}</h1>
          <input type="hidden" name="fid" value="${fid}" />
-         <a href="${SCRIPT_NAME}?id=${QRYID}&fmodify=${fid}">Rename</a><label
-            >Delete</label><a
+         <a class="tab" href="${SCRIPT_NAME}?id=${QRYID}&fmodify=${fid}">Rename</a>
+         <label class="tab">Delete</label>
+         <a class="tab"
            href="${SCRIPT_NAME}?id=${QRYID}&fmove=${fid}">Move</a>
-         <input type="text" name="name" value="${fname}" />
+         <label>Pass Bookmarks on to:</label>
+         <select name="target">
+           $(printf '<option value="%s">%s</option>' $(list_folders |grep -v "^${fid}"))
+           <option value="____________">(none)</option>
+         </select>
          <button type="submit" name="control" value="confirm">OK</button>
          <button type="submit" name="control" value="cancel">Cancel</button>
        </form>
        EOF
-    elif [ "$fid" = "$fmove" ]; then
-      cat <<-EOF
+  elif [ -n "$fmove" ]; then
+    read fid fname order <"${BDB}/${fmove}.bm"
+    cat <<-EOF
        <form class="modfolder move" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=modfolder">
+          <h1>Move Folder: ${fname}</h1>
          <input type="hidden" name="fid" value="${fid}" />
-         <a href="${SCRIPT_NAME}?id=${QRYID}&fmodify=${fid}">Rename</a><a
-           href="${SCRIPT_NAME}?id=${QRYID}&fdelete=${fid}">Delete</a><label
-           >Move</label>
-         <input type="text" name="name" value="${fname}" />
+         <a class="tab" href="${SCRIPT_NAME}?id=${QRYID}&fmodify=${fid}">Rename</a>
+         <a class="tab" href="${SCRIPT_NAME}?id=${QRYID}&fdelete=${fid}">Delete</a>
+         <label class="tab">Move</label>
+         <label>Move before folder:</label>
+         <select name="target">
+           $(printf '<option value="%s">%s</option>' $(list_folders |grep -v "^${fid}"))
+           <option value="____________">(last)</option>
+         </select>
          <button type="submit" name="control" value="confirm">OK</button>
          <button type="submit" name="control" value="cancel">Cancel</button>
        </form>
        EOF
-    fi
+  fi
+}
+
+show_folders(){
+  list_folders \
+  | while read fid fname order; do
+    cat <<-EOF
+       <section class="folder" id="${fid}">
+         <h1>${fname}</h1>
+         <a class="modify" href="${SCRIPT_NAME}?id=${QRYID}&fmodify=${fid}">Modify</a>
+         $(list_bookmarks "$fid")
+          <form class="newbookmark" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&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>
+       </section>
+       EOF
   done
 }
 
@@ -271,7 +297,8 @@ cat <<EOF
   <title>Bookman - Your Collection</title>
   <link rel="stylesheet" type="text/css" href="bookmarks.css" />
 </head><body id="collection">
-  $(list_folders)
+  $(foldermod)
+  $(show_folders)
   <form class="newfolder" method="POST" action="${SCRIPT_NAME}?id=${QRYID}&action=newfolder">
     <input type="text" name="name" value="" placeholder="New Folder" />
     <button type="submit">New</button>