PageRenderTime 29ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/enki-core-jsp-hook/src/main/resources/META-INF/jsps/html/taglib/ui/ratings/page.jsp

https://gitlab.com/natyportal/Portal-datos-abiertos
JavaServer Pages | 254 lines | 189 code | 52 blank | 13 comment | 20 complexity | b4e5280e3e64b3e5a87c4208b1887f05 MD5 | raw file
  1. <%--
  2. /**
  3. * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
  4. *
  5. * This library is free software; you can redistribute it and/or modify it under
  6. * the terms of the GNU Lesser General Public License as published by the Free
  7. * Software Foundation; either version 2.1 of the License, or (at your option)
  8. * any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  13. * details.
  14. */
  15. --%>
  16. <%@ include file="/html/taglib/ui/ratings/init.jsp" %>
  17. <%
  18. String randomNamespace = PortalUtil.generateRandomKey(request, "taglib_ui_ratings_page") + StringPool.UNDERLINE;
  19. String className = (String) request.getAttribute("liferay-ui:ratings:className");
  20. long classPK = GetterUtil.getLong((String) request.getAttribute("liferay-ui:ratings:classPK"));
  21. int numberOfStars = GetterUtil.getInteger((String) request.getAttribute("liferay-ui:ratings:numberOfStars"));
  22. RatingsEntry ratingsEntry = (RatingsEntry) request.getAttribute("liferay-ui:ratings:ratingsEntry");
  23. RatingsStats ratingsStats = (RatingsStats) request.getAttribute("liferay-ui:ratings:ratingsStats");
  24. boolean round = GetterUtil.getBoolean((String) request.getAttribute("liferay-ui:ratings:round"), true);
  25. boolean setRatingsEntry = GetterUtil.getBoolean((String) request.getAttribute("liferay-ui:ratings:setRatingsEntry"));
  26. boolean setRatingsStats = GetterUtil.getBoolean((String) request.getAttribute("liferay-ui:ratings:setRatingsStats"));
  27. String type = GetterUtil.getString((String) request.getAttribute("liferay-ui:ratings:type"));
  28. String url = (String) request.getAttribute("liferay-ui:ratings:url");
  29. if (numberOfStars < 1) {
  30. numberOfStars = 1;
  31. }
  32. if (!setRatingsEntry) {
  33. ratingsEntry = RatingsEntryLocalServiceUtil.fetchEntry(themeDisplay.getUserId(), className, classPK);
  34. }
  35. if (!setRatingsStats) {
  36. ratingsStats = RatingsStatsLocalServiceUtil.getStats(className, classPK);
  37. }
  38. if (Validator.isNull(url)) {
  39. url = themeDisplay.getPathMain() + "/portal/rate_entry";
  40. }
  41. double averageScore = 0.0;
  42. if (ratingsStats != null) {
  43. averageScore = ratingsStats.getAverageScore();
  44. }
  45. int averageIndex = (int) Math.round(averageScore * numberOfStars);
  46. if (!round) {
  47. averageIndex = (int) Math.floor(averageScore * numberOfStars);
  48. }
  49. double yourScore = -1.0;
  50. if (ratingsEntry != null) {
  51. yourScore = ratingsEntry.getScore();
  52. }
  53. %>
  54. <c:if test="<%= !themeDisplay.isFacebook() %>">
  55. <div class="taglib-ratings <%= type %>" id="<%= randomNamespace %>ratingContainer">
  56. <c:choose>
  57. <c:when test="<%= type.equals(RatingsType.STARS.getValue()) %>">
  58. <c:if test="<%= themeDisplay.isSignedIn() && !TrashUtil.isInTrash(className, classPK) %>">
  59. <div class="liferay-rating-vote" id="<%= randomNamespace %>ratingStar">
  60. <div id="<%= randomNamespace %>ratingStarContent">
  61. <div class="rating-label"><liferay-ui:message key="your-rating"/></div>
  62. <liferay-util:whitespace-remover>
  63. <%
  64. double yourScoreStars = (yourScore != -1.0) ? yourScore * numberOfStars : 0.0;
  65. for (int i = 1; i <= numberOfStars; i++) {
  66. String ratingId = PortalUtil.generateRandomKey(request, "taglib_ui_ratings_page_rating");
  67. %>
  68. <a class="rating-element <%= (i <= yourScoreStars) ? "icon-star" : "icon-star-empty" %>"
  69. href="javascript:;"></a>
  70. <div class="rating-input-container">
  71. <label for="<%= ratingId %>"><liferay-ui:message
  72. arguments="<%= new Object[] {i, numberOfStars} %>"
  73. key='<%= (yourScoreStars == i) ? (i == 1 ? "you-have-rated-this-x-star-out-of-x" : "you-have-rated-this-x-stars-out-of-x") : (i == 1 ? "rate-this-x-star-out-of-x" : "rate-this-x-stars-out-of-x") %>'
  74. translateArguments="<%= false %>"/></label>
  75. <input checked="<%= i == yourScoreStars %>" class="rating-input"
  76. id="<%= ratingId %>" name="<portlet:namespace />rating" type="radio"
  77. value="<%= i %>">
  78. </div>
  79. <%
  80. }
  81. %>
  82. </liferay-util:whitespace-remover>
  83. </div>
  84. </div>
  85. </c:if>
  86. <div class="liferay-rating-score" id="<%= randomNamespace %>ratingScore">
  87. <div id="<%= randomNamespace %>ratingScoreContent">
  88. <div class="rating-label">
  89. <liferay-ui:message key="average"/>
  90. (<%= ratingsStats.getTotalEntries() %> <liferay-ui:message
  91. key='<%= (ratingsStats.getTotalEntries() == 1) ? "vote" : "votes" %>'/>)
  92. </div>
  93. <liferay-util:whitespace-remover>
  94. <%
  95. for (int i = 1; i <= numberOfStars; i++) {
  96. double averageNumberOfStars = averageScore * numberOfStars;
  97. %>
  98. <span class="rating-element <%= (i <= averageIndex) ? "icon-star" : "icon-star-empty" %>"
  99. title="<%= TrashUtil.isInTrash(className, classPK) ? LanguageUtil.get(resourceBundle, "ratings-are-disabled-because-this-entry-is-in-the-recycle-bin") : ((i == 1) ? LanguageUtil.format(request, ((averageNumberOfStars == 1.0) ? "the-average-rating-is-x-star-out-of-x" : "the-average-rating-is-x-stars-out-of-x"), new Object[] {averageNumberOfStars, numberOfStars}, false) : StringPool.BLANK) %>"></span>
  100. <%
  101. }
  102. %>
  103. </liferay-util:whitespace-remover>
  104. </div>
  105. </div>
  106. </c:when>
  107. <c:when test="<%= type.equals(RatingsType.LIKE.getValue()) || type.equals(RatingsType.THUMBS.getValue()) %>">
  108. <%
  109. String ratingIdPrefix = "ratingThumb";
  110. if (type.equals(RatingsType.LIKE.getValue())) {
  111. ratingIdPrefix = "ratingLike";
  112. }
  113. %>
  114. <div class="liferay-rating-vote thumbrating" id="<%= randomNamespace + ratingIdPrefix %>">
  115. <div class="helper-clearfix rating-content thumbrating-content"
  116. id="<%= randomNamespace + ratingIdPrefix %>Content">
  117. <liferay-util:whitespace-remover>
  118. <%
  119. int positiveVotes = (int) Math.round(ratingsStats.getTotalScore());
  120. int negativeVotes = ratingsStats.getTotalEntries() - positiveVotes;
  121. boolean thumbUp = (yourScore != -1.0) && (yourScore >= 0.5);
  122. boolean thumbDown = (yourScore != -1.0) && (yourScore < 0.5);
  123. %>
  124. <c:choose>
  125. <c:when test="<%= !themeDisplay.isSignedIn() || TrashUtil.isInTrash(className, classPK) %>">
  126. <%
  127. String thumbsTitle = StringPool.BLANK;
  128. if (TrashUtil.isInTrash(className, classPK)) {
  129. thumbsTitle = LanguageUtil.get(resourceBundle, "ratings-are-disabled-because-this-entry-is-in-the-recycle-bin");
  130. }
  131. %>
  132. <span class="glyphicon glyphicon-thumbs-up rating-element rating-thumb-up rating-<%= (thumbUp) ? "on" : "off" %>"
  133. title="<%= thumbsTitle %>"><%= positiveVotes %></span>
  134. <c:if test="<%= type.equals(RatingsType.THUMBS.getValue()) %>">
  135. <span class="glyphicon glyphicon-thumbs-down rating-element rating-thumb-down rating-<%= (thumbDown) ? "on" : "off" %>"
  136. title="<%= thumbsTitle %>"><%= negativeVotes %></span>
  137. </c:if>
  138. </c:when>
  139. <c:otherwise>
  140. <a class="glyphicon glyphicon-thumbs-up rating-element rating-thumb-up rating-<%= (thumbUp) ? "on" : "off" %>"
  141. href="javascript:;"><%= positiveVotes %>
  142. </a>
  143. <c:if test="<%= type.equals(RatingsType.THUMBS.getValue()) %>">
  144. <a class="glyphicon glyphicon-thumbs-down rating-element rating-thumb-down rating-<%= (thumbDown) ? "on" : "off" %>"
  145. href="javascript:;"><%= negativeVotes %>
  146. </a>
  147. </c:if>
  148. <div class="rating-input-container">
  149. <%
  150. String ratingId = PortalUtil.generateRandomKey(request, "taglib_ui_ratings_page_rating");
  151. String positiveRatingMessage = null;
  152. if (type.equals(RatingsType.THUMBS.getValue())) {
  153. positiveRatingMessage = (thumbUp) ? "you-have-rated-this-as-good" : "rate-this-as-good";
  154. } else {
  155. positiveRatingMessage = (thumbUp) ? "unlike-this" : "like-this";
  156. }
  157. %>
  158. <label for="<%= ratingId %>"><liferay-ui:message
  159. key="<%= positiveRatingMessage %>"/></label>
  160. <input class="rating-input" id="<%= ratingId %>"
  161. name="<portlet:namespace /><%= ratingIdPrefix %>" type="radio"
  162. value="up">
  163. <c:if test="<%= type.equals(RatingsType.THUMBS.getValue()) %>">
  164. <%
  165. ratingId = PortalUtil.generateRandomKey(request, "taglib_ui_ratings_page_rating");
  166. %>
  167. <label for="<%= ratingId %>"><liferay-ui:message
  168. key='<%= (thumbDown) ? "you-have-rated-this-as-bad" : "rate-this-as-bad" %>'/></label>
  169. <input class="rating-input" id="<%= ratingId %>"
  170. name="<portlet:namespace /><%= ratingIdPrefix %>" type="radio"
  171. value="down">
  172. </c:if>
  173. </div>
  174. </c:otherwise>
  175. </c:choose>
  176. </liferay-util:whitespace-remover>
  177. </div>
  178. </div>
  179. </c:when>
  180. </c:choose>
  181. </div>
  182. <c:if test="<%= !TrashUtil.isInTrash(className, classPK) %>">
  183. <aui:script use="liferay-ratings">
  184. Liferay.Ratings.register(
  185. {
  186. averageScore: <%= MathUtil.format(averageScore, 1, 1) %>,
  187. className: '<%= HtmlUtil.escapeJS(className) %>',
  188. classPK: '<%= classPK %>',
  189. containerId: '<%= randomNamespace %>ratingContainer',
  190. namespace: '<%= randomNamespace %>',
  191. round: <%= round %>,
  192. size: <%= numberOfStars %>,
  193. totalEntries: <%= ratingsStats.getTotalEntries() %>,
  194. totalScore: <%= ratingsStats.getTotalScore() %>,
  195. type: '<%= type %>',
  196. uri: '<%= url %>',
  197. yourScore: <%= yourScore %>
  198. }
  199. );
  200. </aui:script>
  201. </c:if>
  202. </c:if>