recipe-comments.xsl 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2. xmlns:eat="http://msqr.us/xsd/ieat"
  3. xmlns:xweb="http://msqr.us/xsd/jaxb-web"
  4. xmlns:date="http://exslt.org/dates-and-times"
  5. exclude-result-prefixes="eat xweb">
  6. <!-- imports -->
  7. <xsl:import href="tmpl/default-layout.xsl"/>
  8. <xsl:import href="tmpl/display-recipe.xsl"/>
  9. <!-- layout variables -->
  10. <xsl:variable name="layout.global.nav.page" select="'vew-recipe'"/>
  11. <!-- helper vars -->
  12. <xsl:variable name="index-section"
  13. select="$aux/eat:ui/eat:search-results/eat:ui-index/eat:index-section[@selected = 'true']"/>
  14. <xsl:variable name="recipe-criteria" select="$aux/eat:ui/eat:search-results/eat:recipe-criteria"/>
  15. <xsl:variable name="recipe" select="$aux/eat:ui/eat:recipe"/>
  16. <xsl:variable name="comments" select="$recipe/eat:comment"/>
  17. <!-- create key of users for easy lookup -->
  18. <xsl:key name="comment-users" match="xweb:x-data/xweb:x-auxillary/eat:ui/eat:search-results/eat:user" use="@userId"/>
  19. <xsl:template match="xweb:x-data" mode="page-title">
  20. <xsl:value-of select="$recipe/eat:name"/>
  21. <xsl:text> (</xsl:text>
  22. <xsl:value-of select="key('i18n','comments')"/>
  23. <xsl:text>)</xsl:text>
  24. </xsl:template>
  25. <xsl:template match="eat:recipe" mode="return-nav">
  26. <a class="back">
  27. <xsl:attribute name="href">
  28. <xsl:value-of select="$web-context"/>
  29. <xsl:text>/recipe.do?recipeId=</xsl:text>
  30. <xsl:value-of select="@recipeId"/>
  31. <xsl:apply-templates select="$index-section" mode="href"/>
  32. <xsl:apply-templates select="$recipe-criteria" mode="href"/>
  33. </xsl:attribute>
  34. <xsl:value-of select="key('i18n','back.to')"/>
  35. <xsl:text> </xsl:text>
  36. <xsl:value-of select="eat:name"/>
  37. </a>
  38. </xsl:template>
  39. <xsl:template match="xweb:x-data" mode="page-head-content">
  40. <script type="text/javascript" src="{$web-context}/js/jquery-1.3.2.js" xml:space="preserve"> </script>
  41. <script type="text/javascript" src="{$web-context}/js/jquery.ajaxQueue.js" xml:space="preserve"> </script>
  42. <script type="text/javascript" src="{$web-context}/js/xweb-locale.js" xml:space="preserve"> </script>
  43. <script type="text/javascript" src="{$web-context}/js/ieat-util.js" xml:space="preserve"> </script>
  44. <script type="text/javascript" xml:space="preserve">
  45. <xsl:comment>
  46. function init() {
  47. installTextAreaFocusHandler();
  48. document.forms[0].elements['comment'].focus();
  49. }
  50. window.onload = init;
  51. //</xsl:comment>
  52. </script>
  53. </xsl:template>
  54. <xsl:template match="xweb:x-data" mode="page-body">
  55. <div class="return-nav">
  56. <xsl:apply-templates select="$recipe" mode="return-nav"/>
  57. </div>
  58. <xsl:if test="$acting-user">
  59. <div class="intro">
  60. <xsl:value-of select="key('i18n','recipe-comments.intro')"/>
  61. </div>
  62. <form method="post" action="{$web-context}{$ctx/xweb:path}">
  63. <table class="form">
  64. <tr>
  65. <th>
  66. <xsl:value-of select="key('i18n','recipe.comment.displayName')"/>
  67. </th>
  68. <td>
  69. <textarea name="comment" class="small">
  70. <xsl:value-of select="$req/eat:param[@key='comment']"/>
  71. <!-- the following space prevents browser rendering mishaps -->
  72. <xsl:text> </xsl:text>
  73. </textarea>
  74. </td>
  75. </tr>
  76. <tr>
  77. <th/>
  78. <td>
  79. <input type="submit" value="{key('i18n','save.displayName')}"/>
  80. </td>
  81. </tr>
  82. </table>
  83. <input type="hidden" name="recipeId" value="{$recipe/@recipeId}"/>
  84. <!-- handle contextual navigation -->
  85. <xsl:apply-templates select="$aux/eat:ui/eat:search-results"
  86. mode="contextual-navigation"/>
  87. </form>
  88. <hr />
  89. </xsl:if>
  90. <xsl:choose>
  91. <xsl:when test="$comments">
  92. <ol>
  93. <xsl:apply-templates select="$comments"/>
  94. </ol>
  95. </xsl:when>
  96. <xsl:otherwise>
  97. <p>
  98. <xsl:value-of select="key('i18n','recipe-comments.none')"/>
  99. </p>
  100. </xsl:otherwise>
  101. </xsl:choose>
  102. </xsl:template>
  103. <xsl:template match="eat:comment">
  104. <li>
  105. <div class="comment-body">
  106. <xsl:value-of select="."/>
  107. </div>
  108. <div>
  109. <xsl:attribute name="class">
  110. <xsl:choose>
  111. <xsl:when test="@userId = $acting-user/@userId">
  112. <xsl:text>comment-credits-self</xsl:text>
  113. </xsl:when>
  114. <xsl:otherwise>
  115. <xsl:text>comment-credits</xsl:text>
  116. </xsl:otherwise>
  117. </xsl:choose>
  118. </xsl:attribute>
  119. <xsl:value-of select="key('comment-users',@userId)/@login"/>
  120. <xsl:text> </xsl:text>
  121. <xsl:value-of select="key('i18n','on')"/>
  122. <xsl:text> </xsl:text>
  123. <xsl:value-of select="date:format-date(string(@createdDate),'d MMM yyyy')"/>
  124. </div>
  125. </li>
  126. </xsl:template>
  127. </xsl:stylesheet>