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");
}
item.add(AttributeModifier.replace("class", cssClass.toString()));
}
};
PagedEntityListPanel navigator = new PagedEntityListPanel("navigator", dv) {
private static final long serialVersionUID = 5097048616003411362L;
@Override
protected void onEvent(AjaxRequestTarget target) {
emptySelection(target);
target.add(container);
}
};
dataContainer = new DataViewContainer<PrivateMessage>(container, dv, navigator);
dataContainer.setLinks(new OmOrderByBorder<PrivateMessage>("orderById", "id", dataContainer)
, new OmOrderByBorder<PrivateMessage>("orderByFrom", "from.lastname", dataContainer)
, new OmOrderByBorder<PrivateMessage>("orderBySubject", "subject", dataContainer)
, new OmOrderByBorder<PrivateMessage>("orderBySend", "inserted", dataContainer));
add(dataContainer.orderLinks);
add(navigator);
add(unread.setOutputMarkupId(true));
add(buttons.setOutputMarkupId(true));
buttons.add(toInboxBtn.add(new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
getBean(PrivateMessagesDao.class).moveMailsToFolder(selectedMessages, INBOX_FOLDER_ID);
selectFolder(selectedFolder, selectedFolderModel.getObject(), target);
}
}));
buttons.add(deleteBtn.add(new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
if (TRASH_FOLDER_ID == selectedFolderModel.getObject()) {
getBean(PrivateMessagesDao.class).delete(selectedMessages);
} else {
getBean(PrivateMessagesDao.class).moveMailsToFolder(selectedMessages, TRASH_FOLDER_ID);
}
emptySelection(target);
target.add(container);
}
}));
buttons.add(readBtn.add(new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
getBean(PrivateMessagesDao.class).updateReadStatus(selectedMessages, true);
emptySelection(target);
target.add(container, unread);
}
}));
buttons.add(unreadBtn.add(new AjaxEventBehavior("click") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
getBean(PrivateMessagesDao.class).updateReadStatus(selectedMessages, false);
emptySelection(target);
target.add(container);
}
}));
buttons.add(selectDropDown.setOutputMarkupId(true).add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
switch (selectDropDown.getModelObject()) {
case SELECT_CHOOSE:
break;
case SELECT_ALL:
selectedMessages.clear();
selectedMessages.addAll(allMessages);
break;
case SELECT_NONE:
selectedMessages.clear();
break;
case SELECT_UNREAD:
selectedMessages.clear();
selectedMessages.addAll(unreadMessages);
break;
case SELECT_READ:
selectedMessages.clear();
selectedMessages.addAll(readMessages);
break;
}
target.add(container);
}
}));
buttons.add(moveDropDown.setOutputMarkupId(true).add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
long folderId = moveDropDown.getModelObject().getPrivateMessageFolderId();
if (folderId != MOVE_CHOOSE) {
getBean(PrivateMessagesDao.class).moveMailsToFolder(selectedMessages, folderId);
}
selectFolder(selectedFolder, selectedFolderModel.getObject(), target);
}
}));
selectMessage(-1, null);
add(container.add(dv).setOutputMarkupId(true));
//TODO add valid autoupdate add(new AjaxSelfUpdatingTimerBehavior(seconds(15)));
add(selectedMessage.setOutputMarkupId(true));
IDataProvider<UserContact> dp = new IDataProvider<UserContact>() {
private static final long serialVersionUID = 1L;
public void detach() {
}
public Iterator<? extends UserContact> iterator(long first, long count) {
return getBean(UserContactsDao.class).get(getUserId(), (int)first, (int)count).iterator();
}
public long size() {
return getBean(UserContactsDao.class).count(getUserId());
}
public IModel<UserContact> model(UserContact object) {
return Model.of(object);
}
};
final UserInfoDialog d = new UserInfoDialog("infoDialog", newMessage);
final DataView<UserContact> dw = new DataView<UserContact>("users", dp) {
private static final long serialVersionUID = 1L;
private String getName(UserContact uc) {
return uc.getOwner().getFirstname() + " " + uc.getOwner().getLastname(); //FIXME salutation
}
@Override
protected void populateItem(Item<UserContact> item) {
UserContact uc = item.getModelObject();
final long contactId = uc.getUserContactId();
final long userId = uc.getOwner().getUser_id();
if (uc.getPending()) {
item.add(AttributeModifier.append("class", "unread"));
}
item.add(new Label("name", getName(uc)));
item.add(new WebMarkupContainer("accept").add(new AjaxEventBehavior("onclick") {
private static final long serialVersionUID = 7223188816617664993L;
@Override
protected void onEvent(AjaxRequestTarget target) {
ContactsHelper.acceptUserContact(contactId);
updateContacts(target);
}
}).setVisible(uc.getPending()));
item.add(new WebMarkupContainer("decline").add(new AjaxEventBehavior("onclick") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
getBean(UserContactsDao.class).deleteUserContact(contactId);
updateContacts(target);
}
}).setVisible(uc.getPending()));
item.add(new WebMarkupContainer("view").add(new AjaxEventBehavior("onclick") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
d.open(target, userId);
}
}));
item.add(new WebMarkupContainer("message").add(new AjaxEventBehavior("onclick") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
newMessage.reset(true).open(target, userId);
}
}).setVisible(!uc.getPending()));
item.add(new WebMarkupContainer("delete").add(new AjaxEventBehavior("onclick") {
private static final long serialVersionUID = 1L;
@Override
protected void onEvent(AjaxRequestTarget target) {
getBean(UserContactsDao.class).deleteUserContact(contactId);