Search in sources :

Example 16 with TableMultiSelectEvent

use of org.olat.core.gui.components.table.TableMultiSelectEvent in project openolat by klemens.

the class UserSearchController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == tableCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            if (te.getActionId().equals(ACTION_SINGLESELECT_CHOOSE)) {
                int rowid = te.getRowId();
                Identity foundIdentity = tdm.getObject(rowid);
                foundIdentities.add(foundIdentity);
                // Tell parentController that a subject has been found
                fireEvent(ureq, new SingleIdentityChosenEvent(foundIdentity));
            }
        } else if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
            TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
            if (tmse.getAction().equals(ACTION_MULTISELECT_CHOOSE)) {
                foundIdentities = tdm.getObjects(tmse.getSelection());
                fireEvent(ureq, new MultiIdentityChosenEvent(foundIdentities));
            }
        }
    } else if (source == autocompleterC) {
        if (event instanceof EntriesChosenEvent) {
            EntriesChosenEvent ece = (EntriesChosenEvent) event;
            List<String> res = ece.getEntries();
            // if we get the event, we have a result or an incorrect selection see OLAT-5114 -> check for empty
            String mySel = res.isEmpty() ? null : (String) res.get(0);
            if ((mySel == null) || mySel.trim().equals("")) {
                getWindowControl().setWarning(translate("error.search.form.notempty"));
                return;
            }
            // default not found
            Long key = -1l;
            try {
                key = Long.valueOf(mySel);
                if (key > 0) {
                    Identity chosenIdent = BaseSecurityManager.getInstance().loadIdentityByKey(key);
                    // No need to check for null, exception is thrown when identity does not exist which really
                    // should not happen at all.
                    // Tell that an identity has been chosen
                    fireEvent(ureq, new SingleIdentityChosenEvent(chosenIdent));
                }
            } catch (NumberFormatException e) {
                getWindowControl().setWarning(translate("error.no.user.found"));
                return;
            }
        }
    } else if (source == searchform) {
        if (event == Event.DONE_EVENT) {
            // form validation was ok
            doSearch(ureq);
        } else if (event == Event.CANCELLED_EVENT) {
            fireEvent(ureq, Event.CANCELLED_EVENT);
        }
    }
}
Also used : TableEvent(org.olat.core.gui.components.table.TableEvent) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) SingleIdentityChosenEvent(org.olat.basesecurity.events.SingleIdentityChosenEvent) ArrayList(java.util.ArrayList) List(java.util.List) Identity(org.olat.core.id.Identity) MultiIdentityChosenEvent(org.olat.basesecurity.events.MultiIdentityChosenEvent) EntriesChosenEvent(org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent)

Example 17 with TableMultiSelectEvent

use of org.olat.core.gui.components.table.TableMultiSelectEvent in project openolat by klemens.

the class GroupOverviewController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    super.event(ureq, source, event);
    if (source == groupListCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            GroupOverviewRow item = tableDataModel.getObject(te.getRowId());
            BusinessGroup currBusinessGroup = businessGroupService.loadBusinessGroup(item.getKey());
            if (currBusinessGroup == null) {
                // group seems to be removed meanwhile, reload table and show error
                showError("group.removed");
                updateModel();
            } else if (TABLE_ACTION_LAUNCH.equals(te.getActionId())) {
                NewControllerFactory.getInstance().launch("[BusinessGroup:" + currBusinessGroup.getKey() + "]", ureq, getWindowControl());
            } else if (TABLE_ACTION_UNSUBSCRIBE.equals(te.getActionId())) {
                doLeave(ureq, Collections.singletonList(currBusinessGroup));
            }
        } else if (event instanceof TableMultiSelectEvent) {
            TableMultiSelectEvent mse = (TableMultiSelectEvent) event;
            List<GroupOverviewRow> items = tableDataModel.getObjects(mse.getSelection());
            if (TABLE_ACTION_UNSUBSCRIBE.equals(mse.getAction())) {
                List<BusinessGroup> groups = toBusinessGroups(items);
                doLeave(ureq, groups);
            }
        }
    } else if (source == groupsCtrl && event instanceof AddToGroupsEvent) {
        AddToGroupsEvent groupsEv = (AddToGroupsEvent) event;
        if (groupsEv.isEmpty()) {
            // no groups selected
            showWarning("group.add.result.none");
        } else {
            if (cmc != null) {
                cmc.deactivate();
            }
            boolean mailMandatory = groupModule.isMandatoryEnrolmentEmail(ureq.getUserSession().getRoles());
            if (mailMandatory) {
                doAddToGroups(groupsEv, true);
                updateModel();
            } else {
                confirmSendMailBox = activateYesNoDialog(ureq, null, translate("dialog.modal.bg.send.mail"), confirmSendMailBox);
                confirmSendMailBox.setUserObject(groupsEv);
            }
        }
        cleanUpPopups();
    } else if (source == confirmSendMailBox) {
        boolean sendMail = DialogBoxUIFactory.isYesEvent(event) || DialogBoxUIFactory.isOkEvent(event);
        AddToGroupsEvent groupsEv = (AddToGroupsEvent) confirmSendMailBox.getUserObject();
        doAddToGroups(groupsEv, sendMail);
        updateModel();
    } else if (source == removeFromGrpDlg) {
        if (event == Event.DONE_EVENT) {
            boolean sendMail = removeFromGrpDlg.isSendMail();
            List<BusinessGroup> groupsToDelete = removeFromGrpDlg.getGroupsToDelete();
            List<BusinessGroup> groupsToLeave = removeFromGrpDlg.getGroupsToLeave();
            removeUserFromGroup(ureq, groupsToLeave, groupsToDelete, sendMail);
        }
        cmc.deactivate();
        cleanUpPopups();
    } else if (source == cmc) {
        cleanUpPopups();
    }
}
Also used : AddToGroupsEvent(org.olat.group.model.AddToGroupsEvent) TableEvent(org.olat.core.gui.components.table.TableEvent) BusinessGroup(org.olat.group.BusinessGroup) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with TableMultiSelectEvent

use of org.olat.core.gui.components.table.TableMultiSelectEvent in project openolat by klemens.

the class OrphanVersionsController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == tableCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            String actionid = te.getActionId();
            int rowid = te.getRowId();
            OrphanVersion orphan = (OrphanVersion) tableCtr.getTableDataModel().getObject(rowid);
            if (actionid.equals(CMD_DELETE)) {
                VersionsManager.getInstance().delete(orphan);
                orphans.remove(orphan);
                tableCtr.modelChanged();
            }
        } else if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
            // Multiselect events
            TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
            BitSet selectedOrphans = tmse.getSelection();
            String actionid = tmse.getAction();
            if (CMD_DELETE.equals(actionid)) {
                List<OrphanVersion> toRemove = new ArrayList<OrphanVersion>();
                for (int i = selectedOrphans.nextSetBit(0); i >= 0; i = selectedOrphans.nextSetBit(i + 1)) {
                    int rowCount = tableCtr.getTableDataModel().getRowCount();
                    if (i >= 0 && i < rowCount) {
                        OrphanVersion orphan = (OrphanVersion) tableCtr.getTableDataModel().getObject(i);
                        VersionsManager.getInstance().delete(orphan);
                        toRemove.add(orphan);
                    }
                }
                for (OrphanVersion orphan : toRemove) {
                    orphans.remove(orphan);
                }
                tableCtr.setTableDataModel(new OrphanTableModel(orphans));
                tableCtr.modelChanged();
            }
        }
    }
}
Also used : TableEvent(org.olat.core.gui.components.table.TableEvent) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) List(java.util.List) OrphanVersion(org.olat.core.util.vfs.version.OrphanVersion)

Example 19 with TableMultiSelectEvent

use of org.olat.core.gui.components.table.TableMultiSelectEvent in project openolat by klemens.

the class DENManageDatesController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    ICourse course = CourseFactory.loadCourse(ores);
    if (manageDatesForm == source) {
        // generate the dates and put them into the table
        editTableDataList = denManager.generateDates(manageDatesForm.getSubject(), manageDatesForm.getComment(), manageDatesForm.getLocation(), manageDatesForm.getDuration(), manageDatesForm.getPause(), manageDatesForm.getBeginDate(), manageDatesForm.getRetakes(), manageDatesForm.getNumParts(), editTableDataList, denCourseNode.getIdent());
        denManager.persistDENSettings(editTableDataList, course, denCourseNode);
        editDENTable.setTableDataModel(editTableData);
    } else if (source == editDENTable) {
        TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
        selectedDates = tmse.getSelection();
        // clicked button to edit one date or more dates
        if (tmse.getAction().equals(DENEditTableDataModel.CHANGE_ACTION) && selectedDates.cardinality() > 0) {
            if (selectedDates.cardinality() == 1) {
                // if only one date is choosen, we can prefill some entries
                removeAsListenerAndDispose(editSingleDateForm);
                editSingleDateForm = new DENDatesForm(ureq, getWindowControl(), getTranslator(), DENDatesForm.EDIT_SINGLE_DATE_LAYOUT);
                listenTo(editSingleDateForm);
                // in this case only one date is possible
                KalendarEvent calEvent = editTableData.getObjects(selectedDates).get(0);
                editSingleDateForm.setSubject(calEvent.getSubject());
                editSingleDateForm.setComment(calEvent.getComment());
                editSingleDateForm.setLocation(calEvent.getLocation());
                editSingleDateForm.setNumParts(calEvent.getNumParticipants());
                editSingleDateForm.setFormDate(calEvent.getBegin());
                editSingleDateForm.setDuration(denManager.getDurationAsString(calEvent));
                removeAsListenerAndDispose(editDateModalCntrll);
                editDateModalCntrll = new CloseableModalController(getWindowControl(), "close", editSingleDateForm.getInitialComponent(), true, translate("dates.edit"));
                listenTo(editDateModalCntrll);
            } else if (selectedDates.cardinality() > 1) {
                removeAsListenerAndDispose(editMultipleDatesForm);
                editMultipleDatesForm = new DENDatesForm(ureq, getWindowControl(), getTranslator(), DENDatesForm.EDIT_MULTIPLE_DATES_LAYOUT);
                listenTo(editMultipleDatesForm);
                removeAsListenerAndDispose(editDateModalCntrll);
                editDateModalCntrll = new CloseableModalController(getWindowControl(), "close", editMultipleDatesForm.getInitialComponent(), true, translate("dates.edit"));
                listenTo(editDateModalCntrll);
            }
            // persist dates
            denManager.persistDENSettings(editTableData.getObjects(), course, denCourseNode);
            editDateModalCntrll.activate();
        } else if (tmse.getAction().equals(DENEditTableDataModel.DELETE_ACTION)) {
            // delete selected dates
            editTableData.removeEntries(tmse.getSelection());
            editDENTable.setTableDataModel(editTableData);
            // persist dates
            denManager.persistDENSettings(editTableData.getObjects(), course, denCourseNode);
        }
    } else if (source == editSingleDateForm) {
        // save changes for one date
        editTableData.setObjects(denManager.updateDateInList(editSingleDateForm.getSubject(), editSingleDateForm.getComment(), editSingleDateForm.getLocation(), editSingleDateForm.getDuration(), editSingleDateForm.getBeginDate(), editSingleDateForm.getNumParts(), editTableData.getObjects(), // only one bit is set
        selectedDates.nextSetBit(0)));
        editDENTable.setTableDataModel(editTableData);
        denManager.persistDENSettings(editTableData.getObjects(), course, denCourseNode);
        editDateModalCntrll.deactivate();
    } else if (source == editMultipleDatesForm) {
        // save changes for multiple dates
        editTableData.setObjects(denManager.updateMultipleDatesInList(editMultipleDatesForm.getSubject(), editMultipleDatesForm.getComment(), editMultipleDatesForm.getLocation(), editMultipleDatesForm.getMovementGap(), editMultipleDatesForm.getNumParts(), editTableData.getObjects(), selectedDates));
        editDENTable.setTableDataModel(editTableData);
        denManager.persistDENSettings(editTableData.getObjects(), course, denCourseNode);
        editDateModalCntrll.deactivate();
    }
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) ICourse(org.olat.course.ICourse)

Example 20 with TableMultiSelectEvent

use of org.olat.core.gui.components.table.TableMultiSelectEvent in project openolat by klemens.

the class DENManageParticipantsController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == tableListParticipants) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent tableEvent = (TableEvent) event;
            // open window for choosen date to manage the enrolled users or manually add
            if (tableEvent.getActionId().equals(DENListTableDataModel.CHANGE_ACTION)) {
                selectedEvent = listTableData.getObject(tableEvent.getRowId());
                List<Identity> participants = denManager.getEventParticipants(selectedEvent);
                participantsTableData = new DENParticipantsTableDataModel(participants);
                removeAsListenerAndDispose(tableManageParticipants);
                tableManageParticipants = denManager.createParticipantsTable(ureq, getWindowControl(), getTranslator(), participantsTableData);
                listenTo(tableManageParticipants);
                participantsVC = createVelocityContainer("participants");
                DateFormat df = new SimpleDateFormat();
                participantsVC.contextPut("dateTitle", selectedEvent.getSubject());
                participantsVC.contextPut("dateTimeframe", df.format(selectedEvent.getBegin()) + " - " + df.format(selectedEvent.getEnd()));
                participantsVC.put("participantsTable", tableManageParticipants.getInitialComponent());
                addParticipantButton = LinkFactory.createButton("participants.add", participantsVC, this);
                removeAsListenerAndDispose(manageParticipantsModalCntrl);
                manageParticipantsModalCntrl = new CloseableModalController(getWindowControl(), "close", participantsVC, true, translate("dates.table.participant.manage"));
                listenTo(manageParticipantsModalCntrl);
                manageParticipantsModalCntrl.activate();
            }
        } else {
            TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
            BitSet selection = tmse.getSelection();
            // delete all users from the selected dates
            if (tmse.getAction().equals(DENListTableDataModel.DELETE_ACTION) && selection.cardinality() > 0) {
                selectedIds = denManager.getSelectedEventParticipants(dateList, selection);
                dateList = denManager.deleteParticipants(ores, courseNode, denManager.getSelectedEventIDs(dateList, selection));
                listTableData.setObjects(dateList);
                // send notification mail
                createNotificationMail(ureq, courseNode.getShortTitle(), REMOVE_ACTION);
            } else if (tmse.getAction().equals(DENListTableDataModel.MAIL_ACTION) && selection.cardinality() > 0) {
                // send email to all users from the selected dates
                List<Identity> participants = denManager.getSelectedEventParticipants(dateList, selection);
                createParticipantsMail(ureq, participants);
            } else if (selection.cardinality() == 0) {
                showWarning("participants.message.empty");
            }
        }
    } else if (source == userSearchCntrl) {
        if (event == Event.CANCELLED_EVENT) {
            userSearchCMC.deactivate();
        } else {
            List<Identity> toAdd = null;
            selectedIds = new ArrayList<Identity>();
            if (event instanceof SingleIdentityChosenEvent) {
                SingleIdentityChosenEvent singleEvent = (SingleIdentityChosenEvent) event;
                Identity choosenIdentity = singleEvent.getChosenIdentity();
                toAdd = new ArrayList<Identity>();
                toAdd.add(choosenIdentity);
            } else if (event instanceof MultiIdentityChosenEvent) {
                MultiIdentityChosenEvent multiEvent = (MultiIdentityChosenEvent) event;
                toAdd = multiEvent.getChosenIdentities();
            }
            boolean showMessage = false;
            if (toAdd != null && toAdd.size() > 0) {
                for (Identity identity : toAdd) {
                    status = denManager.doEnroll(identity, selectedEvent, ores, courseNode, true);
                    if (!status.isEnrolled() && status.getErrorMessage().equals(DENStatus.ERROR_ALREADY_ENROLLED))
                        showMessage = true;
                    else
                        selectedIds.add(identity);
                }
                if (showMessage)
                    showWarning("enrollment.warning.manual");
                refreshTables();
            }
            userSearchCMC.deactivate();
            if (selectedIds.size() > 0) {
                // write notification mail
                createNotificationMail(ureq, selectedEvent.getSubject(), ADD_ACTION);
            }
        }
    } else if (source == tableManageParticipants) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent tableEvent = (TableEvent) event;
            // delete single user from event
            if (tableEvent.getActionId().equals(DENParticipantsTableDataModel.REMOVE_ACTION)) {
                Identity identity = participantsTableData.getEntryAt(tableEvent.getRowId());
                status = denManager.cancelEnroll(identity, selectedEvent, ores);
                if (!status.isCancelled())
                    showError();
                else // send notification mail
                {
                    selectedIds.clear();
                    selectedIds.add(identity);
                    createNotificationMail(ureq, selectedEvent.getSubject(), REMOVE_ACTION);
                }
                refreshTables();
            // write email to single user
            } else if (tableEvent.getActionId().equals(DENParticipantsTableDataModel.MAIL_ACTION)) {
                List<Identity> participants = new ArrayList<Identity>();
                participants.add(participantsTableData.getEntryAt(tableEvent.getRowId()));
                createParticipantsMail(ureq, participants);
            }
        }
    } else if (source == notificationCtr && event == Event.DONE_EVENT) {
        if (notificationCtr.getMailTemplate() != null) {
            Identity sender = ureq.getIdentity();
            MailerResult result = new MailerResult();
            String metaId = UUID.randomUUID().toString().replace("-", "");
            MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
            MailBundle[] bundles = mailManager.makeMailBundles(context, selectedIds, notificationCtr.getMailTemplate(), sender, metaId, result);
            result.append(mailManager.sendMessage(bundles));
            if (notificationCtr.getMailTemplate().getCpfrom()) {
                MailBundle ccBundles = mailManager.makeMailBundle(context, sender, notificationCtr.getMailTemplate(), sender, metaId, result);
                result.append(mailManager.sendMessage(ccBundles));
            }
            MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
        }
        notificationCmc.deactivate();
        selectedIds.clear();
    } else if (source == contactCtr) {
        notificationCmc.deactivate();
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailerResult(org.olat.core.util.mail.MailerResult) MailContext(org.olat.core.util.mail.MailContext) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) TableEvent(org.olat.core.gui.components.table.TableEvent) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SingleIdentityChosenEvent(org.olat.basesecurity.events.SingleIdentityChosenEvent) ArrayList(java.util.ArrayList) ContactList(org.olat.core.util.mail.ContactList) List(java.util.List) Identity(org.olat.core.id.Identity) MultiIdentityChosenEvent(org.olat.basesecurity.events.MultiIdentityChosenEvent) MailBundle(org.olat.core.util.mail.MailBundle) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

TableMultiSelectEvent (org.olat.core.gui.components.table.TableMultiSelectEvent)48 TableEvent (org.olat.core.gui.components.table.TableEvent)40 ArrayList (java.util.ArrayList)34 List (java.util.List)34 Identity (org.olat.core.id.Identity)18 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)16 BitSet (java.util.BitSet)12 SingleIdentityChosenEvent (org.olat.basesecurity.events.SingleIdentityChosenEvent)10 MultiIdentityChosenEvent (org.olat.basesecurity.events.MultiIdentityChosenEvent)8 UserRequest (org.olat.core.gui.UserRequest)6 WindowControl (org.olat.core.gui.control.WindowControl)6 ControllerCreator (org.olat.core.gui.control.creator.ControllerCreator)6 PopupBrowserWindow (org.olat.core.gui.control.generic.popup.PopupBrowserWindow)6 MailNotificationEditController (org.olat.core.util.mail.MailNotificationEditController)6 MailTemplate (org.olat.core.util.mail.MailTemplate)6 UserInfoMainController (org.olat.user.UserInfoMainController)6 MediaResource (org.olat.core.gui.media.MediaResource)4 AssertException (org.olat.core.logging.AssertException)4 MailerResult (org.olat.core.util.mail.MailerResult)4 VFSRevisionMediaResource (org.olat.core.util.vfs.VFSRevisionMediaResource)4