]> git.plutz.net Git - busy/blobdiff - templates/Home.page
porting busy to confetti framework
[busy] / templates / Home.page
diff --git a/templates/Home.page b/templates/Home.page
new file mode 100644 (file)
index 0000000..67d41fb
--- /dev/null
@@ -0,0 +1,97 @@
+#!/bin/zsh
+
+switchbutton(){
+  hide="$1"; shift 1;
+  show="$1"; shift 1;
+  text="$*"
+  cat <<EOF
+  <a class="function" href="#${show}" onclick='javascript:hide_screen("${hide}");show_screen("${show}");'>${text}</a>
+EOF
+}
+
+edit_intro(){
+  cat <<HomeEND
+      <div id="introedit" style="display: none;">
+        <form action="/?action=introedit&i=intro" method="post" accept-charset="UTF-8">
+          <textarea name="text" rows="10">$([ -r "Home/intro" ] && cat Home/intro)</textarea><br>
+          <input type="submit">
+          $(switchbutton introedit introtext Cancel) 
+        </form>
+      </div>
+HomeEND
+}
+
+add_news(){
+  cat <<HomeEND
+  <div class="NEWS">
+    <a id="new" class='function' href='#add' onclick='javascript:hide_screen("new");show_screen("add");'>Add News</a>
+    <div id="add" style="display: none;">
+      <form action="/?action=introedit&i=news" method="post" accept-charset="UTF-8">
+        <textarea name="text" rows="10"></textarea><br>
+        <input type="submit">
+        $(switchbutton add new Cancel)
+      </form>
+    </div>
+  </div>
+HomeEND
+}
+
+edit_news(){
+  each="$1"
+  info="$(sed 's:Home/::;s:.news::' <<<"$each")"
+
+  cat <<HomeEND
+      <div id="edit_$info" style="display: none;">
+        <form action="/?action=introedit&i=$info" method="post" accept-charset="UTF-8">
+          <textarea name="text" rows="10">$([ -r "$each" ] && cat $each)</textarea><br>
+          <input type="submit">
+          $(switchbutton edit_$info news_$info Cancel)
+        </form>
+      </div>
+HomeEND
+}
+
+show_news(){
+  stat -c '' Home/<0000000000-9999999999>_<000-999>.news && for each in $(ls -c Home/<0000000000-9999999999>_<000-999>.news); do
+    info="$(sed 's:Home/::;s:.news::' <<<"$each")"
+
+    cat <<HomeEND
+    <div class="NEWS">
+      <div id="news_$info"><div class="wikitext">
+      $([ -r "$each" ] && _wiki "$each")
+      $($ACL_EDITNEWS && echo "<hr/>$(switchbutton news_$info edit_$info Edit)")
+      </div></div>
+      $($ACL_EDITNEWS && edit_news $each)
+    </div>
+HomeEND
+  done
+}
+
+cat <<HomeEND
+  <div id="LEFT">
+    <form method="GET" action="/${SCRIPTNAME}" accept-charset="utf-8">
+      <input type="hidden" name="p" value="Home">
+      <input type="text" name="s" placeholder="Search"><br>
+      <input type="submit" value="Search News">
+    </form>
+    <hr>
+    $(searchresults)
+  </div>
+
+  <div id="MAIN">
+    <div id="INTRO">
+      <div id="introtext"><div class="wikitext">
+      $([ -r "Home/intro" ] && _wiki "Home/intro")
+      $($ACL_EDITINTRO && echo "<hr/> $(switchbutton introtext introedit Edit)")
+      </div></div>
+      $($ACL_EDITINTRO && edit_intro)
+    </div>
+
+    $($ACL_ADDNEWS && add_news)
+
+    $(show_news)
+  </div>
+  <div id="RIGHT">
+  $(sponsored)
+  </div>
+HomeEND