root/main/trunk/greenstone3/web/interfaces/default/transform/layouts/usercomments.xsl @ 31543

Revision 31543, 4.5 KB (checked in by ak19, 3 years ago)

Next incremental change to adding user comments in GS3. This time to make the get-meta-array and set-meta-array functions be called asynchronously from user_comments.js (these operations can be called synchronously by any others wishing to tuse them, and do so by default). user_comments.js chooses to call get-meta-array and even set-meta-array asynchronously by passing in the appropriate flag to make the ajax calls asynchronous. To protect against any overlapping read/write issues and mutliple submit comments (set-meta-array calls) from being fired off with overlap, the submit button gets disabled until the set-meta-array call has returned and its callback is called. Similarly, the submit button is disabled until the page has finished loading existing user comments (get-meta-array call).

1<?xml version="1.0" encoding="ISO-8859-1"?>
2<xsl:stylesheet version="1.0"
3    xmlns:xsl=""
4    xmlns:java=""
5    xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
6    xmlns:gslib=""
7    xmlns:gsf=""
8    extension-element-prefixes="java util"
9    exclude-result-prefixes="java util gsf">
11<xsl:template name="userCommentsSection">
13  <!-- 1. Make some variables available to javascript that the usercomments related js functions need -->
14  <gsf:variable name="d"><xsl:value-of select="/page/pageRequest/paramList/param[@name='d']/@value"/></gsf:variable>
15  <gsf:variable name="c"><xsl:value-of select="/page/pageRequest/paramList/param[@name='c']/@value"/></gsf:variable>
16  <gsf:variable name="site"><xsl:value-of select="/page/pageResponse/interfaceOptions/option[@name='site_name']/@value"/></gsf:variable>
18  <gsf:variable name="textusercommentssection"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.heading')"/></gsf:variable>
19  <gsf:variable name="textisempty"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.isempty')"/></gsf:variable>
20  <gsf:variable name="textcommentsubmitted"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.submitted')"/></gsf:variable>
22  <!-- 2. Load the javascript, which will do stuff on window load/ready for which it needs the above gs.variables -->
23  <script type="text/javascript" src="interfaces/{$interface_name}/js/gsajaxapi.js"><xsl:text> </xsl:text></script>
24  <script type="text/javascript" src="interfaces/{$interface_name}/js/user_comments.js"><xsl:text> </xsl:text></script>
27  <!-- 3. Set up the User comments section in the HTML -->
28  <div id="commentssection" class="centrediv">   
29    <div id="usercomments">
30      <!-- A heading for the comment section will be added here dynamically either if
31       previously submitted comments exist, or if the form#usercommentform to add
32       a new comment is displayed. Otherwise only the "Add Comments" link is shown. -->
33      <xsl:comment>Existing comments will be loaded dynamically loaded into this div#usercomments</xsl:comment>
34    </div>
36    <!-- If the user's logged in, show the comment form, else show the link to the login page -->
37    <xsl:choose>
38      <xsl:when test="/page/pageRequest/userInformation">   
39    <!-- Logged in, allow user to add a comment by displaying a form -->
40    <form name="AddUserCommentForm" id="usercommentform">
41      <input type="hidden" name="username"><xsl:attribute name="value"><xsl:value-of select="/page/pageRequest/userInformation/@username"/></xsl:attribute></input>
42      <div>
43        <p><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.add')"/></p>
44        <!-- The textarea will be added in by javascript into div#commentarea to avoid the problem of XML turning empty tags into self-closing ones and a self-closing text-area becomes invalid HTML -->
45        <!--<textarea required="required" name="comment" rows="10" cols="64" placeholder="Add your comment here..."></textarea>-->
46        <div id="commentarea">Comment area to appear here</div>
47        <input type="hidden" name="d"><xsl:attribute name="value"><xsl:value-of select="/page/pageRequest/paramList/param[@name='d']/@value"/></xsl:attribute></input>
48      </div>
50      <input type="submit" id="usercommentSubmitButton" onclick="addUserComment(document.AddUserCommentForm.username.value, document.AddUserCommentForm.comment.value, document.AddUserCommentForm.d.value, document); return false;"><xsl:attribute name="value"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.submit')"/></xsl:attribute></input>
51      <label id="usercommentfeedback"><xsl:comment>Text to prevent empty tags from becoming self-closing tags</xsl:comment></label>
53      <div id="usercommentlogoutlink">
54        <a><xsl:attribute name="href"><xsl:call-template name="generateLogoutURL"/></xsl:attribute>
55        <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'menu.logout')"/></a>
56      </div>
57    </form>
58      </xsl:when>
60      <!-- User not logged in, "add comment" link allows user to login first -->
61      <xsl:otherwise>
62    <div id="usercommentlink">
63      <a><xsl:attribute name="href"><xsl:call-template name="generateLoginURL"/></xsl:attribute>
64      <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.add')"/></a>
65    </div>
66      </xsl:otherwise>
67    </xsl:choose>
69  </div>
Note: See TracBrowser for help on using the browser.