Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add ability to save a post

  • Loading branch information...
commit e169a763bbe54b03cb624c98b3322a468b5d194b 1 parent d23bca9
Austin Seipp authored
Showing with 20 additions and 12 deletions.
  1. +17 −10 src/admin.opa
  2. +3 −2 src/post.opa
View
27 src/admin.opa
@@ -11,7 +11,6 @@ import opaque.bsl.mathjax
import opaque.bsl.shjs
import opaque.bsl.upskirt
-
// User types and user database
type Admin.user = { passwd: string }
type Admin.status = { loggedin: string } / { notloggedin }
@@ -51,9 +50,9 @@ Admin = {{
/* Main administrative page */
adminpage() =
Layout.styled_page("Admin page",
+ <h3><a onclick={_ -> newpost()}>Create new post</a></h3>
<h3><a onclick={_ -> changepw()}>Change password</a></h3>
<h3><a onclick={_ -> logout()}>Logout</a></h3>
- <h3><a onclick={_ -> newpost()}>New post</a></h3>
)
/* Changing passwords */
@@ -70,14 +69,22 @@ Admin = {{
Layout.transform_content(update_form)
/* New posts */
+ post_from_dom() = { title = Dom.get_value(#post_title);
+ date = Date.now();
+ content = Dom.get_value(#post_content);
+ author = Config.author }
+
@private @publish update_preview() =
- p : Post.post = { title = Dom.get_value(#post_title);
- date = Date.now();
- content = Dom.get_value(#post_content);
- author = Config.author }
- do Dom.transform([#preview_output <- Post.to_xhtml(p)])
- do MathJax.reload(#preview_output)
- SHJS.highlight()
+ do Dom.transform([#preview_output <- Post.to_xhtml(post_from_dom())])
+ do MathJax.reload(#preview_output)
+ SHJS.highlight()
+
+ @private save_post() =
+ do Post.insert_new_post(post_from_dom())
+ Layout.transform_content(
+ <h1>Post saved</h1><br />
+ <h3><a href="/admin">Go back to admin page</a></h3>
+ )
newpost() =
post_form() =
@@ -85,7 +92,7 @@ Admin = {{
<input cols=80 id=#post_title /><br />
<textarea rows=20 cols=80 id=#post_content /><br />
<button type="button" onclick={_ -> update_preview()}>Preview</button><br />
- <button type="button" >Publish</button><br />
+ <button type="button" onclick={_ -> save_post()}>Publish</button><br />
<h3><a href="/admin">Go back to admin page</a></h3>
</div>
<br/>
View
5 src/post.opa
@@ -13,12 +13,13 @@ db /posts : intmap(Post.post)
@server Post = {{
- insert_post(p) = /posts[?] <- p
+ insert_new_post(p) = /posts[?] <- p
+ update_post(i,p) = /posts[i] <- p
get_posts() = /posts
get_post(i) = ?/posts[i]
posts_to_list() =
- Map_make(Int.order).To.val_list(get_posts())
+ List.rev(Map_make(Int.order).To.val_list(get_posts()))
to_xhtml(p) =
content = Upskirt.render_to_xhtml(p.content)
Please sign in to comment.
Something went wrong with that request. Please try again.