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

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

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