PageRenderTime 24ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/portal-web/docroot/html/portlet/journal/edit_template.jsp

https://github.com/oterral/liferay-portal
JavaServer Pages | 329 lines | 238 code | 78 blank | 13 comment | 11 complexity | d35d5fcdc12dfdf690839b664b51fde3 MD5 | raw file
  1. <%--
  2. /**
  3. * Copyright (c) 2000-2011 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/portlet/journal/init.jsp" %>
  17. <%
  18. String redirect = ParamUtil.getString(request, "redirect");
  19. String originalRedirect = ParamUtil.getString(request, "originalRedirect", StringPool.BLANK);
  20. if (originalRedirect.equals(StringPool.BLANK)) {
  21. originalRedirect = redirect;
  22. }
  23. else {
  24. redirect = originalRedirect;
  25. }
  26. JournalTemplate template = (JournalTemplate)request.getAttribute(WebKeys.JOURNAL_TEMPLATE);
  27. long groupId = BeanParamUtil.getLong(template, request, "groupId", scopeGroupId);
  28. Group group = GroupLocalServiceUtil.getGroup(groupId);
  29. String templateId = BeanParamUtil.getString(template, request, "templateId");
  30. String newTemplateId = ParamUtil.getString(request, "newTemplateId");
  31. String structureId = BeanParamUtil.getString(template, request, "structureId");
  32. String structureName = StringPool.BLANK;
  33. if (Validator.isNotNull(structureId)) {
  34. try {
  35. JournalStructure structure = JournalStructureLocalServiceUtil.getStructure(groupId, structureId);
  36. structureName = structure.getName(locale);
  37. }
  38. catch (NoSuchStructureException nsse) {
  39. }
  40. }
  41. String xslContent = request.getParameter("xslContent");
  42. String xsl = xslContent;
  43. if (xslContent != null) {
  44. xsl = JS.decodeURIComponent(xsl);
  45. }
  46. else {
  47. xsl = BeanParamUtil.getString(template, request, "xsl");
  48. }
  49. String langType = BeanParamUtil.getString(template, request, "langType", JournalTemplateConstants.LANG_TYPE_VM);
  50. boolean cacheable = BeanParamUtil.getBoolean(template, request, "cacheable");
  51. if (template == null) {
  52. cacheable = true;
  53. }
  54. %>
  55. <aui:form method="post" name="fm2">
  56. <input name="xslContent" type="hidden" value="" />
  57. <input name="formatXsl" type="hidden" value="" />
  58. <input name="langType" type="hidden" value="" />
  59. </aui:form>
  60. <portlet:actionURL var="editTemplateURL">
  61. <portlet:param name="struts_action" value="/journal/edit_template" />
  62. </portlet:actionURL>
  63. <aui:form action="<%= editTemplateURL %>" enctype="multipart/form-data" method="post" name="fm1" onSubmit='<%= "event.preventDefault(); " + renderResponse.getNamespace() + "saveTemplate();" %>'>
  64. <aui:input name="<%= Constants.CMD %>" type="hidden" />
  65. <aui:input name="redirect" type="hidden" value="<%= redirect %>" />
  66. <aui:input name="originalRedirect" type="hidden" value="<%= originalRedirect %>" />
  67. <aui:input name="groupId" type="hidden" value="<%= groupId %>" />
  68. <aui:input name="templateId" type="hidden" value="<%= templateId %>" />
  69. <aui:input name="xslContent" type="hidden" value="<%= JS.encodeURIComponent(xsl) %>" />
  70. <aui:input name="saveAndContinue" type="hidden" />
  71. <liferay-ui:header
  72. backURL="<%= redirect %>"
  73. localizeTitle="<%= (template == null) %>"
  74. title='<%= (template == null) ? "new-template" : template.getName(locale) %>'
  75. />
  76. <liferay-ui:error exception="<%= DuplicateTemplateIdException.class %>" message="please-enter-a-unique-id" />
  77. <liferay-ui:error exception="<%= TemplateIdException.class %>" message="please-enter-a-valid-id" />
  78. <liferay-ui:error exception="<%= TemplateNameException.class %>" message="please-enter-a-valid-name" />
  79. <liferay-ui:error exception="<%= TemplateSmallImageNameException.class %>">
  80. <%
  81. String[] imageExtensions = PrefsPropsUtil.getStringArray(PropsKeys.JOURNAL_IMAGE_EXTENSIONS, ",");
  82. %>
  83. <liferay-ui:message key="image-names-must-end-with-one-of-the-following-extensions" /> <%= StringUtil.merge(imageExtensions, StringPool.COMMA) %>.
  84. </liferay-ui:error>
  85. <liferay-ui:error exception="<%= TemplateSmallImageSizeException.class %>">
  86. <%
  87. long imageMaxSize = PrefsPropsUtil.getLong(PropsKeys.JOURNAL_IMAGE_SMALL_MAX_SIZE) / 1024;
  88. %>
  89. <liferay-ui:message arguments="<%= imageMaxSize %>" key="please-enter-a-small-image-with-a-valid-file-size-no-larger-than-x" />
  90. </liferay-ui:error>
  91. <liferay-ui:error exception="<%= TemplateXslException.class %>" message="please-enter-a-valid-script-template" />
  92. <aui:model-context bean="<%= template %>" model="<%= JournalTemplate.class %>" />
  93. <aui:fieldset>
  94. <c:choose>
  95. <c:when test="<%= template == null %>">
  96. <c:choose>
  97. <c:when test="<%= PropsValues.JOURNAL_TEMPLATE_FORCE_AUTOGENERATE_ID %>">
  98. <aui:input name="newTemplateId" type="hidden" />
  99. <aui:input name="autoTemplateId" type="hidden" value="<%= true %>" />
  100. </c:when>
  101. <c:otherwise>
  102. <aui:input cssClass="lfr-input-text-container" label="id" name="newTemplateId" field="templateId" fieldParam="newTemplateId" value="<%= newTemplateId %>" />
  103. <aui:input label="autogenerate-id" name="autoTemplateId" type="checkbox" />
  104. </c:otherwise>
  105. </c:choose>
  106. </c:when>
  107. <c:otherwise>
  108. <aui:field-wrapper label="id">
  109. <%= templateId %>
  110. </aui:field-wrapper>
  111. </c:otherwise>
  112. </c:choose>
  113. <aui:input cssClass="lfr-input-text-container" name="name" />
  114. <aui:input cssClass="lfr-textarea-container" name="description" />
  115. <aui:input helpMessage="journal-template-cacheable-help" inlineLabel="right" name="cacheable" value="<%= new Boolean(cacheable) %>" />
  116. <c:if test="<%= template != null %>">
  117. <aui:field-wrapper label="url">
  118. <liferay-ui:input-resource url='<%= themeDisplay.getPortalURL() + themeDisplay.getPathMain() + "/journal/get_template?groupId=" + groupId + "&templateId=" + templateId %>' />
  119. </aui:field-wrapper>
  120. <c:if test="<%= portletDisplay.isWebDAVEnabled() %>">
  121. <aui:field-wrapper label="webdav-url">
  122. <liferay-ui:input-resource url='<%= themeDisplay.getPortalURL() + "/tunnel-web/secure/webdav" + group.getFriendlyURL() + "/journal/Templates/" + templateId %>' />
  123. </aui:field-wrapper>
  124. </c:if>
  125. </c:if>
  126. <aui:field-wrapper label="structure">
  127. <aui:input name="structureId" type="hidden" value="<%= structureId %>" />
  128. <c:choose>
  129. <c:when test="<%= (template == null) || (Validator.isNotNull(structureId)) %>">
  130. <portlet:renderURL var="editStructureURL">
  131. <portlet:param name="struts_action" value="/journal/edit_structure" />
  132. <portlet:param name="redirect" value="<%= currentURL %>" />
  133. <portlet:param name="groupId" value="<%= String.valueOf(groupId) %>" />
  134. <portlet:param name="structureId" value="<%= structureId %>" />
  135. </portlet:renderURL>
  136. <aui:a href="<%= editStructureURL %>" label="<%= structureName %>" id="structureName" />
  137. </c:when>
  138. <c:otherwise>
  139. <aui:a href="" id="structureName" />
  140. </c:otherwise>
  141. </c:choose>
  142. <c:if test="<%= (template == null) || (Validator.isNull(template.getStructureId())) %>">
  143. <aui:button onClick='<%= renderResponse.getNamespace() + "openStructureSelector();" %>' value="select" />
  144. <aui:button disabled="<%= Validator.isNull(structureId) %>" name="removeStructureButton" onClick='<%= renderResponse.getNamespace() + "removeStructure();" %>' value="remove" />
  145. </c:if>
  146. </aui:field-wrapper>
  147. <aui:select label="language-type" name="langType">
  148. <%
  149. for (int i = 0; i < JournalTemplateConstants.LANG_TYPES.length; i++) {
  150. %>
  151. <aui:option label="<%= JournalTemplateConstants.LANG_TYPES[i].toUpperCase() %>" selected="<%= langType.equals(JournalTemplateConstants.LANG_TYPES[i]) %>" value="<%= JournalTemplateConstants.LANG_TYPES[i] %>" />
  152. <%
  153. }
  154. %>
  155. </aui:select>
  156. <aui:field-wrapper label="script">
  157. <aui:input label="" name="xsl" type="file" />
  158. <aui:button name="editorButton" value="launch-editor" />
  159. <c:if test="<%= template != null %>">
  160. <aui:button onClick='<%= renderResponse.getNamespace() + "downloadTemplateContent();" %>' value="download" />
  161. </c:if>
  162. </aui:field-wrapper>
  163. <aui:input inlineLabel="right" label="format-script" name="formatXsl" type="checkbox" />
  164. <aui:input cssClass="lfr-input-text-container" label="small-image-url" name="smallImageURL" />
  165. <span style="font-size: xx-small;">-- <%= LanguageUtil.get(pageContext, "or").toUpperCase() %> --</span>
  166. <aui:input cssClass="lfr-input-text-container" label="small-image" name="smallFile" type="file" />
  167. <aui:input inlineLabel="right" name="smallImage" />
  168. <c:if test="<%= template == null %>">
  169. <aui:field-wrapper label="permissions">
  170. <liferay-ui:input-permissions
  171. modelName="<%= JournalTemplate.class.getName() %>"
  172. />
  173. </aui:field-wrapper>
  174. </c:if>
  175. </aui:fieldset>
  176. <aui:button-row>
  177. <aui:button type="submit" />
  178. <aui:button onClick='<%= renderResponse.getNamespace() + "saveAndContinueTemplate();" %>' value="save-and-continue" />
  179. <aui:button href="<%= redirect %>" type="cancel" />
  180. </aui:button-row>
  181. </aui:form>
  182. <aui:script>
  183. function <portlet:namespace />downloadTemplateContent() {
  184. document.<portlet:namespace />fm2.action = "<%= themeDisplay.getPathMain() %>/journal/get_template_content";
  185. document.<portlet:namespace />fm2.target = "_self";
  186. document.<portlet:namespace />fm2.xslContent.value = document.<portlet:namespace />fm1.<portlet:namespace />xslContent.value;
  187. document.<portlet:namespace />fm2.formatXsl.value = document.<portlet:namespace />fm1.<portlet:namespace />formatXsl.value;
  188. document.<portlet:namespace />fm2.langType.value = document.<portlet:namespace />fm1.<portlet:namespace />langType.value;
  189. document.<portlet:namespace />fm2.submit();
  190. }
  191. function <portlet:namespace />openStructureSelector() {
  192. Liferay.Util.openWindow(
  193. {
  194. dialog: {
  195. stack: false,
  196. width: 680
  197. },
  198. title: '<liferay-ui:message key="structure" />',
  199. uri: '<portlet:renderURL windowState="<%= LiferayWindowState.POP_UP.toString() %>"><portlet:param name="struts_action" value="/journal/select_structure" /><portlet:param name="groupId" value="<%= String.valueOf(groupId) %>" /></portlet:renderURL>'
  200. }
  201. );
  202. }
  203. function <portlet:namespace />removeStructure() {
  204. document.<portlet:namespace />fm1.<portlet:namespace />structureId.value = "";
  205. var nameEl = document.getElementById("<portlet:namespace />structureName");
  206. nameEl.href = "#";
  207. nameEl.innerHTML = "";
  208. document.getElementById("<portlet:namespace />removeStructureButton").disabled = true;
  209. }
  210. function <portlet:namespace />saveAndContinueTemplate() {
  211. document.<portlet:namespace />fm1.<portlet:namespace />saveAndContinue.value = "1";
  212. <portlet:namespace />saveTemplate();
  213. }
  214. function <portlet:namespace />saveTemplate() {
  215. document.<portlet:namespace />fm1.<portlet:namespace /><%= Constants.CMD %>.value = "<%= (template == null) ? Constants.ADD : Constants.UPDATE %>";
  216. <c:if test="<%= template == null %>">
  217. document.<portlet:namespace />fm1.<portlet:namespace />templateId.value = document.<portlet:namespace />fm1.<portlet:namespace />newTemplateId.value;
  218. </c:if>
  219. submitForm(document.<portlet:namespace />fm1);
  220. }
  221. function <portlet:namespace />selectStructure(structureId, structureName, dialog) {
  222. document.<portlet:namespace />fm1.<portlet:namespace />structureId.value = structureId;
  223. var nameEl = document.getElementById("<portlet:namespace />structureName");
  224. nameEl.href = "<portlet:renderURL><portlet:param name="struts_action" value="/journal/edit_structure" /><portlet:param name="redirect" value="<%= currentURL %>" /><portlet:param name="groupId" value="<%= String.valueOf(groupId) %>" /></portlet:renderURL>&<portlet:namespace />structureId=" + structureId;
  225. nameEl.innerHTML = structureName + "&nbsp;";
  226. document.getElementById("<portlet:namespace />removeStructureButton").disabled = false;
  227. if (dialog) {
  228. dialog.close();
  229. }
  230. }
  231. Liferay.Util.disableToggleBoxes('<portlet:namespace />autoTemplateIdCheckbox','<portlet:namespace />newTemplateId', true);
  232. Liferay.Util.inlineEditor(
  233. {
  234. button: '#<portlet:namespace />editorButton',
  235. id: '<portlet:namespace />xslContent',
  236. textarea: '<portlet:namespace />xslContent',
  237. title: '<liferay-ui:message key="editor" />',
  238. uri: '<portlet:renderURL windowState="<%= LiferayWindowState.POP_UP.toString() %>"><portlet:param name="struts_action" value="/journal/edit_template_xsl" /></portlet:renderURL>&<portlet:namespace />langType=' + document.<portlet:namespace />fm1.<portlet:namespace />langType.value
  239. }
  240. );
  241. <c:if test="<%= windowState.equals(WindowState.MAXIMIZED) %>">
  242. <c:choose>
  243. <c:when test="<%= PropsValues.JOURNAL_TEMPLATE_FORCE_AUTOGENERATE_ID %>">
  244. Liferay.Util.focusFormField(document.<portlet:namespace />fm1.<portlet:namespace />name);
  245. </c:when>
  246. <c:otherwise>
  247. Liferay.Util.focusFormField(document.<portlet:namespace />fm1.<portlet:namespace /><%= (template == null) ? "newTemplateId" : "name" %>);
  248. </c:otherwise>
  249. </c:choose>
  250. </c:if>
  251. </aui:script>