source: main/trunk/greenstone3/web/interfaces/default/transform/layouts/usercomments.xsl

Last change on this file was 38316, checked in by anupama, 7 months ago

Incremental change to allow user editing for any accounts who have collection editing powers (not just admin). Future changse would be a full overhaul as they'll happen in the document editor and are unlikely to use the new remove-metadata-array methods.

File size: 6.1 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet version="1.0"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:java="http://xml.apache.org/xslt/java"
5 xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
6 xmlns:gslib="http://www.greenstone.org/skinning"
7 xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat"
8 extension-element-prefixes="java util"
9 exclude-result-prefixes="java util gsf">
10
11<xsl:template name="userCommentsDefineMetanames">
12 <gsf:script>
13 <!-- Older Greenstone3 installations did not use metadata namespace/prefix for usercomment metadata
14
15 From GS3.11 onwards, this is now part of the Greenstone metadata set (gs.), allowing usercomments
16 to be edited and managed from GLI.
17
18 If you want the older way of doing things, replace the JS syntax below the commented out block
19 -->
20
21 <!--
22 gs.usercomments.defaults.metaname_username = "username";
23 gs.usercomments.defaults.metaname_usertimestamp = "usertimestamp";
24 gs.usercomments.defaults.metaname_usercomment = "usercomment";
25 -->
26
27 gs.usercomments.defaults.metaname_username = "gs.username";
28 gs.usercomments.defaults.metaname_usertimestamp = "gs.usertimestamp";
29 gs.usercomments.defaults.metaname_usercomment = "gs.usercomment";
30 </gsf:script>
31</xsl:template>
32
33<xsl:template name="userCommentsSection">
34 <xsl:if test="/page/pageResponse/format[@type='display']/gsf:option[@name='allowUserComments']/@value='true'">
35 <!-- 1. Make some variables available to javascript that the usercomments related js functions need -->
36 <gsf:variable name="d"><xsl:value-of select="/page/pageRequest/paramList/param[@name='d']/@value"/></gsf:variable>
37 <gsf:variable name="c"><xsl:value-of select="/page/pageRequest/paramList/param[@name='c']/@value"/></gsf:variable>
38 <gsf:variable name="site"><xsl:value-of select="/page/pageResponse/interfaceOptions/option[@name='site_name']/@value"/></gsf:variable>
39
40 <gsf:variable name="textusercommentssection"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.heading')"/></gsf:variable>
41 <gsf:variable name="textisempty"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.isempty')"/></gsf:variable>
42 <gsf:variable name="textcommentsubmitted"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.submitted')"/></gsf:variable>
43
44
45 <gsf:variable name="userCanDeleteComments">
46 <xsl:choose>
47 <!--<xsl:when test="/page/pageRequest/userInformation and (util:csvContains(/page/pageRequest/userInformation/@groups, 'administrator'))">1</xsl:when><xsl:otherwise>0</xsl:otherwise>-->
48 <xsl:when test="$canDoEditing = 'true'">1</xsl:when><xsl:otherwise>0</xsl:otherwise>
49 </xsl:choose>
50 </gsf:variable>
51 <gsf:variable name="docID"><xsl:value-of select="/page/pageRequest/paramList/param[@name='d']/@value"/></gsf:variable>
52
53 <!-- 2. Load the javascript, which will do stuff on window load/ready for which it needs the above gs.variables -->
54 <script type="text/javascript" src="interfaces/{$interface_name}/js/gsajaxapi.js"><xsl:text> </xsl:text></script>
55 <script type="text/javascript" src="interfaces/{$interface_name}/js/user_comments.js"><xsl:text> </xsl:text></script>
56 <xsl:call-template name="userCommentsDefineMetanames"/>
57
58 <!-- 3. Set up the User comments section in the HTML -->
59 <div id="commentssection" class="centrediv">
60 <div id="usercomments">
61 <!-- A heading for the comment section will be added here dynamically either if
62 previously submitted comments exist, or if the form#usercommentform to add
63 a new comment is displayed. Otherwise only the "Add Comments" link is shown. -->
64 <xsl:comment>Existing comments will be dynamically loaded into this div#usercomments</xsl:comment>
65 </div>
66
67 <!-- If the user's logged in, show the comment form, else show the link to the login page -->
68 <xsl:choose>
69 <xsl:when test="/page/pageRequest/userInformation">
70 <!-- Logged in, allow user to add a comment by displaying a form -->
71 <form name="AddUserCommentForm" id="usercommentform">
72 <input type="hidden" name="username"><xsl:attribute name="value"><xsl:value-of select="/page/pageRequest/userInformation/@username"/></xsl:attribute></input>
73 <div>
74 <p><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.add')"/></p>
75 <!-- 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. It will look like: -->
76 <!--<textarea required="required" name="comment" rows="10" cols="64" placeholder="Add your comment here..."></textarea>-->
77 <div id="commentarea">Comment area to appear here</div>
78 <input type="hidden" name="d"><xsl:attribute name="value"><xsl:value-of select="/page/pageRequest/paramList/param[@name='d']/@value"/></xsl:attribute></input>
79 </div>
80
81 <input type="submit" id="usercommentSubmitButton" onclick="gs.usercomments.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>
82 <label id="usercommentfeedback"><xsl:comment>Text to prevent empty tags from becoming self-closing tags</xsl:comment></label>
83
84 <div id="usercommentlogoutlink">
85 <a><xsl:attribute name="href"><xsl:call-template name="generateLogoutURL"/></xsl:attribute>
86 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'menu.logout')"/></a>
87 </div>
88 </form>
89 </xsl:when>
90
91 <!-- User not logged in, "add comment" link allows user to login first -->
92 <xsl:otherwise>
93 <div id="usercommentlink">
94 <a><xsl:attribute name="href"><xsl:call-template name="generateLoginURL"/></xsl:attribute>
95 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.add')"/></a>
96 </div>
97 </xsl:otherwise>
98 </xsl:choose>
99
100 </div>
101 </xsl:if>
102</xsl:template>
103
104</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.