Skip to content

Commit

Permalink
LPS-30963 onSubmit event should be triggered when saving an article
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Basto authored and brianchandotcom committed Dec 10, 2012
1 parent fced144 commit 3647577
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 38 deletions.
Expand Up @@ -776,7 +776,7 @@ if (Validator.isNotNull(content)) {
Liferay.Portlet.Journal.PROXY.pathThemeCss = '<%= HttpUtil.encodeURL(themeDisplay.getPathThemeCss()) %>';
Liferay.Portlet.Journal.PROXY.portletNamespace = '<portlet:namespace />';

new Liferay.Portlet.Journal(Liferay.Portlet.Journal.PROXY.portletNamespace, '<%= (article != null) ? HtmlUtil.escape(articleId) : StringPool.BLANK %>');
window.<portlet:namespace />journalPortlet = new Liferay.Portlet.Journal(Liferay.Portlet.Journal.PROXY.portletNamespace, '<%= (article != null) ? HtmlUtil.escape(articleId) : StringPool.BLANK %>');

var defaultLocaleSelector = A.one('#<portlet:namespace/>defaultLocale');

Expand Down
35 changes: 31 additions & 4 deletions portal-web/docroot/html/portlet/journal/edit_article.jsp
Expand Up @@ -155,7 +155,7 @@ request.setAttribute("edit_article.jsp-toLanguageId", toLanguageId);
<portlet:param name="struts_action" value="/journal/edit_article" />
</portlet:renderURL>

<aui:form action="<%= editArticleActionURL %>" enctype="multipart/form-data" method="post" name="fm1">
<aui:form action="<%= editArticleActionURL %>" enctype="multipart/form-data" method="post" name="fm1" onSubmit='<%= renderResponse.getNamespace() + "submitForm(event);" %>'>
<aui:input name="portletResource" type="hidden" value="<%= portletResource %>" />
<aui:input name="<%= Constants.CMD %>" type="hidden" />
<aui:input name="tabs2" type="hidden" value="<%= tabs2 %>" />
Expand Down Expand Up @@ -266,14 +266,14 @@ request.setAttribute("edit_article.jsp-toLanguageId", toLanguageId);
<c:when test="<%= Validator.isNull(toLanguageId) %>">
<c:if test="<%= hasSavePermission %>">
<c:if test="<%= classNameId == JournalArticleConstants.CLASSNAME_ID_DEFAULT %>">
<aui:button name="saveButton" value="<%= saveButtonLabel %>" />
<aui:button name="saveButton" onClick='<%= renderResponse.getNamespace() + "saveArticle()" %>' type="submit" value="<%= saveButtonLabel %>" />
</c:if>

<aui:button disabled="<%= pending %>" name="publishButton" value="<%= publishButtonLabel %>" />
<aui:button disabled="<%= pending %>" name="publishButton" onClick='<%= renderResponse.getNamespace() + "publishArticle()" %>' type="submit" value="<%= publishButtonLabel %>" />
</c:if>
</c:when>
<c:otherwise>
<aui:button name="translateButton" value="save" />
<aui:button name="translateButton" onClick='<%= renderResponse.getNamespace() + "translateArticle()" %>' type="submit" value="save" />

<%
String[] translations = article.getAvailableLocales();
Expand Down Expand Up @@ -345,6 +345,10 @@ request.setAttribute("edit_article.jsp-toLanguageId", toLanguageId);
submitForm(document.<portlet:namespace />fm1);
}

function <portlet:namespace />publishArticle() {
document.<portlet:namespace />fm1.<portlet:namespace /><%= Constants.CMD %>.value = "<%= Constants.PUBLISH %>";
}

function <portlet:namespace />removeArticleLocale() {
if (confirm("<%= UnicodeLanguageUtil.get(pageContext, "are-you-sure-you-want-to-deactivate-this-language") %>")) {
document.<portlet:namespace />fm1.<portlet:namespace /><%= Constants.CMD %>.value = "<%= Constants.DELETE_TRANSLATION %>";
Expand All @@ -353,6 +357,10 @@ request.setAttribute("edit_article.jsp-toLanguageId", toLanguageId);
}
}

function <portlet:namespace />saveArticle() {
document.<portlet:namespace />fm1.<portlet:namespace /><%= Constants.CMD %>.value = "<%= Constants.SAVE %>";
}

function <portlet:namespace />selectDocumentLibrary(url) {
document.getElementById(<portlet:namespace />documentLibraryInput).value = url;
}
Expand Down Expand Up @@ -387,6 +395,25 @@ request.setAttribute("edit_article.jsp-toLanguageId", toLanguageId);
}
}

function <portlet:namespace />submitForm(event) {
event.preventDefault();

if (window.<portlet:namespace />journalPortlet) {
var cmd = document.<portlet:namespace />fm1.<portlet:namespace /><%= Constants.CMD %>.value;

if (cmd === '<%= Constants.TRANSLATE %>') {
window.<portlet:namespace />journalPortlet.translateArticle();
}
else {
window.<portlet:namespace />journalPortlet.saveArticle(cmd);
}
}
}

function <portlet:namespace />translateArticle() {
document.<portlet:namespace />fm1.<portlet:namespace /><%= Constants.CMD %>.value = "<%= Constants.TRANSLATE %>";
}

<c:if test="<%= windowState.equals(WindowState.MAXIMIZED) %>">
<c:choose>
<c:when test="<%= PropsValues.JOURNAL_ARTICLE_FORCE_AUTOGENERATE_ID %>">
Expand Down
33 changes: 0 additions & 33 deletions portal-web/docroot/html/portlet/journal/js/main.js
Expand Up @@ -2396,39 +2396,6 @@ AUI.add(
}
);
}

if (publishButton) {
publishButton.detach('click');

publishButton.on(
'click',
function() {
instance.saveArticle('publish');
}
);
}

if (saveButton) {
saveButton.detach('click');

saveButton.on(
'click',
function() {
instance.saveArticle();
}
);
}

if (translateButton) {
translateButton.detach('click');

translateButton.on(
'click',
function() {
instance.translateArticle();
}
);
}
},

_createDynamicNode: function(nodeName, attributeMap) {
Expand Down

0 comments on commit 3647577

Please sign in to comment.