@SuppressWarnings("unchecked")
public MessagesContactsPanel(String id) {
super(id);
foldersModel = Model.ofList(getBean(PrivateMessageFolderDao.class).get(0, Integer.MAX_VALUE));
updateMoveModel();
add(newMessage = new MessageDialog("newMessage", new CompoundPropertyModel<PrivateMessage>(new PrivateMessage())) {
private static final long serialVersionUID = 1L;
@Override
public void onClose(AjaxRequestTarget target, DialogButton button) {
if (send.equals(button)) {
target.add(container);
}
}
});
final AddFolderDialog addFolder = new AddFolderDialog("addFolder") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target) {
super.onSubmit(target);
PrivateMessageFolderDao fDao = getBean(PrivateMessageFolderDao.class);
fDao.addPrivateMessageFolder(getModelObject(), getUserId());
foldersModel.setObject(fDao.get(0, Integer.MAX_VALUE));
updateMoveModel();
target.add(folders, moveDropDown);
}
};
add(addFolder);
add(new WebMarkupContainer("new").add(new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
newMessage.reset(false).open(target);
}
}).add(new JQueryBehavior(".email.new", "button")));
folders.add(inbox.add(new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
selectFolder(inbox, INBOX_FOLDER_ID, target);
}
}));
folders.add(sent.add(new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
selectFolder(sent, SENT_FOLDER_ID, target);
}
}));
folders.add(trash.add(new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
selectFolder(trash, TRASH_FOLDER_ID, target);
}
}));
folders.add(new WebMarkupContainer("newdir").add(new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
addFolder.open(target);
}
}).add(new JQueryBehavior(".email.newdir", "button")));
add(folders.add(new ListView<PrivateMessageFolder>("folder", foldersModel) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(final ListItem<PrivateMessageFolder> item) {
item.add(new Label("name", item.getModelObject().getFolderName()));
item.add(new WebMarkupContainer("delete").add(new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
PrivateMessageFolderDao fDao = getBean(PrivateMessageFolderDao.class);
fDao.delete(item.getModelObject(), getUserId());
foldersModel.setObject(fDao.get(0, Integer.MAX_VALUE));
target.add(folders);
}
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.getAjaxCallListeners().add(new ConfirmAjaxCallListener(WebSession.getString(713)));
}
}));
item.add(new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
selectFolder(item, item.getModelObject().getPrivateMessageFolderId(), target);
}
});
setFolderClass(item);
}
}).setOutputMarkupId(true));
SearchableDataProvider<PrivateMessage> sdp = new SearchableDataProvider<PrivateMessage>(PrivateMessagesDao.class) {
private static final long serialVersionUID = 1L;
@Override
protected PrivateMessagesDao getDao() {
return (PrivateMessagesDao)super.getDao();
}
@Override
public Iterator<? extends PrivateMessage> iterator(long first, long count) {
allMessages.clear();
readMessages.clear();
unreadMessages.clear();
String sort = getSort() == null ? "" : "m." + getSort().getProperty();
boolean isAsc = getSort() == null ? true : getSort().isAscending();
return getDao().get(getUserId(), selectedFolderModel.getObject(), search, sort, isAsc, (int)first, (int)count).iterator();
}
@Override
public long size() {
return getDao().count(getUserId(), selectedFolderModel.getObject(), search);
}
};
final SearchableDataView<PrivateMessage> dv = new SearchableDataView<PrivateMessage>("messages", sdp) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(Item<PrivateMessage> item) {
PrivateMessage m = item.getModelObject();
final long id = m.getId();
allMessages.add(id);
if (m.getIsRead()) {
readMessages.add(id);
} else {
unreadMessages.add(id);
}
item.add(new Label("id", id));
item.add(new Label("from", getDisplayName(m.getFrom())));
item.add(new Label("subject", m.getSubject()));
item.add(new Label("send", getDateFormat().format(m.getInserted())));
item.add(new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
long selected = id;
if (selectedMessages.contains(id)) {
selectedMessages.remove(id);
selected = selectedMessages.isEmpty() ? -1 : selectedMessages.iterator().next();
} else {
selectedMessages.add(id);
}
selectMessage(selected, target);
target.add(container);
}
});
StringBuilder cssClass = new StringBuilder(Boolean.FALSE.equals(m.getIsRead()) ? "unread" : "");
if (selectedMessages.contains(id)) {
if (cssClass.length() > 0) {
cssClass.append(" ");
}
cssClass.append("selected");