Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Modify message display to use flashscope bean: https://bugzilla.redha…
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Feb 12, 2014
1 parent bf8f080 commit 4a61869
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 17 deletions.
24 changes: 19 additions & 5 deletions zanata-war/src/main/java/org/zanata/action/CopyTransAction.java
Expand Up @@ -26,6 +26,7 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.security.Restrict;
import org.jboss.seam.international.StatusMessage;
import org.zanata.dao.ProjectIterationDAO;
import org.zanata.model.HCopyTransOptions;
import org.zanata.model.HProject;
Expand Down Expand Up @@ -100,14 +101,27 @@ public boolean isCopyTransRunning() {
}

@Restrict("#{s:hasPermission(copyTransAction.projectIteration, 'copy-trans')}")
public void startCopyTrans() {
public
void startCopyTrans() {
if (isCopyTransRunning()) {
flashScope.setAttribute("message", messages
.get("jsf.iteration.CopyTrans.AlreadyStarted.flash"));
StatusMessage statusMessage =
new StatusMessage(
StatusMessage.Severity.INFO,
null,
null,
messages.get("jsf.iteration.CopyTrans.AlreadyStarted.flash"),
null);
flashScope.setAttribute("message", statusMessage);
return;
} else if (getProjectIteration().getDocuments().size() <= 0) {
flashScope.setAttribute("message",
messages.get("jsf.iteration.CopyTrans.NoDocuments"));
StatusMessage statusMessage =
new StatusMessage(
StatusMessage.Severity.INFO,
null,
null,
messages.get("jsf.iteration.CopyTrans.NoDocuments"),
null);
flashScope.setAttribute("message", statusMessage);
return;
}

Expand Down
52 changes: 45 additions & 7 deletions zanata-war/src/main/java/org/zanata/action/SendEmailAction.java
Expand Up @@ -37,14 +37,17 @@
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.international.LocaleSelector;
import org.jboss.seam.international.StatusMessage;
import org.jboss.seam.security.management.JpaIdentityStore;
import org.zanata.common.LocaleId;
import org.zanata.model.HAccount;
import org.zanata.model.HLocale;
import org.zanata.model.HLocaleMember;
import org.zanata.model.HPerson;
import org.zanata.seam.scope.FlashScopeBean;
import org.zanata.service.EmailService;
import org.zanata.service.LocaleService;
import org.zanata.util.ZanataMessages;

/**
* Sends an email to a specified role.
Expand Down Expand Up @@ -115,6 +118,15 @@ public class SendEmailAction implements Serializable {

private List<HPerson> groupMaintainers;

@In
private FlashScopeBean flashScope;

@In
private ZanataMessages zanataMessages;

public static final String SUCCESS = "success";
public static final String FAILED = "failure";

@Create
public void onCreate() {
if (authenticatedAccount == null) {
Expand Down Expand Up @@ -153,6 +165,7 @@ private List<HPerson> getCoordinators() {
* in pages.xml
*/
public String send() {
clearMessage();
Locale pervLocale = localeSelector.getLocale();
localeSelector.setLocale(new Locale("en"));

Expand All @@ -165,31 +178,35 @@ public String send() {
fromName, fromLoginName, replyEmail,
subject, htmlMessage);
FacesMessages.instance().add(msg);
return "success";
addMessage(StatusMessage.Severity.INFO, msg);
return SUCCESS;
} else if (emailType.equals(EMAIL_TYPE_CONTACT_COORDINATOR)) {
String msg =
emailServiceImpl.sendToLanguageCoordinators(
EmailService.COORDINATOR_EMAIL_TEMPLATE,
getCoordinators(), fromName, fromLoginName,
replyEmail, subject, htmlMessage, language);
FacesMessages.instance().add(msg);
return "success";
addMessage(StatusMessage.Severity.INFO, msg);
return SUCCESS;
} else if (emailType.equals(EMAIL_TYPE_REQUEST_JOIN)) {
String msg =
emailServiceImpl.sendToLanguageCoordinators(
EmailService.REQUEST_TO_JOIN_EMAIL_TEMPLATE,
getCoordinators(), fromName, fromLoginName,
replyEmail, subject, htmlMessage, language);
FacesMessages.instance().add(msg);
return "success";
addMessage(StatusMessage.Severity.INFO, msg);
return SUCCESS;
} else if (emailType.equals(EMAIL_TYPE_REQUEST_ROLE)) {
String msg =
emailServiceImpl.sendToLanguageCoordinators(
EmailService.REQUEST_ROLE_EMAIL_TEMPLATE,
getCoordinators(), fromName, fromLoginName,
replyEmail, subject, htmlMessage, language);
FacesMessages.instance().add(msg);
return "success";
addMessage(StatusMessage.Severity.INFO, msg);
return SUCCESS;
} else if (emailType.equals(EMAIL_TYPE_REQUEST_TO_JOIN_GROUP)) {
String msg =
emailServiceImpl
Expand All @@ -198,8 +215,8 @@ public String send() {
groupMaintainers, fromName,
fromLoginName, replyEmail, subject,
htmlMessage);
FacesMessages.instance().add(msg);
return "success";
addMessage(StatusMessage.Severity.INFO, msg);
return SUCCESS;
} else {
throw new Exception("Invalid email type: " + emailType);
}
Expand All @@ -211,7 +228,7 @@ public String send() {
"Failed to send email: fromName '{}', fromLoginName '{}', replyEmail '{}', subject '{}', message '{}'",
e, fromName, fromLoginName, replyEmail, subject,
htmlMessage);
return "failure";
return FAILED;
} finally {
localeSelector.setLocale(pervLocale);
}
Expand All @@ -221,14 +238,35 @@ public String send() {
* @return string 'canceled'
*/
public void cancel() {
clearMessage();
log.info(
"Canceled sending email: fromName '{}', fromLoginName '{}', replyEmail '{}', subject '{}', message '{}'",
fromName, fromLoginName, replyEmail, subject, htmlMessage);
FacesMessages.instance().add("Sending message canceled");
addMessage(StatusMessage.Severity.INFO, "Sending message canceled");
}

public String sendToVersionGroupMaintainer(List<HPerson> maintainers) {
groupMaintainers = maintainers;
return send();
}

/**
* Use FlashScopeBean to store message in page. Multiple ajax requests for
* re-rendering statistics after updating will clear FacesMessages.
*
* @param severity
* @param message
*/
private void addMessage(StatusMessage.Severity severity, String message) {
StatusMessage statusMessage =
new StatusMessage(severity, null, null, message, null);
statusMessage.interpolate();
flashScope.setAttribute("message", statusMessage);
}

private void clearMessage() {
flashScope.getAndClearAttribute("message");
}

}
2 changes: 1 addition & 1 deletion zanata-war/src/main/resources/messages.properties
Expand Up @@ -926,7 +926,7 @@ jsf.email.rolerequest.UserRequestingRole=Zanata user '#{sendEmail.fromName}' wit
jsf.email.rolerequest.AddUserInstructions=You can assign #{sendEmail.fromName} to requested role in #{sendEmail.locale.localeId.id} team on the language team page.

#------ request-to-join-group email ------
jsf.email.group.maintainer.SentNotification=Your message has been sent to the #{versionGroupJoinAction.groupName} group maintainer
jsf.email.group.maintainer.SentNotification=Your message has been sent to the \'#{versionGroupJoinAction.groupName}\' group maintainer
jsf.email.maintainer.DearMaintainer=Dear Group Maintainer,
jsf.email.joingrouprequest.RequestingToJoinGroup=Zanata user '#{sendEmail.fromName}' with id '#{sendEmail.fromLoginName}' is requesting project version to be added to group '#{versionGroupJoinAction.groupName}'.
jsf.email.UserMessageIntro=#{sendEmail.fromName} has included the following message with their request:
Expand Down
25 changes: 21 additions & 4 deletions zanata-war/src/main/webapp/iteration/view.xhtml
Expand Up @@ -32,10 +32,27 @@
<!-- This is a place holder to avoid using FacesMessages, as they are lost on redirects or Ajax requests
TODO: Use JSF2 Flash Scope-->
</ui:remove>
<a4j:outputPanel rendered="#{flashScope.hasAttribute('message')}">
<ul id="messages" class="message">
<li
class="icon-info-circle-2 infomsg">#{flashScope.getAndClearAttribute('message')}</li>
<a4j:outputPanel rendered="#{flashScope.hasAttribute('message')}" styleClass="new-zanata">
<ul class="list--no-bullets l--push-top-1">
<ui:repeat value="#{flashScope.getAndClearAttribute('message')}"
var="message">
<s:fragment rendered="#{message.severity eq 'INFO'}">
<li class="message--highlight l--push-bottom-half">
#{message.summary}
</li>
</s:fragment>
<s:fragment rendered="#{message.severity eq 'WARN'}">
<li class="message--warning l--push-bottom-half">
#{message.summary}
</li>
</s:fragment>
<s:fragment
rendered="#{message.severity eq 'ERROR' or message.severity eq 'FATAL'}">
<li class="message--danger l--push-bottom-half">
#{message.summary}
</li>
</s:fragment>
</ui:repeat>
</ul>
</a4j:outputPanel>

Expand Down

0 comments on commit 4a61869

Please sign in to comment.