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

Commit

Permalink
Implement notification for warning and error in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Oct 2, 2013
1 parent 9f1ab29 commit e813bba
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 32 deletions.
Expand Up @@ -86,6 +86,12 @@ public enum ShortcutContext {
* Used by
* {@link org.zanata.webtrans.client.presenter.TargetContentsPresenter}
*/
ValidationWarningPopup
ValidationWarningPopup,

/**
* Used by
* {@link org.zanata.webtrans.client.ui.NotificationDetailsBox}
*/
NotificationDetailsPopup

}
Expand Up @@ -610,10 +610,10 @@ public void onFileUploadComplete(SubmitCompleteEvent event) {
if (event.getResults().contains(String.valueOf(HttpServletResponse.SC_OK))) {
if (event.getResults().contains("Warnings")) {
eventBus.fireEvent(new NotificationEvent(Severity.Warning,
"File uploaded.", event.getResults(), true, null));
"File uploaded with warnings", event.getResults(), true, null));
} else {
eventBus.fireEvent(new NotificationEvent(Severity.Info,
"File uploaded.", event.getResults(), true, null));
"File uploaded", event.getResults(), true, null));
}
queryStats();
} else {
Expand Down
Expand Up @@ -29,18 +29,15 @@ public class NotificationDetailsBox extends ShortcutContextAwareDialogBox {
DialogBoxCloseButton closeButton;

@UiField
HTMLPanel detailMessages;

@UiField
HTMLPanel summary;
HTMLPanel messageWrapper, message, details;

private final WebTransMessages messages;

@Inject
public NotificationDetailsBox(WebTransMessages messages,
KeyShortcutPresenter keyShortcutPresenter) {

super(true, false, ShortcutContext.TransHistoryPopup,
super(true, false, ShortcutContext.NotificationDetailsPopup,
keyShortcutPresenter);

this.messages = messages;
Expand All @@ -54,40 +51,55 @@ public NotificationDetailsBox(WebTransMessages messages,
setWidget(container);
}

public void setMessageDetails(NotificationEvent notificationEvent) {

Severity severity = notificationEvent.getSeverity();
String details = notificationEvent.getDetails();
String severityClass = getSeverityClass(severity);
public void setMessage(NotificationEvent notificationEvent) {
String notificationMessage = notificationEvent.getMessage();
String notificationDetails = notificationEvent.getDetails();

getCaption().setText(
messages.notification()
+ " - "
+ DateUtil.formatShortDate(notificationEvent
+ DateUtil.formatLongDateTime(notificationEvent
.getDate()));
this.summary.setStyleName(severityClass);
this.summary.getElement().setInnerHTML(notificationEvent.getMessage());
messageWrapper.setStyleName(getSeverityClass(notificationEvent
.getSeverity()));

if (notificationEvent.isDisplayAsHtml()) {
SafeHtmlBuilder builder =
new SafeHtmlBuilder()
.appendHtmlConstant(notificationMessage);
message.getElement().setInnerHTML(builder.toSafeHtml().asString());
} else {
message.getElement().setInnerHTML(notificationMessage);
}

detailMessages.setStyleName(severityClass);
if (!Strings.isNullOrEmpty(details)) {
if (notificationEvent.isDisplayAsHtml()) {
if (notificationEvent.isDisplayAsHtml()) {
if (!Strings.isNullOrEmpty(notificationDetails)) {
SafeHtmlBuilder builder =
new SafeHtmlBuilder().appendHtmlConstant(details);
detailMessages.getElement().setInnerHTML(
new SafeHtmlBuilder()
.appendHtmlConstant(notificationDetails);
details.getElement().setInnerHTML(
builder.toSafeHtml().asString());
details.setVisible(true);
} else {
details.setVisible(false);
}
} else {
if (!Strings.isNullOrEmpty(notificationDetails)) {
details.getElement().setInnerHTML(notificationDetails);
details.setVisible(true);
} else {
detailMessages.getElement().setInnerHTML(details);
details.setVisible(false);
}
}
}

private String getSeverityClass(Severity severity) {
if (severity == Severity.Warning) {
return "message--warning";
return "message--warning l__wrapper l--pad-all-half";
} else if (severity == Severity.Error) {
return "message--danger";
return "message--danger l__wrapper l--pad-all-half";
}
return "message--highlight";
return "message--highlight l__wrapper l--pad-all-half";
}

interface NotificationDetailsBoxUiBinder extends
Expand Down
Expand Up @@ -24,10 +24,19 @@
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:z='urn:import:org.zanata.webtrans.client.ui'>

<ui:style>
.container {
min-width: 20em;
max-height: 40em;
overflow: auto;
}
</ui:style>

<g:HTMLPanel styleName="new-zanata">
<g:HTMLPanel ui:field="summary"/>
<g:HTMLPanel styleName="new-zanata {style.container}">
<z:DialogBoxCloseButton ui:field="closeButton" />
<g:HTMLPanel ui:field="detailMessages"/>
<g:HTMLPanel styleName="l__wrapper l--pad-all-half" ui:field="messageWrapper">
<g:HTMLPanel ui:field="message" styleName="l--push-bottom-half" />
<g:HTMLPanel ui:field="details"/>
</g:HTMLPanel>
</g:HTMLPanel>
</ui:UiBinder>
Expand Up @@ -56,7 +56,7 @@ public NotificationItem(final NotificationEvent notificationEvent,
initWidget(uiBinder.createAndBindUi(this));
this.addStyleName(getSeverityClass(notificationEvent.getSeverity()));

message.setText(DateUtil.formatShortDate(notificationEvent
message.setText(DateUtil.formatLongDateTime(notificationEvent
.getDate()) + " " + notificationEvent.getMessage());

InlineLink inlineLink = notificationEvent.getInlineLink();
Expand All @@ -66,7 +66,7 @@ public NotificationItem(final NotificationEvent notificationEvent,
link.setVisible(false);
}

details.setText("Details");
details.setText("More details");
details.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Expand Down
Expand Up @@ -324,7 +324,7 @@ public void showNotification(NotificationEvent notification) {

@Override
public void showNotificationDetail(NotificationEvent notificationEvent) {
notificationDetailsBox.setMessageDetails(notificationEvent);
notificationDetailsBox.setMessage(notificationEvent);

notificationDetailsBox.center();
}
Expand Down
Expand Up @@ -152,7 +152,7 @@ public void appendMessage(final NotificationEvent notificationEvent) {
msgLabel.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
detailBox.setMessageDetails(notificationEvent);
detailBox.setMessage(notificationEvent);
detailBox.center();
}
});
Expand Down

0 comments on commit e813bba

Please sign in to comment.