diff --git a/src/main/java/se/su/dsv/scipro/commentthread/panels/CommentThreadPanel.html b/src/main/java/se/su/dsv/scipro/commentthread/panels/CommentThreadPanel.html index 8053f15ad1..30bf3c38dd 100644 --- a/src/main/java/se/su/dsv/scipro/commentthread/panels/CommentThreadPanel.html +++ b/src/main/java/se/su/dsv/scipro/commentthread/panels/CommentThreadPanel.html @@ -33,6 +33,7 @@ <div wicket:id="navigator" class="comment-pager last"></div> </div> <div class="last comment-form"> + <div wicket:id="feedbackPanel"></div> <form wicket:id="commentForm"> <div class="last"> <strong>Comment:</strong> diff --git a/src/main/java/se/su/dsv/scipro/commentthread/panels/CommentThreadPanel.java b/src/main/java/se/su/dsv/scipro/commentthread/panels/CommentThreadPanel.java index 49bc7d262f..a1ecdc08fc 100644 --- a/src/main/java/se/su/dsv/scipro/commentthread/panels/CommentThreadPanel.java +++ b/src/main/java/se/su/dsv/scipro/commentthread/panels/CommentThreadPanel.java @@ -19,6 +19,7 @@ import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.TextArea; import org.apache.wicket.markup.html.list.ListItem; import org.apache.wicket.markup.html.list.PageableListView; +import org.apache.wicket.markup.html.panel.FeedbackPanel; import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; @@ -70,6 +71,7 @@ public class CommentThreadPanel extends Panel { private final Set<SubscriberModel> subscriberModels; private final String title; private final Long classId; + private final FeedbackPanel feedbackPanel; public CommentThreadPanel(final String id, final Commentable keyObject, final int numberOfComments, final Set<SubscriberModel> subscriberModels, @@ -111,6 +113,10 @@ public class CommentThreadPanel extends Panel { dialog.setWidth(470); dialog.add(dialogContainer); add(dialog); + feedbackPanel = new FeedbackPanel("feedbackPanel"); + feedbackPanel.setOutputMarkupId(true); + add(feedbackPanel); + dialogContainer.setOutputMarkupId(true); editCommentForm = new EditCommentForm("editCommentForm", @@ -176,30 +182,35 @@ public class CommentThreadPanel extends Panel { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { - Comment comment = (Comment) form.getDefaultModelObject(); - comment = commentDao.save(comment); - System.out.println(subscriberModels); - if (subscriberModels != null) { - for (SubscriberModel sm : subscriberModels) { - createNotification(sm.getUser(), comment.getComment(), - sm.getNotificationPriority(), sm.getAbsolutePath()); + if (comment.getComment() == null || comment.getComment().length() < 1) { + error("Comment can't be empty"); + + } else { + comment = commentDao.save(comment); + if (subscriberModels != null) { + for (SubscriberModel sm : subscriberModels) { + notificationController.createNotificationForComment(sm.getUser(), comment.getComment(), + sm.getNotificationPriority(), title, classId.toString(), sm.getAbsolutePath()); + } } - } - /* - * Do not, on purpose set the forms defaultModelObject to - * the now persisted object, we leave the original object so - * it can be re reused for any number of submits * - */ + /* + * Do not, on purpose set the forms defaultModelObject + * to the now persisted object, we leave the original + * object so it can be re reused for any number of + * submits * + */ - webMarkupContainer.remove(commentListView); - webMarkupContainer.remove(customPagingNavigator); - textArea.setDefaultModelObject(""); - generateCommentListView(); - webMarkupContainer.add(commentListView); - webMarkupContainer.add(customPagingNavigator); - target.addComponent(textArea); - target.addComponent(webMarkupContainer); + webMarkupContainer.remove(commentListView); + webMarkupContainer.remove(customPagingNavigator); + textArea.setDefaultModelObject(""); + generateCommentListView(); + webMarkupContainer.add(commentListView); + webMarkupContainer.add(customPagingNavigator); + target.addComponent(textArea); + target.addComponent(webMarkupContainer); + } + target.addComponent(feedbackPanel); } }; @@ -338,29 +349,4 @@ public class CommentThreadPanel extends Panel { } } - private void createNotification(final User user, final String message, - final NotificationPriority notificationPriority, final String absolutePath) { - - Properties props = null; - try { - props = PropsUtils.load("notification.properties"); - } catch (Exception e) { - e.printStackTrace(); - } - String mailSubject = props.getProperty("mailSubject"); - String conferenceNotification = props.getProperty("conferenceNotificationComment"); - String twoNewLines = props.getProperty("twoNewLines"); - - String webNotificationMessage = SciProSession.get().getUser() + conferenceNotification - + title; - - String mailMessage = webNotificationMessage + twoNewLines + message; - - NotificationMessage notificationMessage = new NotificationMessage(webNotificationMessage, - mailSubject, mailMessage); - notificationController.processNotification(user, notificationMessage, absolutePath+"&"+classId - , - notificationPriority); - } - }