PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

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

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