Author: bdelacretaz
Date: Mon May 31 13:31:56 2010
New Revision: 949738

URL: http://svn.apache.org/viewvc?rev=949738&view=rev
Log:
SLING-1540 - espblog sample failed with 'currentNode is not defined'

Modified:
    
sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/edit.esp
    
sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/html.esp

Modified: 
sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/edit.esp
URL: 
http://svn.apache.org/viewvc/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/edit.esp?rev=949738&r1=949737&r2=949738&view=diff
==============================================================================
--- 
sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/edit.esp
 (original)
+++ 
sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/edit.esp
 Mon May 31 13:31:56 2010
@@ -21,7 +21,33 @@
 
 <html>
 <%
-pageTitle = currentNode.title ? currentNode.title : "New post";
+// Check if we have a currentNode
+var currentNodeProvided = ((typeof currentNode != "undefined") && 
currentNode.title != null); 
+function getCurrentNodeValue(prop) {
+    var result = "";
+    if(currentNodeProvided && currentNode[prop]) {
+        result = currentNode[prop];
+    }
+    return result;
+}
+
+// Compute path to used for the POST request, different
+// depending on existence of a current node or not
+var postPath = null;
+var pageTitle = null;
+if(currentNodeProvided) {
+    postPath = currentNode.getPath();
+    pageTitle = currentNode.title;
+} else {
+    postPath = request.getContextPath() + "";
+    if(postPath.length > 0) {
+        postPath += "/";
+    }
+    postPath += request.getPathInfo();
+    pageTitle = "New post";
+}
+
+// Load header utility
 load("header.esp");
 %>
        <body>
@@ -41,15 +67,20 @@ load("header.esp");
        </div>
        
        <div class="main">
-                       <h1><%= pageTitle %></h1>
+            <h1><%= pageTitle %></h1>
+                       
+            <p>
+                Note that you need to <a 
href="?sling:authRequestLogin=1">login</a> 
+                before creating or editing a post.
+            </p> 
                                        
-                       <form class="hform" method="POST" action="<%= 
currentNode.getPath().lastIndexOf("*") != currentNode.getPath().length-1 ? 
currentNode : "/content/espblog/posts/*" %>" enctype="multipart/form-data">     
                                       
+                       <form class="hform" method="POST" action="<%= postPath 
%>" enctype="multipart/form-data">                                              
 
                                        
                                        <p><label>Title</label>
-                                       <input name="title" type="text" 
size="80" value="<%= currentNode.getPath().lastIndexOf("*") != 
currentNode.getPath().length-1 ? currentNode.title : "" %>"></p>
+                                       <input name="title" type="text" 
size="80" value="<%= getCurrentNodeValue("title") %>"></p>
                                        
                                        <p><label>Body</label>
-                                       <textarea name="posttext" cols="40" 
rows="5"><%= currentNode.getPath().lastIndexOf("*") != 
currentNode.getPath().length-1 ? currentNode.posttext : "" %></textarea></p>
+                                       <textarea name="posttext" cols="40" 
rows="5"><%=  getCurrentNodeValue("posttext") %></textarea></p>
                                        
                                        <p><label>File</label><input 
type="file" name="attachments/*"/></p>
 
@@ -61,4 +92,4 @@ load("header.esp");
                        </form>
                </div>                                  
        </body>
-</html>
+</html>
\ No newline at end of file

Modified: 
sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/html.esp
URL: 
http://svn.apache.org/viewvc/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/html.esp?rev=949738&r1=949737&r2=949738&view=diff
==============================================================================
--- 
sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/html.esp
 (original)
+++ 
sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/html.esp
 Mon May 31 13:31:56 2010
@@ -86,6 +86,10 @@ function renderMedia(postNode, mediaFold
                                <% if(currentNode.title) { %>                   
                                
                            <h3>Comment on this post</h3>
                                <form class="hform" method="POST" 
action="<%=currentNode%>/comments/*">
+                    <p>
+                        Note that you need to <a 
href="?sling:authRequestLogin=1">login</a> 
+                        before commenting on this post.
+                    </p> 
                                        <p><label>Your name</label><input 
type="text" size="80" name="commenter"/></p>
                                        <p><label>Your comment</label>
                                        <textarea name="commenttext" 
cols="40"></textarea></p>


Reply via email to