private static final long serialVersionUID = 1L;
@Override
public void onSubmit() {
super.onSubmit();
FeedbackMessage m = getModelObject();
User student;
m.setAuthor(ISISession.get().getUser());
m.setTimestamp(new Date());
if (m.getAuthor().getRole().equals(Role.STUDENT)) {
student = ISISession.get().getUser();
sectionService.adjustMessageCount(student, ((ISIStandardPage) getPage()).getLoc(), Role.STUDENT, 1);
} else {
student = ISISession.get().getStudent();
sectionService.adjustMessageCount(student, ((ISIStandardPage) getPage()).getLoc(), m.getAuthor().getRole(), 1);
}
m.setStudent(student);
m.setPrompt(promptM.getObject());
m.setLocation(((ISIStandardPage) getPage()).getLoc().getLocation());
m.setUnread(true);
m.setVisible(true);
Databinder.getHibernateSession().save(m);
cwmService.flushChanges();
eventService.saveEvent("message:sent", String.valueOf(m.getId()), ((ISIStandardPage) getPage()).getPageName());
}
@Override
public boolean isVisible() {
return !ISISession.get().getUser().hasRole(Role.RESEARCHER); // Researchers cannot send messages
}
};
form.setOutputMarkupPlaceholderTag(true);
TextArea<String> messageField = new TextArea<String>("message");
messageField.setRequired(true);
form.add(messageField);
form.add(new FormComponentLabel("messageLabel", messageField));
final FeedbackPanel feedbackPanel = new ComponentFeedbackPanel("feedbackPanel", form);
feedbackPanel.setOutputMarkupPlaceholderTag(true);
form.add(feedbackPanel);
AjaxSubmitLink sendLink = new AjaxSubmitLink("send") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
messageList.add(0, (FeedbackMessage) form.getModelObject());
form.setDefaultModel(new CompoundPropertyModel<FeedbackMessage>(new FeedbackMessage()));
if (target != null) {
target.addComponent(form);
target.addComponent(responseContainer);
target.addComponent(callingButton);
}
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
form.error("Please type a message.");
if (target != null)
target.addComponent(feedbackPanel);
}
};
form.add(sendLink);
sidebarDialog.getBodyContainer().add(form);
responses = new ListView<FeedbackMessage>("responses", new FeedbackListModel()) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<FeedbackMessage> item) {
final FeedbackMessage m = (FeedbackMessage) item.getModelObject();
item.add(new Label("date", DateFormat.getDateInstance(DateFormat.MEDIUM).format(m.getTimestamp())));
item.add(new Label("time", DateFormat.getTimeInstance(DateFormat.MEDIUM).format(m.getTimestamp())));
item.add(new Label("name", m.getAuthor().getFullName()));
item.add(new Label("message", m.getMessage()));
// Delete Dialog
AjaxDeletePersistedObjectDialog<FeedbackMessage> dialog = new AjaxDeletePersistedObjectDialog<FeedbackMessage>("deleteModal", new Model<FeedbackMessage>(m)) {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unchecked")
@Override
protected void deleteObject(AjaxRequestTarget target) {
FeedbackMessage m = (FeedbackMessage) getDefaultModelObject();
ISIResponseService.get().deleteFeedbackMessage((IModel<FeedbackMessage>) getDefaultModel());
messageList.remove(m);
if (m.isUnread()) {
if (m.getAuthor().getRole().equals(Role.STUDENT)) {
sectionService.adjustMessageCount(m.getStudent(), ((ISIStandardPage) getPage()).getLoc(), Role.STUDENT, -1);
} else {
sectionService.adjustMessageCount(m.getStudent(), ((ISIStandardPage) getPage()).getLoc(), m.getAuthor().getRole(), -1);
}
}
target.addComponent(responseContainer);
target.addComponent(callingButton);
target.addChildren(getPage(), IDisplayFeedbackStatus.class);
}
};
dialog.setObjectName("Feedback Message");
item.add(dialog);
// Delete Link
item.add(new WebMarkupContainer("delete").add(dialog.getClickToOpenBehavior())
.setVisible(ISISession.get().getUser().equals(m.getAuthor())));
if (m.getAuthor().getRole().equals(Role.STUDENT)) {
item.add(new SimpleAttributeModifier("class", "respStudent"));
} else if (m.getAuthor().getRole().equals(Role.TEACHER)){
item.add(new SimpleAttributeModifier("class", "respTeacher"));
}
}
};
responseContainer = new WebMarkupContainer("responseContainer");