changeset 10:2cd590fc87bf draft

Viewing and posting comments
author e085711
date Thu, 13 Sep 2012 11:18:22 +0900
parents 87c015a99196
children c8e930683c14
files app/views/Application/show.html app/views/main.html
diffstat 2 files changed, 44 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/app/views/Application/show.html	Thu Sep 13 11:06:17 2012 +0900
+++ b/app/views/Application/show.html	Thu Sep 13 11:18:22 2012 +0900
@@ -1,6 +1,11 @@
 #{extends 'main.html' /}
 #{set title:post.title /}
 
+#{if flash.success}
+    <p class="success">${flash.success}</p>
+#{/if}
+ 
+#{display post:post, as:'full' /}
 
 <ul id="pagination">
 	#{if post.previous()}
@@ -19,26 +24,42 @@
 	#{/if}
 </ul>
 
-#{display post:post, as:'full' /}
-
-<h3> Post a comment</h3>
-
+<h3>Post a comment</h3>
+ 
 #{form @Application.postComment(post.id)}
+ 
+    #{ifErrors}
+        <p class="error">
+            All fields are required!
+        </p>
+    #{/ifErrors}
+ 
+    <p>
+        <label for="author">Your name: </label>
+        <input type="text" name="author" id="author" value="${params.author}" />
+    </p>
+    <p>
+        <label for="content">Your message: </label>
+        <textarea name="content" id="content">${params.content}</textarea>
+    </p>
+    <p>
+        <input type="submit" value="Submit your comment" />
+    </p>
+#{/form}
 
-	#{ifErrors}
-		<p class="error">
-			All fields are required!
-		</p>
-	#{/ifErrors}
-	<p>
-		<label for="author">Your name:</label>
-		<input type="text" name="author" id="author" value="${params.author}" />
-	</p>
-	<p>
-		<label for="content">Your message:</label>
-		<textarea name="content" id="content">${params.content}</textarea>
-	</p>
-	<p>
-		<input type="submit" value="Submit your comment"/>
-	</p>
-#{/form}
+<script type="text/javascript" charset="utf-8">
+    $(function() {         
+        // Expose the form 
+        $('form').click(function() { 
+            $('form').expose({api: true}).load(); 
+        }); 
+        
+        // If there is an error, focus to form
+        if($('form .error').size()) {
+            $('form').expose({api: true, loadSpeed: 0}).load(); 
+            $('form input[type=text]').get(0).focus();
+        }
+    });
+</script>
+
+
--- a/app/views/main.html	Thu Sep 13 11:06:17 2012 +0900
+++ b/app/views/main.html	Thu Sep 13 11:18:22 2012 +0900
@@ -7,6 +7,8 @@
             href="@{'/public/stylesheets/main.css'}" />
         <link rel="shortcut icon" type="image/png" 
             href="@{'/public/images/favicon.png'}" />
+		<script src="@{'/public/javascripts/jquery-1.6.4.min.js'}"></script>
+		<script src="@{'/public/javascripts/jquery.tools.min.js'}"></script>
     </head>
     <body>