diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/FormItem.java b/src/main/java/org/olat/core/gui/components/form/flexible/FormItem.java index f788b7b60707c0ef6a7675341b3083946fb853cd..17342675e005475aec13442871b97c439f160bf1 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/FormItem.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/FormItem.java @@ -254,6 +254,8 @@ public interface FormItem extends FormBaseComponentIdProvider { * i18n key parameters */ public void setLabel(String labelkey, String[] params); + + public void setLabel(String labelkey, String[] params, boolean translate); /** * see setErrorComponent for comments diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/elements/MultipleSelectionElement.java b/src/main/java/org/olat/core/gui/components/form/flexible/elements/MultipleSelectionElement.java index f5bbf2d3eedc341bbcb75ef95cdda29614cef322..7bed40d6170af885ce327add465a0dddbce767c9 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/elements/MultipleSelectionElement.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/elements/MultipleSelectionElement.java @@ -56,6 +56,8 @@ public interface MultipleSelectionElement extends SelectionElement { */ public void setKeysAndValues(String[] keys, String values[], String[] cssClasses); + public Set<String> getKeys(); + /** * @param howmany * @return diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormItemImpl.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormItemImpl.java index e0b23e8aad8a2f12419bbfd322d5dc126672c0aa..0e43ef1d4fbc6ca3f2e34e6da4eb166ee2afc5da 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormItemImpl.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/FormItemImpl.java @@ -64,6 +64,7 @@ public abstract class FormItemImpl implements FormItem, InlineElement { private Panel examplePanel; private String[] labelParams; private String labelKey; + private boolean translateLabel; private Component labelC; private Panel labelPanel; protected Translator translator; @@ -176,7 +177,7 @@ public abstract class FormItemImpl implements FormItem, InlineElement { protected abstract void rootFormAvailable(); protected boolean translateLabel() { - return true; + return translateLabel; } public void setTranslator(Translator translator) { @@ -211,19 +212,24 @@ public abstract class FormItemImpl implements FormItem, InlineElement { } public String getLabelText() { - return translate(labelKey, labelParams); + return translateLabel() ? translate(labelKey, labelParams) : labelKey; } public void setLabel(String label, String[] params) { + setLabel(label, params, true); + } + + public void setLabel(String label, String[] params, boolean translate) { if (label == null) { hasLabel = false; } hasLabel = true; + translateLabel = translate; labelKey = label; labelParams = params; // set label may be called before the translator is available if (getTranslator() != null) { - labelC = new SimpleLabelText(label, translate(label, params)); + labelC = new SimpleLabelText(label, getLabelText()); labelPanel.setContent(labelC); } } diff --git a/src/main/java/org/olat/group/ui/edit/BusinessGroupAreasController.java b/src/main/java/org/olat/group/ui/edit/BusinessGroupAreasController.java new file mode 100644 index 0000000000000000000000000000000000000000..54196ccdc2d6a3a7ec650492196d97a9bab67e2d --- /dev/null +++ b/src/main/java/org/olat/group/ui/edit/BusinessGroupAreasController.java @@ -0,0 +1,151 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.group.ui.edit; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.olat.core.CoreSpringFactory; +import org.olat.core.gui.UserRequest; +import org.olat.core.gui.components.form.flexible.FormItem; +import org.olat.core.gui.components.form.flexible.FormItemContainer; +import org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement; +import org.olat.core.gui.components.form.flexible.impl.FormBasicController; +import org.olat.core.gui.components.form.flexible.impl.FormEvent; +import org.olat.core.gui.control.Controller; +import org.olat.core.gui.control.WindowControl; +import org.olat.core.logging.activity.ThreadLocalUserActivityLogger; +import org.olat.group.BusinessGroup; +import org.olat.group.BusinessGroupService; +import org.olat.group.GroupLoggingAction; +import org.olat.group.area.BGArea; +import org.olat.group.area.BGAreaManager; +import org.olat.repository.RepositoryEntry; +import org.olat.util.logging.activity.LoggingResourceable; + +/** + * + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + */ +public class BusinessGroupAreasController extends FormBasicController { + + private BusinessGroup businessGroup; + private final BGAreaManager areaManager; + private final BusinessGroupService businessGroupService; + + public BusinessGroupAreasController(UserRequest ureq, WindowControl wControl, BusinessGroup businessGroup) { + super(ureq, wControl); + + this.businessGroup = businessGroup; + areaManager = CoreSpringFactory.getImpl(BGAreaManager.class); + businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); + + initForm(ureq); + updateBusinessGroup(businessGroup); + } + + @Override + protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { + setFormTitle("fieldset.legend.areas"); + setFormContextHelp("org.olat.group.ui.edit", "grp-${type}-select-area.html", "help.hover.bgArea-${type}"); + } + + private void updateBusinessGroup(BusinessGroup businessGroup) { + this.businessGroup = businessGroup; + for(FormItem item: flc.getFormComponents().values()) { + flc.remove(item); + } + + List<BGArea> selectedAreas = areaManager.findBGAreasOfBusinessGroup(businessGroup); + + List<RepositoryEntry> entries = businessGroupService.findRepositoryEntries(Collections.singletonList(businessGroup), 0, -1); + for(RepositoryEntry entry:entries) { + List<BGArea> areas = areaManager.findBGAreasInContext(entry.getOlatResource()); + String[] keys = new String[areas.size()]; + String[] values = new String[areas.size()]; + for(int i=areas.size(); i-->0; ) { + keys[i] = areas.get(i).getKey().toString(); + values[i] = areas.get(i).getName(); + } + MultipleSelectionElement el = uifactory.addCheckboxesVertical("repo_" + entry.getKey(), null, flc, keys, values, null, 1); + el.setLabel(entry.getDisplayname(), null, false); + el.showLabel(true); + el.setUserObject(entry.getOlatResource()); + el.addActionListener(this, FormEvent.ONCHANGE); + + for(String key:keys) { + for(BGArea area:selectedAreas) { + if(key.equals(area.getKey().toString())) { + el.select(key, true); + break; + } + } + } + } + } + + @Override + protected void doDispose() { + // + } + + @Override + protected void formOK(UserRequest ureq) { + // + } + + @Override + protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) { + if(source instanceof MultipleSelectionElement) { + MultipleSelectionElement mse = (MultipleSelectionElement)source; + Set<String> selectedAreaKeys = mse.getSelectedKeys(); + Set<String> allAreaKeys = mse.getKeys(); + List<BGArea> currentSelectedAreas = areaManager.findBGAreasOfBusinessGroup(businessGroup); + Map<String, BGArea> currentSelectedAreaKeys = new HashMap<String, BGArea>(); + for(BGArea area:currentSelectedAreas) { + currentSelectedAreaKeys.put(area.getKey().toString(), area); + } + + for(String areaKey:allAreaKeys) { + boolean selected = selectedAreaKeys.contains(areaKey); + boolean currentlySelected = currentSelectedAreaKeys.containsKey(areaKey); + if (selected && !currentlySelected) { + // add relation: + BGArea area = areaManager.loadArea(new Long(areaKey)); + areaManager.addBGToBGArea(businessGroup, area); + + ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_AREA_UPDATED, getClass(), + LoggingResourceable.wrap(area)); + } else if (!selected && currentlySelected) { + // remove relation: + BGArea area = currentSelectedAreaKeys.get(areaKey); + areaManager.removeBGFromArea(businessGroup, area); + + ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_AREA_UPDATED, getClass(), + LoggingResourceable.wrap(area)); + } + } + } + super.formInnerEvent(ureq, source, event); + } +} diff --git a/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java b/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java index dbaf8572dbcf0852c0edda2d11c6f84961baa1ee..33836efd2a05e132c0a76652f47ee6052da59496 100644 --- a/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java +++ b/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java @@ -25,24 +25,13 @@ package org.olat.group.ui.edit; -import java.util.Collections; -import java.util.Iterator; import java.util.List; import org.apache.commons.lang.StringEscapeUtils; -import org.olat.admin.securitygroup.gui.GroupController; -import org.olat.admin.securitygroup.gui.IdentitiesAddEvent; -import org.olat.admin.securitygroup.gui.IdentitiesMoveEvent; -import org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent; -import org.olat.admin.securitygroup.gui.WaitingGroupController; -import org.olat.basesecurity.SecurityGroup; -import org.olat.collaboration.CollaborationTools; -import org.olat.collaboration.CollaborationToolsFactory; -import org.olat.collaboration.CollaborationToolsSettingsController; import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; -import org.olat.core.gui.components.choice.Choice; +import org.olat.core.gui.components.panel.Panel; import org.olat.core.gui.components.tabbedpane.TabbedPane; import org.olat.core.gui.components.tabbedpane.TabbedPaneChangedEvent; import org.olat.core.gui.components.velocity.VelocityContainer; @@ -54,9 +43,7 @@ import org.olat.core.gui.control.controller.BasicController; import org.olat.core.gui.control.generic.dtabs.Activateable2; import org.olat.core.gui.control.generic.modal.DialogBoxController; import org.olat.core.gui.control.generic.modal.DialogBoxUIFactory; -import org.olat.core.id.Identity; import org.olat.core.id.Roles; -import org.olat.core.id.context.BusinessControlFactory; import org.olat.core.id.context.ContextEntry; import org.olat.core.id.context.StateEntry; import org.olat.core.logging.AssertException; @@ -66,78 +53,45 @@ import org.olat.core.util.Util; import org.olat.core.util.coordinate.CoordinatorManager; import org.olat.core.util.coordinate.LockResult; import org.olat.core.util.event.GenericEventListener; -import org.olat.core.util.mail.MailContext; -import org.olat.core.util.mail.MailContextImpl; -import org.olat.core.util.mail.MailHelper; -import org.olat.core.util.mail.MailTemplate; -import org.olat.core.util.mail.MailerResult; -import org.olat.core.util.mail.MailerWithTemplate; import org.olat.core.util.resource.OLATResourceableJustBeforeDeletedEvent; -import org.olat.course.groupsandrights.CourseRights; import org.olat.group.BusinessGroup; -import org.olat.group.BusinessGroupAddResponse; import org.olat.group.BusinessGroupService; import org.olat.group.GroupLoggingAction; -import org.olat.group.area.BGArea; -import org.olat.group.area.BGAreaManager; -import org.olat.group.model.DisplayMembers; -import org.olat.group.right.BGRightManager; -import org.olat.group.right.BGRights; import org.olat.group.ui.BGControllerFactory; -import org.olat.group.ui.BGMailHelper; -import org.olat.group.ui.BusinessGroupFormController; import org.olat.instantMessaging.InstantMessagingModule; import org.olat.util.logging.activity.LoggingResourceable; /** * Description: <BR> * This controller displays a tabbed pane that lets the user configure and - * modify a business group. The functionality must be configured using the - * BGConfigFlags. + * modify a business group. * <P> * Fires BusinessGroupModifiedEvent via the OLATResourceableEventCenter * <P> * Initial Date: Aug 17, 2004 * - * @author patrick + * @author patrick, srosse */ - public class BusinessGroupEditController extends BasicController implements ControllerEventListener, GenericEventListener, Activateable2 { - private final BGRightManager rightManager; - private final BGAreaManager areaManager; - private final BusinessGroupService businessGroupService; - - private BusinessGroupFormController modifyBusinessGroupController; - private BusinessGroup currBusinessGroup; - private CollaborationToolsSettingsController ctc; - private GroupController ownerGrpCntrllr; - private GroupController partipGrpCntrllr; - private WaitingGroupController waitingGruppeController; - private AreasToGroupDataModel areaDataModel; + private boolean hasResources; + private BusinessGroup currBusinessGroup; + private final BusinessGroupService businessGroupService; - private RightsToGroupDataModel rightDataModel; - private Choice areasChoice, rightsChoice; - private List<BGArea> selectedAreas; - private List<String> selectedRights; - private BGRights bgRights; private TabbedPane tabbedPane; - private VelocityContainer vc_edit; - private VelocityContainer vc_tab_bgDetails; - private VelocityContainer vc_tab_grpmanagement; - private VelocityContainer vc_tab_bgCTools; - private VelocityContainer vc_tab_bgAreas; - private VelocityContainer vc_tab_bgRights; - //fxdiff VCRP-1,2: access control of resources - private int tabAccessIndex; - private BusinessGroupEditAccessController tabAccessCtrl; - private DisplayMemberSwitchForm dmsForm; + private VelocityContainer mainVC; private LockResult lockEntry; - private DialogBoxController alreadyLockedDialogController; - + + //controllers in tabs + private BusinessGroupEditDetailsController editDetailsController; + private BusinessGroupToolsController collaborationToolsController; + private BusinessGroupMembersController membersController; private BusinessGroupEditResourceController resourceController; + private BusinessGroupAreasController areasController; + private BusinessGroupRightsController rightsController; + private BusinessGroupEditAccessController tabAccessCtrl; /** * Never call this constructor directly, use the BGControllerFactory instead!! @@ -158,100 +112,154 @@ public class BusinessGroupEditController extends BasicController implements Cont addLoggingResourceable(LoggingResourceable.wrap(businessGroup)); // Initialize managers - areaManager = CoreSpringFactory.getImpl(BGAreaManager.class); - rightManager = CoreSpringFactory.getImpl(BGRightManager.class); businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); - // Initialize other members // Initialize translator: - // package translator with default group fallback translators and type - // translator setTranslator(Util.createPackageTranslator(BGControllerFactory.class, getLocale(), getTranslator())); - // Initialize available rights - bgRights = new CourseRights(ureq.getLocale()); + // try to acquire edit lock on business group String locksubkey = "groupEdit"; lockEntry = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(businessGroup, ureq.getIdentity(), locksubkey); if (lockEntry.isSuccess()) { - // reload group to minimize stale object exception and update last usage - // timestamp + // reload group to minimize stale object exception and update last usage timestamp currBusinessGroup = businessGroupService.setLastUsageFor(getIdentity(), businessGroup); if(currBusinessGroup == null) { VelocityContainer vc = createVelocityContainer("deleted"); vc.contextPut("name", businessGroup.getName()); putInitialPanel(vc); - return; + } else { + // add as listener to BusinessGroup so we are being notified about changes. + CoordinatorManager.getInstance().getCoordinator().getEventBus().registerFor(this, ureq.getIdentity(), currBusinessGroup); + + //create some controllers + editDetailsController = new BusinessGroupEditDetailsController(ureq, getWindowControl(), businessGroup); + listenTo(editDetailsController); + + collaborationToolsController = new BusinessGroupToolsController(ureq, getWindowControl(), businessGroup); + listenTo(collaborationToolsController); + + membersController = new BusinessGroupMembersController(ureq, getWindowControl(), businessGroup); + listenTo(membersController); + + //fxdiff VCRP-1,2: access control of resources + tabbedPane = new TabbedPane("bgTabbs", ureq.getLocale()); + tabbedPane.addListener(this); + setAllTabs(ureq); + mainVC = createVelocityContainer("edit"); + mainVC.put("tabbedpane", tabbedPane); + String[] title = new String[] { StringEscapeUtils.escapeHtml(currBusinessGroup.getName()) }; + mainVC.contextPut("title", getTranslator().translate("group.edit.title", title)); + putInitialPanel(mainVC); } - - // add as listener to BusinessGroup so we are being notified about - // changes. - CoordinatorManager.getInstance().getCoordinator().getEventBus().registerFor(this, ureq.getIdentity(), currBusinessGroup); - - /* - * add Tabbed Panes for configuration - */ - //fxdiff VCRP-1,2: access control of resources - tabbedPane = new TabbedPane("bgTabbs", ureq.getLocale()); - tabbedPane.addListener(this); - setAllTabs(ureq); - vc_edit = createVelocityContainer("edit"); - vc_edit.put("tabbedpane", tabbedPane); - String[] title = new String[] { StringEscapeUtils.escapeHtml(currBusinessGroup.getName()) }; - vc_edit.contextPut("title", getTranslator().translate("group.edit.title", title)); - putInitialPanel(vc_edit); - }else{ + } else { //lock was not successful ! alreadyLockedDialogController = DialogBoxUIFactory.createResourceLockedMessage(ureq, wControl, lockEntry, "error.message.locked", getTranslator()); listenTo(alreadyLockedDialogController); alreadyLockedDialogController.activate(); - } - //fxdiff BAKS-7 Resume function - ContextEntry ce = wControl.getBusinessControl().popLauncherContextEntry(); - if(ce != null) { - wControl.getBusinessControl().setCurrentContextEntry(BusinessControlFactory.getInstance().createContextEntry(currBusinessGroup));//tab are not in the regular path - tabbedPane.activate(ureq, Collections.singletonList(ce), null); - tabbedPane.addToHistory(ureq, wControl); + putInitialPanel(new Panel("empty")); } } + /** + * Learning areas and and course rights should only appear when at least one course is associated.</br> + * <ul><li> + * a) No courses associated and user is not author</br> + * Description, Tools, Members, Publishing and booking + * </li><li> + * b) No course associated and user is author:</br> + * Description, Tools, Members, Courses, Publishing and booking + * </li><li> + * c) With courses associated:</br> + * Description, Tools, Members, Courses, Learning areas, Course rights, Publishing and booking + * + * @param ureq + */ private void setAllTabs(UserRequest ureq) { - vc_tab_bgDetails = createTabDetails(ureq, currBusinessGroup);// modifies vc_tab_bgDetails - tabbedPane.addTab(translate("group.edit.tab.details"), vc_tab_bgDetails); - - vc_tab_bgCTools = createTabCollabTools(ureq); - tabbedPane.addTab(translate("group.edit.tab.collabtools"), vc_tab_bgCTools); - - vc_tab_bgAreas = createTabAreas(); - tabbedPane.addTab(translate("group.edit.tab.areas"), vc_tab_bgAreas); - - vc_tab_bgRights = createTabRights(); - tabbedPane.addTab(translate("group.edit.tab.rights"), vc_tab_bgRights); - - vc_tab_grpmanagement = createTabGroupManagement(ureq); - tabbedPane.addTab(translate("group.edit.tab.members"), vc_tab_grpmanagement); - - resourceController = new BusinessGroupEditResourceController(ureq, getWindowControl(), currBusinessGroup); - listenTo(resourceController); - tabbedPane.addTab(translate("group.edit.tab.resources"), resourceController.getInitialComponent()); + hasResources = businessGroupService.hasResources(currBusinessGroup); + + tabbedPane.removeAll(); + tabbedPane.addTab(translate("group.edit.tab.details"), editDetailsController.getInitialComponent()); + tabbedPane.addTab(translate("group.edit.tab.collabtools"), collaborationToolsController.getInitialComponent()); - tabAccessCtrl = new BusinessGroupEditAccessController(ureq, getWindowControl(), currBusinessGroup); - listenTo(tabAccessCtrl); - tabAccessIndex = tabbedPane.addTab(translate("group.edit.tab.accesscontrol"), tabAccessCtrl.getInitialComponent()); + membersController.updateBusinessGroup(currBusinessGroup); + tabbedPane.addTab(translate("group.edit.tab.members"), membersController.getInitialComponent()); + //resources (optional) + resourceController = getResourceController(ureq); + if(resourceController != null) { + tabbedPane.addTab(translate("group.edit.tab.resources"), resourceController.getInitialComponent()); + } + //areas controller (optional) + areasController = getAreasController(ureq); + if(areasController != null) { + tabbedPane.addTab(translate("group.edit.tab.areas"), areasController.getInitialComponent()); + } + + rightsController = getRightsController(ureq); + if(rightsController != null) { + tabbedPane.addTab(translate("group.edit.tab.rights"), rightsController.getInitialComponent()); + } + + tabAccessCtrl = getAccessController(ureq); + if(tabAccessCtrl != null) { + tabbedPane.addTab(translate("group.edit.tab.accesscontrol"), tabAccessCtrl.getInitialComponent()); + } } /** - * Refresh Member-tab when waiting-list configuration change. + * The resources / courses tab is enabled if the user is + * an administrator, a group manager or an author. Or if the group has + * already some resources. + * * @param ureq + * @return */ - private void refreshAllTabs(UserRequest ureq) { - tabbedPane.removeAll(); - tabbedPane.addTab(translate("group.edit.tab.details"), vc_tab_bgDetails); - tabbedPane.addTab(translate("group.edit.tab.collabtools"), vc_tab_bgCTools); - tabbedPane.addTab(translate("group.edit.tab.areas"), vc_tab_bgAreas); - tabbedPane.addTab(translate("group.edit.tab.rights"), vc_tab_bgRights); - tabbedPane.addTab(translate("group.edit.tab.members"), createTabGroupManagement(ureq)); - tabbedPane.addTab(translate("group.edit.tab.resources"), resourceController.getInitialComponent()); - tabbedPane.addTab(translate("group.edit.tab.accesscontrol"), tabAccessCtrl.getInitialComponent()); + private BusinessGroupEditResourceController getResourceController(UserRequest ureq) { + Roles roles = ureq.getUserSession().getRoles(); + boolean enabled = roles.isOLATAdmin() || roles.isGroupManager() || roles.isAuthor() || hasResources; + if(enabled) { + if(resourceController == null) { + resourceController = new BusinessGroupEditResourceController(ureq, getWindowControl(), currBusinessGroup); + listenTo(resourceController); + } + return resourceController; + } + removeAsListenerAndDispose(resourceController); + resourceController = null; + return null; + } + + private BusinessGroupAreasController getAreasController(UserRequest ureq) { + if(hasResources) { + if(areasController == null) { + areasController = new BusinessGroupAreasController(ureq, getWindowControl(), currBusinessGroup); + listenTo(areasController); + } + return areasController; + } + removeAsListenerAndDispose(areasController); + areasController = null; + return null; + } + + private BusinessGroupRightsController getRightsController(UserRequest ureq) { + if(hasResources) { + if(rightsController == null) { + rightsController = new BusinessGroupRightsController(ureq, getWindowControl(), currBusinessGroup); + listenTo(rightsController); + } + return rightsController; + } + removeAsListenerAndDispose(rightsController); + rightsController = null; + return null; + } + + private BusinessGroupEditAccessController getAccessController(UserRequest ureq) { + if(tabAccessCtrl == null) { + tabAccessCtrl = new BusinessGroupEditAccessController(ureq, getWindowControl(), currBusinessGroup); + listenTo(tabAccessCtrl); + } + return tabAccessCtrl; } /** @@ -260,35 +268,7 @@ public class BusinessGroupEditController extends BasicController implements Cont */ @Override public void event(UserRequest ureq, Component source, Event event) { - if (source == areasChoice) { - if (event == Choice.EVNT_VALIDATION_OK) { - updateGroupAreaRelations(); - // do loggin - for (Iterator<BGArea> iter = selectedAreas.iterator(); iter.hasNext();) { - BGArea area = iter.next(); - ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_AREA_UPDATED, getClass(), - LoggingResourceable.wrap(area)); - } - if (selectedAreas.size()==0) { - ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_AREA_UPDATED_EMPTY, getClass()); - } - } - } else if (source == rightsChoice) { - if (event == Choice.EVNT_VALIDATION_OK) { - updateGroupRightsRelations(); - // do loggin - for (Iterator<String> iter = selectedRights.iterator(); iter.hasNext();) { - ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_RIGHT_UPDATED, getClass(), - LoggingResourceable.wrapBGRight(iter.next())); - } - if (selectedRights.size()==0) { - ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_RIGHT_UPDATED_EMPTY, getClass()); - } - // notify current active users of this business group - BusinessGroupModifiedEvent.fireModifiedGroupEvents(BusinessGroupModifiedEvent.GROUPRIGHTS_MODIFIED_EVENT, currBusinessGroup, null); - } - //fxdiff BAKS-7 Resume function - } else if (source == tabbedPane && event instanceof TabbedPaneChangedEvent) { + if (source == tabbedPane && event instanceof TabbedPaneChangedEvent) { tabbedPane.addToHistory(ureq, getWindowControl()); } } @@ -299,15 +279,7 @@ public class BusinessGroupEditController extends BasicController implements Cont */ @Override public void event(UserRequest ureq, Controller source, Event event) { - if (source == dmsForm && event == Event.CHANGED_EVENT) { - businessGroupService.updateDisplayMembers(currBusinessGroup, - new DisplayMembers(dmsForm.getShowOwners(), dmsForm.getShowPartipiciants(), dmsForm.getShowWaitingList())); - // notify current active users of this business group - BusinessGroupModifiedEvent.fireModifiedGroupEvents(BusinessGroupModifiedEvent.CONFIGURATION_MODIFIED_EVENT, currBusinessGroup, null); - // do loggin - ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_CONFIGURATION_CHANGED, getClass()); - - } else if (source == ctc) { + if (source == collaborationToolsController) { if (event == Event.CHANGED_EVENT) { // notify current active users of this business group BusinessGroupModifiedEvent @@ -318,313 +290,31 @@ public class BusinessGroupEditController extends BasicController implements Cont if (event == Event.CANCELLED_EVENT || DialogBoxUIFactory.isOkEvent(event)) { fireEvent(ureq, Event.CANCELLED_EVENT); } - } else if(event instanceof IdentitiesAddEvent ) { - IdentitiesAddEvent identitiesAddedEvent = (IdentitiesAddEvent) event; - BusinessGroupAddResponse response = null; - addLoggingResourceable(LoggingResourceable.wrap(currBusinessGroup)); - if (source == ownerGrpCntrllr) { - response = businessGroupService.addOwners(ureq.getIdentity(), identitiesAddedEvent.getAddIdentities(), currBusinessGroup); - } else if (source == partipGrpCntrllr) { - response = businessGroupService.addParticipants(ureq.getIdentity(), identitiesAddedEvent.getAddIdentities(), currBusinessGroup); - } else if (source == waitingGruppeController) { - response = businessGroupService.addToWaitingList(ureq.getIdentity(), identitiesAddedEvent.getAddIdentities(), currBusinessGroup); - } - identitiesAddedEvent.setIdentitiesAddedEvent(response.getAddedIdentities()); - identitiesAddedEvent.setIdentitiesWithoutPermission(response.getIdentitiesWithoutPermission()); - identitiesAddedEvent.setIdentitiesAlreadyInGroup(response.getIdentitiesAlreadyInGroup()); - fireEvent(ureq, Event.CHANGED_EVENT ); - } else if (event instanceof IdentitiesRemoveEvent) { - List<Identity> identities = ((IdentitiesRemoveEvent) event).getRemovedIdentities(); - if (source == ownerGrpCntrllr) { - businessGroupService.removeOwners(ureq.getIdentity(), identities, currBusinessGroup); - } else if (source == partipGrpCntrllr) { - businessGroupService.removeParticipants(ureq.getIdentity(), identities, currBusinessGroup); - if (currBusinessGroup.getWaitingListEnabled().booleanValue()) { - // It is possible that a user is transfered from waiting-list to participants => reload data to see transfered user in right group. - partipGrpCntrllr.reloadData(); - waitingGruppeController.reloadData(); - } - } else if (source == waitingGruppeController) { - businessGroupService.removeFromWaitingList(ureq.getIdentity(), identities, currBusinessGroup); - } - fireEvent(ureq, Event.CHANGED_EVENT ); - } else if (source == waitingGruppeController) { - if (event instanceof IdentitiesMoveEvent) { - IdentitiesMoveEvent identitiesMoveEvent = (IdentitiesMoveEvent) event; - BusinessGroupAddResponse response = businessGroupService.moveIdentityFromWaitingListToParticipant(identitiesMoveEvent.getChosenIdentities(), ureq.getIdentity(), currBusinessGroup); - identitiesMoveEvent.setNotMovedIdentities(response.getIdentitiesAlreadyInGroup()); - identitiesMoveEvent.setMovedIdentities(response.getAddedIdentities()); - // Participant and waiting-list were changed => reload both - partipGrpCntrllr.reloadData(); - waitingGruppeController.reloadData(); - // send mail for all of them - MailerWithTemplate mailer = MailerWithTemplate.getInstance(); - MailTemplate mailTemplate = identitiesMoveEvent.getMailTemplate(); - if (mailTemplate != null) { - //fxdiff VCRP-16: intern mail system - MailContext context = new MailContextImpl(currBusinessGroup, null, getWindowControl().getBusinessControl().getAsString()); - MailerResult mailerResult = mailer.sendMailAsSeparateMails(context, identitiesMoveEvent.getMovedIdentities(), null, null, mailTemplate, null); - MailHelper.printErrorsAndWarnings(mailerResult, getWindowControl(), ureq.getLocale()); - } - fireEvent(ureq, Event.CHANGED_EVENT ); - } - //fxdiff VCRP-1,2: access control of resources - } else if (source == modifyBusinessGroupController || source == tabAccessCtrl) { - if (event == Event.DONE_EVENT) { - // update business group with the specified values - // values are taken from the modifyBusinessGroupForm - currBusinessGroup = updateBusinessGroup(); + } else if (source == editDetailsController) { + if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) { + //reload the business group + currBusinessGroup = editDetailsController.getGroup(); // inform index about change - refreshAllTabs(ureq); + setAllTabs(ureq); // notify current active users of this business group BusinessGroupModifiedEvent - .fireModifiedGroupEvents(BusinessGroupModifiedEvent.CONFIGURATION_MODIFIED_EVENT, this.currBusinessGroup, null); + .fireModifiedGroupEvents(BusinessGroupModifiedEvent.CONFIGURATION_MODIFIED_EVENT, currBusinessGroup, null); // rename the group also in the IM servers group list if (InstantMessagingModule.isEnabled()) { - String groupID = InstantMessagingModule.getAdapter().createChatRoomString(this.currBusinessGroup); - InstantMessagingModule.getAdapter().renameRosterGroup(groupID, this.modifyBusinessGroupController.getGroupName()); + String groupID = InstantMessagingModule.getAdapter().createChatRoomString(currBusinessGroup); + InstantMessagingModule.getAdapter().renameRosterGroup(groupID, currBusinessGroup.getName()); } // do logging ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_CONFIGURATION_CHANGED, getClass()); - //fxdiff VCRP-1,2: access control of resources - if(source == tabAccessCtrl) { - tabbedPane.setSelectedPane(tabAccessIndex); - } - - } else if (event == Event.CANCELLED_EVENT) { - // reinit details form - // TODO:fj:b introduce reset() for a form - - if (this.modifyBusinessGroupController != null) { - removeAsListenerAndDispose(this.modifyBusinessGroupController); - } - modifyBusinessGroupController = new BusinessGroupFormController(ureq, getWindowControl(), currBusinessGroup); - listenTo(modifyBusinessGroupController); - vc_tab_bgDetails.put("businessGroupForm", this.modifyBusinessGroupController.getInitialComponent()); - } } else if (source == resourceController) { + setAllTabs(ureq); fireEvent(ureq, event); } } - /** - * persist the updates - */ - private BusinessGroup updateBusinessGroup() { - String bgName = modifyBusinessGroupController.getGroupName(); - String bgDesc = modifyBusinessGroupController.getGroupDescription(); - Integer bgMax = modifyBusinessGroupController.getGroupMax(); - Integer bgMin = modifyBusinessGroupController.getGroupMin(); - boolean waitingListEnabled = modifyBusinessGroupController.isWaitingListEnabled(); - boolean autoCloseRanksEnabled = modifyBusinessGroupController.isAutoCloseRanksEnabled(); - vc_tab_grpmanagement.contextPut("hasWaitingGrp", waitingListEnabled); - return businessGroupService.updateBusinessGroup(currBusinessGroup, bgName, bgDesc, - bgMin, bgMax, waitingListEnabled, autoCloseRanksEnabled); - } - - /** - * Update the areas associated to this group: remove and add areas - */ - private void updateGroupAreaRelations() { - // refresh group to prevent stale object exception and context proxy issues - currBusinessGroup = businessGroupService.loadBusinessGroup(currBusinessGroup); - // 1) add areas to group - List<Integer> addedAreas = areasChoice.getAddedRows(); - for (Integer position:addedAreas) { - BGArea area = areaDataModel.getObject(position.intValue()); - areaManager.addBGToBGArea(currBusinessGroup, area); - selectedAreas.add(area); - } - // 2) remove areas from group - List<Integer> removedAreas = areasChoice.getRemovedRows(); - for (Integer position: removedAreas) { - BGArea area = areaDataModel.getObject(position.intValue()); - areaManager.removeBGFromArea(currBusinessGroup, area); - selectedAreas.remove(area); - } - } - - /** - * Update the rights associated to this group: remove and add rights - */ - private void updateGroupRightsRelations() { - // refresh group to prevent stale object exception and context proxy issues - currBusinessGroup = businessGroupService.loadBusinessGroup(currBusinessGroup); - // 1) add rights to group - List<Integer> addedRights = rightsChoice.getAddedRows(); - for (Integer position: addedRights) { - String right = rightDataModel.getObject(position.intValue()); - rightManager.addBGRight(right, currBusinessGroup); - selectedRights.add(right); - } - // 2) remove rights from group - List<Integer> removedRights = rightsChoice.getRemovedRows(); - for (Integer position:removedRights) { - String right = rightDataModel.getObject(position.intValue()); - rightManager.removeBGRight(right, currBusinessGroup); - selectedRights.remove(right); - } - } - - /** - * get a CollaborationToolController via CollaborationToolsFactory, the CTC is - * initialised with the UserRequest. The CTC provides a List of Collaboration - * Tools which can be enabled and disabled (so far) through checkboxes. - * - * @param ureq - */ - private VelocityContainer createTabCollabTools(UserRequest ureq) { - VelocityContainer tmp = createVelocityContainer("tab_bgCollabTools"); - CollaborationTools ctsm = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(currBusinessGroup); - ctc = ctsm.createCollaborationToolsSettingsController(ureq, getWindowControl()); - // we are listening on CollaborationToolsSettingsController events - // which are just propagated to our attached controllerlistener... - // e.g. the BusinessGroupMainRunController, updating the MenuTree - // if a CollaborationToolsSetting has changed... so far this means - // enabling/disabling a Tool within the tree. - listenTo(ctc); - tmp.put("collabTools", ctc.getInitialComponent()); - tmp.contextPut("type", this.currBusinessGroup.getType()); - return tmp; - } - - /** - * adds a area-to-group tab to the tabbed pane - */ - private VelocityContainer createTabAreas() { - VelocityContainer tmp = createVelocityContainer("tab_bgAreas"); - List<BGArea> allAreas = areaManager.findBGAreasOfBusinessGroup(currBusinessGroup); - selectedAreas = areaManager.findBGAreasOfBusinessGroup(currBusinessGroup); - areaDataModel = new AreasToGroupDataModel(allAreas, selectedAreas); - - areasChoice = new Choice("areasChoice", getTranslator()); - areasChoice.setSubmitKey("submit"); - areasChoice.setCancelKey("cancel"); - areasChoice.setTableDataModel(areaDataModel); - areasChoice.addListener(this); - tmp.put("areasChoice", areasChoice); - tmp.contextPut("noAreasFound", (allAreas.size() > 0 ? Boolean.FALSE : Boolean.TRUE)); - tmp.contextPut("isGmAdmin", Boolean.TRUE); - tmp.contextPut("type", currBusinessGroup.getType()); - return tmp; - } - - /** - * adds a right-to-group tab to the tabbed pane - */ - private VelocityContainer createTabRights() { - VelocityContainer tmp = createVelocityContainer("tab_bgRights"); - selectedRights = rightManager.findBGRights(currBusinessGroup); - rightDataModel = new RightsToGroupDataModel(bgRights, selectedRights); - - rightsChoice = new Choice("rightsChoice", getTranslator()); - rightsChoice.setSubmitKey("submit"); - rightsChoice.setCancelKey("cancel"); - rightsChoice.setTableDataModel(this.rightDataModel); - rightsChoice.addListener(this); - tmp.put("rightsChoice", rightsChoice); - tmp.contextPut("type", this.currBusinessGroup.getType()); - return tmp; - } - - /** - * @param businessGroup - */ - private VelocityContainer createTabDetails(UserRequest ureq, BusinessGroup businessGroup) { - VelocityContainer tmp = createVelocityContainer("tab_bgDetail"); - - removeAsListenerAndDispose(modifyBusinessGroupController); - modifyBusinessGroupController = new BusinessGroupFormController(ureq, getWindowControl(), businessGroup); - listenTo(this.modifyBusinessGroupController); - - tmp.put("businessGroupForm", modifyBusinessGroupController.getInitialComponent()); - tmp.contextPut("BuddyGroup", businessGroup); - tmp.contextPut("type", currBusinessGroup.getType()); - tmp.contextPut("groupid", currBusinessGroup.getKey()); - return tmp; - } - - /** - * @param ureq - */ - private VelocityContainer createTabGroupManagement(UserRequest ureq) { - - boolean hasWaitingList = currBusinessGroup.getWaitingListEnabled().booleanValue(); - // - VelocityContainer tmp = createVelocityContainer("tab_bgGrpMngmnt"); - // Member Display Form, allows to enable/disable that others partips see - // partips and/or owners - // - DisplayMembers displayMembers = businessGroupService.getDisplayMembers(currBusinessGroup); - // configure the form with checkboxes for owners and/or partips according - // the booleans - removeAsListenerAndDispose(dmsForm); - dmsForm = new DisplayMemberSwitchForm(ureq, getWindowControl(), true, true, hasWaitingList); - listenTo(dmsForm); - // set if the checkboxes are checked or not. - dmsForm.setShowOwnersChecked(displayMembers.isShowOwners()); - dmsForm.setShowPartipsChecked(displayMembers.isShowParticipants()); - if (hasWaitingList) dmsForm.setShowWaitingListChecked(displayMembers.isShowWaitingList()); - - tmp.put("displayMembers", dmsForm.getInitialComponent()); - Roles roles = ureq.getUserSession().getRoles(); - boolean enableTablePreferences = roles.isOLATAdmin() || roles.isGroupManager(); - boolean requiresOwner = true; - // groupcontroller which allows to remove all members depending on - // configuration. - removeAsListenerAndDispose(ownerGrpCntrllr); - ownerGrpCntrllr = new GroupController(ureq, getWindowControl(), true, requiresOwner, enableTablePreferences, currBusinessGroup.getOwnerGroup()); - listenTo(ownerGrpCntrllr); - // add mail templates used when adding and removing users - MailTemplate ownerAddUserMailTempl = BGMailHelper.createAddParticipantMailTemplate(currBusinessGroup, ureq.getIdentity()); - ownerGrpCntrllr.setAddUserMailTempl(ownerAddUserMailTempl,true); - MailTemplate ownerAremoveUserMailTempl = BGMailHelper.createRemoveParticipantMailTemplate(currBusinessGroup, ureq.getIdentity()); - ownerGrpCntrllr.setRemoveUserMailTempl(ownerAremoveUserMailTempl,true); - // expose to velocity - tmp.put("ownerGrpMngmnt", ownerGrpCntrllr.getInitialComponent()); - tmp.contextPut("hasOwnerGrp", Boolean.TRUE); - - // groupcontroller which allows to remove all members - removeAsListenerAndDispose(partipGrpCntrllr); - partipGrpCntrllr = new GroupController(ureq, getWindowControl(), true, false, enableTablePreferences, currBusinessGroup.getPartipiciantGroup()); - listenTo(partipGrpCntrllr); - - // add mail templates used when adding and removing users - MailTemplate partAddUserMailTempl = BGMailHelper.createAddParticipantMailTemplate(currBusinessGroup, ureq.getIdentity()); - partipGrpCntrllr.setAddUserMailTempl(partAddUserMailTempl,true); - MailTemplate partAremoveUserMailTempl = BGMailHelper.createRemoveParticipantMailTemplate(currBusinessGroup, ureq.getIdentity()); - partipGrpCntrllr.setRemoveUserMailTempl(partAremoveUserMailTempl,true); - // expose to velocity - tmp.put("partipGrpMngmnt", partipGrpCntrllr.getInitialComponent()); - tmp.contextPut("type", this.currBusinessGroup.getType()); - - // Show waiting list only if enabled - if (hasWaitingList) { - // waitinglist-groupcontroller which allows to remove all members - SecurityGroup waitingList = currBusinessGroup.getWaitingGroup(); - removeAsListenerAndDispose(waitingGruppeController); - waitingGruppeController = new WaitingGroupController(ureq, getWindowControl(), true, false, enableTablePreferences, waitingList ); - listenTo(waitingGruppeController); - - // add mail templates used when adding and removing users - MailTemplate waitAddUserMailTempl = BGMailHelper.createAddWaitinglistMailTemplate(currBusinessGroup, ureq.getIdentity()); - waitingGruppeController.setAddUserMailTempl(waitAddUserMailTempl,true); - MailTemplate waitRemoveUserMailTempl = BGMailHelper.createRemoveWaitinglistMailTemplate(currBusinessGroup, ureq.getIdentity()); - waitingGruppeController.setRemoveUserMailTempl(waitRemoveUserMailTempl,true); - MailTemplate waitTransferUserMailTempl = BGMailHelper.createWaitinglistTransferMailTemplate(currBusinessGroup, ureq.getIdentity()); - waitingGruppeController.setTransferUserMailTempl(waitTransferUserMailTempl); - // expose to velocity - tmp.put("waitingGrpMngmnt", waitingGruppeController.getInitialComponent()); - tmp.contextPut("hasWaitingGrp", Boolean.TRUE); - } else { - tmp.contextPut("hasWaitingGrp", Boolean.FALSE); - } - return tmp; - } - /** * @see org.olat.core.util.event.GenericEventListener#event(org.olat.core.gui.control.Event) */ diff --git a/src/main/java/org/olat/group/ui/edit/BusinessGroupEditDetailsController.java b/src/main/java/org/olat/group/ui/edit/BusinessGroupEditDetailsController.java new file mode 100644 index 0000000000000000000000000000000000000000..f288d975cfc372ffe6b387e332469da164661d4b --- /dev/null +++ b/src/main/java/org/olat/group/ui/edit/BusinessGroupEditDetailsController.java @@ -0,0 +1,100 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.group.ui.edit; + +import org.olat.core.CoreSpringFactory; +import org.olat.core.gui.UserRequest; +import org.olat.core.gui.components.Component; +import org.olat.core.gui.components.velocity.VelocityContainer; +import org.olat.core.gui.control.Controller; +import org.olat.core.gui.control.Event; +import org.olat.core.gui.control.WindowControl; +import org.olat.core.gui.control.controller.BasicController; +import org.olat.group.BusinessGroup; +import org.olat.group.BusinessGroupService; +import org.olat.group.ui.BusinessGroupFormController; + +/** + * + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + */ +public class BusinessGroupEditDetailsController extends BasicController { + + private final VelocityContainer mainVC; + private final BusinessGroupFormController editController; + + private BusinessGroup businessGroup; + private final BusinessGroupService businessGroupService; + + public BusinessGroupEditDetailsController(UserRequest ureq, WindowControl wControl, BusinessGroup businessGroup) { + super(ureq, wControl); + + this.businessGroup = businessGroup; + businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); + + mainVC = createVelocityContainer("tab_bgDetail"); + + editController = new BusinessGroupFormController(ureq, getWindowControl(), businessGroup); + listenTo(editController); + + mainVC.put("businessGroupForm", editController.getInitialComponent()); + mainVC.contextPut("groupid", businessGroup.getKey()); + putInitialPanel(mainVC); + } + + public BusinessGroup getGroup() { + return businessGroup; + } + + @Override + protected void doDispose() { + // + } + + @Override + protected void event(UserRequest ureq, Component source, Event event) { + // + } + + @Override + protected void event(UserRequest ureq, Controller source, Event event) { + if(source == editController) { + if(event == Event.DONE_EVENT) { + businessGroup = updateBusinessGroup(); + fireEvent(ureq, Event.CHANGED_EVENT); + } + } + super.event(ureq, source, event); + } + + /** + * persist the updates + */ + private BusinessGroup updateBusinessGroup() { + String bgName = editController.getGroupName(); + String bgDesc = editController.getGroupDescription(); + Integer bgMax = editController.getGroupMax(); + Integer bgMin = editController.getGroupMin(); + boolean waitingListEnabled = editController.isWaitingListEnabled(); + boolean autoCloseRanksEnabled = editController.isAutoCloseRanksEnabled(); + return businessGroupService.updateBusinessGroup(businessGroup, bgName, bgDesc, + bgMin, bgMax, waitingListEnabled, autoCloseRanksEnabled); + } +} diff --git a/src/main/java/org/olat/group/ui/edit/BusinessGroupMembersController.java b/src/main/java/org/olat/group/ui/edit/BusinessGroupMembersController.java new file mode 100644 index 0000000000000000000000000000000000000000..dd5b77b0e1a537c3f2f76fe22f6c9cab96bf495d --- /dev/null +++ b/src/main/java/org/olat/group/ui/edit/BusinessGroupMembersController.java @@ -0,0 +1,231 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.group.ui.edit; + +import java.util.List; + +import org.olat.admin.securitygroup.gui.GroupController; +import org.olat.admin.securitygroup.gui.IdentitiesAddEvent; +import org.olat.admin.securitygroup.gui.IdentitiesMoveEvent; +import org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent; +import org.olat.admin.securitygroup.gui.WaitingGroupController; +import org.olat.basesecurity.SecurityGroup; +import org.olat.core.CoreSpringFactory; +import org.olat.core.gui.UserRequest; +import org.olat.core.gui.components.Component; +import org.olat.core.gui.components.velocity.VelocityContainer; +import org.olat.core.gui.control.Controller; +import org.olat.core.gui.control.Event; +import org.olat.core.gui.control.WindowControl; +import org.olat.core.gui.control.controller.BasicController; +import org.olat.core.id.Identity; +import org.olat.core.id.Roles; +import org.olat.core.logging.activity.ThreadLocalUserActivityLogger; +import org.olat.core.util.mail.MailContext; +import org.olat.core.util.mail.MailContextImpl; +import org.olat.core.util.mail.MailHelper; +import org.olat.core.util.mail.MailTemplate; +import org.olat.core.util.mail.MailerResult; +import org.olat.core.util.mail.MailerWithTemplate; +import org.olat.group.BusinessGroup; +import org.olat.group.BusinessGroupAddResponse; +import org.olat.group.BusinessGroupService; +import org.olat.group.GroupLoggingAction; +import org.olat.group.model.DisplayMembers; +import org.olat.group.ui.BGMailHelper; +import org.olat.util.logging.activity.LoggingResourceable; + +/** + * + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + */ +public class BusinessGroupMembersController extends BasicController { + + private final VelocityContainer mainVC; + + private DisplayMemberSwitchForm dmsForm; + private GroupController ownerGrpCntrllr; + private GroupController partipGrpCntrllr; + private WaitingGroupController waitingGruppeController; + + private BusinessGroup businessGroup; + private final BusinessGroupService businessGroupService; + + public BusinessGroupMembersController(UserRequest ureq, WindowControl wControl, BusinessGroup businessGroup) { + super(ureq, wControl); + + this.businessGroup = businessGroup; + businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); + + mainVC = createVelocityContainer("tab_bgGrpMngmnt"); + putInitialPanel(mainVC); + + boolean hasWaitingList = businessGroup.getWaitingListEnabled().booleanValue(); + + // Member Display Form, allows to enable/disable that others partips see + // partips and/or owners + // + DisplayMembers displayMembers = businessGroupService.getDisplayMembers(businessGroup); + // configure the form with checkboxes for owners and/or partips according + // the booleans + dmsForm = new DisplayMemberSwitchForm(ureq, getWindowControl(), true, true, hasWaitingList); + listenTo(dmsForm); + // set if the checkboxes are checked or not. + dmsForm.setShowOwnersChecked(displayMembers.isShowOwners()); + dmsForm.setShowPartipsChecked(displayMembers.isShowParticipants()); + if (hasWaitingList) { + dmsForm.setShowWaitingListChecked(displayMembers.isShowWaitingList()); + } + + mainVC.put("displayMembers", dmsForm.getInitialComponent()); + Roles roles = ureq.getUserSession().getRoles(); + boolean enableTablePreferences = roles.isOLATAdmin() || roles.isGroupManager(); + boolean requiresOwner = true; + // groupcontroller which allows to remove all members depending on + // configuration. + ownerGrpCntrllr = new GroupController(ureq, getWindowControl(), true, requiresOwner, enableTablePreferences, businessGroup.getOwnerGroup()); + listenTo(ownerGrpCntrllr); + // add mail templates used when adding and removing users + MailTemplate ownerAddUserMailTempl = BGMailHelper.createAddParticipantMailTemplate(businessGroup, ureq.getIdentity()); + ownerGrpCntrllr.setAddUserMailTempl(ownerAddUserMailTempl,true); + MailTemplate ownerAremoveUserMailTempl = BGMailHelper.createRemoveParticipantMailTemplate(businessGroup, ureq.getIdentity()); + ownerGrpCntrllr.setRemoveUserMailTempl(ownerAremoveUserMailTempl,true); + // expose to velocity + mainVC.put("ownerGrpMngmnt", ownerGrpCntrllr.getInitialComponent()); + mainVC.contextPut("hasOwnerGrp", Boolean.TRUE); + + // groupcontroller which allows to remove all members + removeAsListenerAndDispose(partipGrpCntrllr); + partipGrpCntrllr = new GroupController(ureq, getWindowControl(), true, false, enableTablePreferences, businessGroup.getPartipiciantGroup()); + listenTo(partipGrpCntrllr); + + // add mail templates used when adding and removing users + MailTemplate partAddUserMailTempl = BGMailHelper.createAddParticipantMailTemplate(businessGroup, ureq.getIdentity()); + partipGrpCntrllr.setAddUserMailTempl(partAddUserMailTempl,true); + MailTemplate partAremoveUserMailTempl = BGMailHelper.createRemoveParticipantMailTemplate(businessGroup, ureq.getIdentity()); + partipGrpCntrllr.setRemoveUserMailTempl(partAremoveUserMailTempl,true); + // expose to velocity + mainVC.put("partipGrpMngmnt", partipGrpCntrllr.getInitialComponent()); + + // Show waiting list only if enabled + // waitinglist-groupcontroller which allows to remove all members + SecurityGroup waitingList = businessGroup.getWaitingGroup(); + waitingGruppeController = new WaitingGroupController(ureq, getWindowControl(), true, false, enableTablePreferences, waitingList ); + listenTo(waitingGruppeController); + + // add mail templates used when adding and removing users + MailTemplate waitAddUserMailTempl = BGMailHelper.createAddWaitinglistMailTemplate(businessGroup, ureq.getIdentity()); + waitingGruppeController.setAddUserMailTempl(waitAddUserMailTempl,true); + MailTemplate waitRemoveUserMailTempl = BGMailHelper.createRemoveWaitinglistMailTemplate(businessGroup, ureq.getIdentity()); + waitingGruppeController.setRemoveUserMailTempl(waitRemoveUserMailTempl,true); + MailTemplate waitTransferUserMailTempl = BGMailHelper.createWaitinglistTransferMailTemplate(businessGroup, ureq.getIdentity()); + waitingGruppeController.setTransferUserMailTempl(waitTransferUserMailTempl); + // expose to velocity + mainVC.put("waitingGrpMngmnt", waitingGruppeController.getInitialComponent()); + + mainVC.contextPut("hasWaitingGrp", new Boolean(hasWaitingList)); + } + + @Override + protected void doDispose() { + // + } + + @Override + protected void event(UserRequest ureq, Component source, Event event) { + // + } + + protected void updateBusinessGroup(BusinessGroup businessGroup) { + this.businessGroup = businessGroup; + + boolean hasWaitingList = businessGroup.getWaitingListEnabled().booleanValue(); + Boolean waitingFlag = (Boolean)mainVC.getContext().get("hasWaitingGrp"); + if(waitingFlag == null || waitingFlag.booleanValue() != hasWaitingList) { + mainVC.contextPut("hasWaitingGrp", new Boolean(hasWaitingList)); + dmsForm.setWaitingListVisible(hasWaitingList); + } + } + + @Override + protected void event(UserRequest ureq, Controller source, Event event) { + if (source == dmsForm) { + if(event == Event.CHANGED_EVENT) { + businessGroupService.updateDisplayMembers(businessGroup, + new DisplayMembers(dmsForm.getShowOwners(), dmsForm.getShowPartipiciants(), dmsForm.getShowWaitingList())); + // notify current active users of this business group + BusinessGroupModifiedEvent.fireModifiedGroupEvents(BusinessGroupModifiedEvent.CONFIGURATION_MODIFIED_EVENT, businessGroup, null); + // do loggin + ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_CONFIGURATION_CHANGED, getClass()); + } + } else if(event instanceof IdentitiesAddEvent ) { + IdentitiesAddEvent identitiesAddedEvent = (IdentitiesAddEvent) event; + BusinessGroupAddResponse response = null; + addLoggingResourceable(LoggingResourceable.wrap(businessGroup)); + if (source == ownerGrpCntrllr) { + response = businessGroupService.addOwners(ureq.getIdentity(), identitiesAddedEvent.getAddIdentities(), businessGroup); + } else if (source == partipGrpCntrllr) { + response = businessGroupService.addParticipants(ureq.getIdentity(), identitiesAddedEvent.getAddIdentities(), businessGroup); + } else if (source == waitingGruppeController) { + response = businessGroupService.addToWaitingList(ureq.getIdentity(), identitiesAddedEvent.getAddIdentities(), businessGroup); + } + identitiesAddedEvent.setIdentitiesAddedEvent(response.getAddedIdentities()); + identitiesAddedEvent.setIdentitiesWithoutPermission(response.getIdentitiesWithoutPermission()); + identitiesAddedEvent.setIdentitiesAlreadyInGroup(response.getIdentitiesAlreadyInGroup()); + fireEvent(ureq, Event.CHANGED_EVENT ); + } else if (event instanceof IdentitiesRemoveEvent) { + List<Identity> identities = ((IdentitiesRemoveEvent) event).getRemovedIdentities(); + if (source == ownerGrpCntrllr) { + businessGroupService.removeOwners(ureq.getIdentity(), identities, businessGroup); + } else if (source == partipGrpCntrllr) { + businessGroupService.removeParticipants(ureq.getIdentity(), identities, businessGroup); + if (businessGroup.getWaitingListEnabled().booleanValue()) { + // It is possible that a user is transfered from waiting-list to participants => reload data to see transfered user in right group. + partipGrpCntrllr.reloadData(); + waitingGruppeController.reloadData(); + } + } else if (source == waitingGruppeController) { + businessGroupService.removeFromWaitingList(ureq.getIdentity(), identities, businessGroup); + } + fireEvent(ureq, Event.CHANGED_EVENT ); + } else if (source == waitingGruppeController) { + if (event instanceof IdentitiesMoveEvent) { + IdentitiesMoveEvent identitiesMoveEvent = (IdentitiesMoveEvent) event; + BusinessGroupAddResponse response = businessGroupService.moveIdentityFromWaitingListToParticipant(identitiesMoveEvent.getChosenIdentities(), ureq.getIdentity(), businessGroup); + identitiesMoveEvent.setNotMovedIdentities(response.getIdentitiesAlreadyInGroup()); + identitiesMoveEvent.setMovedIdentities(response.getAddedIdentities()); + // Participant and waiting-list were changed => reload both + partipGrpCntrllr.reloadData(); + waitingGruppeController.reloadData(); + // send mail for all of them + MailerWithTemplate mailer = MailerWithTemplate.getInstance(); + MailTemplate mailTemplate = identitiesMoveEvent.getMailTemplate(); + if (mailTemplate != null) { + //fxdiff VCRP-16: intern mail system + MailContext context = new MailContextImpl(businessGroup, null, getWindowControl().getBusinessControl().getAsString()); + MailerResult mailerResult = mailer.sendMailAsSeparateMails(context, identitiesMoveEvent.getMovedIdentities(), null, null, mailTemplate, null); + MailHelper.printErrorsAndWarnings(mailerResult, getWindowControl(), ureq.getLocale()); + } + fireEvent(ureq, Event.CHANGED_EVENT ); + } + } + super.event(ureq, source, event); + } +} diff --git a/src/main/java/org/olat/group/ui/edit/BusinessGroupRightsController.java b/src/main/java/org/olat/group/ui/edit/BusinessGroupRightsController.java new file mode 100644 index 0000000000000000000000000000000000000000..2e18f823b69f2dafbebb8e7429fe57c396d24bdd --- /dev/null +++ b/src/main/java/org/olat/group/ui/edit/BusinessGroupRightsController.java @@ -0,0 +1,133 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.group.ui.edit; + +import java.util.Iterator; +import java.util.List; + +import org.olat.core.CoreSpringFactory; +import org.olat.core.gui.UserRequest; +import org.olat.core.gui.components.Component; +import org.olat.core.gui.components.choice.Choice; +import org.olat.core.gui.components.velocity.VelocityContainer; +import org.olat.core.gui.control.Controller; +import org.olat.core.gui.control.Event; +import org.olat.core.gui.control.WindowControl; +import org.olat.core.gui.control.controller.BasicController; +import org.olat.core.logging.activity.ThreadLocalUserActivityLogger; +import org.olat.course.groupsandrights.CourseRights; +import org.olat.group.BusinessGroup; +import org.olat.group.BusinessGroupService; +import org.olat.group.GroupLoggingAction; +import org.olat.group.right.BGRightManager; +import org.olat.group.right.BGRights; +import org.olat.util.logging.activity.LoggingResourceable; + +/** + * + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + */ +public class BusinessGroupRightsController extends BasicController { + + private RightsToGroupDataModel rightDataModel; + private Choice rightsChoice; + private List<String> selectedRights; + private BGRights bgRights; + + private final VelocityContainer mainVC; + + private BusinessGroup businessGroup; + private final BGRightManager rightManager; + private final BusinessGroupService businessGroupService; + + public BusinessGroupRightsController(UserRequest ureq, WindowControl wControl, BusinessGroup businessGroup) { + super(ureq, wControl); + + this.businessGroup = businessGroup; + rightManager = CoreSpringFactory.getImpl(BGRightManager.class); + businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); + // Initialize available rights + bgRights = new CourseRights(ureq.getLocale()); + + mainVC = createVelocityContainer("tab_bgRights"); + selectedRights = rightManager.findBGRights(businessGroup); + rightDataModel = new RightsToGroupDataModel(bgRights, selectedRights); + + rightsChoice = new Choice("rightsChoice", getTranslator()); + rightsChoice.setSubmitKey("submit"); + rightsChoice.setCancelKey("cancel"); + rightsChoice.setTableDataModel(this.rightDataModel); + rightsChoice.addListener(this); + mainVC.put("rightsChoice", rightsChoice); + putInitialPanel(mainVC); + } + + @Override + protected void doDispose() { + // + } + + @Override + protected void event(UserRequest ureq, Component source, Event event) { + if (source == rightsChoice) { + if (event == Choice.EVNT_VALIDATION_OK) { + updateGroupRightsRelations(); + // do loggin + for (Iterator<String> iter = selectedRights.iterator(); iter.hasNext();) { + ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_RIGHT_UPDATED, getClass(), + LoggingResourceable.wrapBGRight(iter.next())); + } + if (selectedRights.size()==0) { + ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_RIGHT_UPDATED_EMPTY, getClass()); + } + // notify current active users of this business group + BusinessGroupModifiedEvent.fireModifiedGroupEvents(BusinessGroupModifiedEvent.GROUPRIGHTS_MODIFIED_EVENT, businessGroup, null); + } + //fxdiff BAKS-7 Resume function + } + } + + @Override + protected void event(UserRequest ureq, Controller source, Event event) { + super.event(ureq, source, event); + } + + /** + * Update the rights associated to this group: remove and add rights + */ + private void updateGroupRightsRelations() { + // refresh group to prevent stale object exception and context proxy issues + businessGroup = businessGroupService.loadBusinessGroup(businessGroup); + // 1) add rights to group + List<Integer> addedRights = rightsChoice.getAddedRows(); + for (Integer position: addedRights) { + String right = rightDataModel.getObject(position.intValue()); + rightManager.addBGRight(right, businessGroup); + selectedRights.add(right); + } + // 2) remove rights from group + List<Integer> removedRights = rightsChoice.getRemovedRows(); + for (Integer position:removedRights) { + String right = rightDataModel.getObject(position.intValue()); + rightManager.removeBGRight(right, businessGroup); + selectedRights.remove(right); + } + } +} diff --git a/src/main/java/org/olat/group/ui/edit/BusinessGroupToolsController.java b/src/main/java/org/olat/group/ui/edit/BusinessGroupToolsController.java new file mode 100644 index 0000000000000000000000000000000000000000..cad62d546ee57024ce0cd2a2ba3a144cc4cff88c --- /dev/null +++ b/src/main/java/org/olat/group/ui/edit/BusinessGroupToolsController.java @@ -0,0 +1,76 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.group.ui.edit; + +import org.olat.collaboration.CollaborationTools; +import org.olat.collaboration.CollaborationToolsFactory; +import org.olat.collaboration.CollaborationToolsSettingsController; +import org.olat.core.gui.UserRequest; +import org.olat.core.gui.components.Component; +import org.olat.core.gui.components.velocity.VelocityContainer; +import org.olat.core.gui.control.Controller; +import org.olat.core.gui.control.Event; +import org.olat.core.gui.control.WindowControl; +import org.olat.core.gui.control.controller.BasicController; +import org.olat.group.BusinessGroup; + +/** + * + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + */ +public class BusinessGroupToolsController extends BasicController { + + private final VelocityContainer mainVC; + private final CollaborationToolsSettingsController toolsController; + + public BusinessGroupToolsController(UserRequest ureq, WindowControl wControl, BusinessGroup businessGroup) { + super(ureq, wControl); + + mainVC = createVelocityContainer("tab_bgCollabTools"); + CollaborationTools ctsm = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(businessGroup); + toolsController = ctsm.createCollaborationToolsSettingsController(ureq, getWindowControl()); + // we are listening on CollaborationToolsSettingsController events + // which are just propagated to our attached controllerlistener... + // e.g. the BusinessGroupMainRunController, updating the MenuTree + // if a CollaborationToolsSetting has changed... so far this means + // enabling/disabling a Tool within the tree. + listenTo(toolsController); + mainVC.put("collabTools", toolsController.getInitialComponent()); + putInitialPanel(mainVC); + } + + @Override + protected void doDispose() { + // + } + + @Override + protected void event(UserRequest ureq, Component source, Event event) { + // + } + + @Override + protected void event(UserRequest ureq, Controller source, Event event) { + if(source == toolsController) { + fireEvent(ureq, event); + } + super.event(ureq, source, event); + } +} diff --git a/src/main/java/org/olat/group/ui/edit/DisplayMemberSwitchForm.java b/src/main/java/org/olat/group/ui/edit/DisplayMemberSwitchForm.java index a1e7007008cb9dbf20baec27f2856e5ee7fe545c..d628dcba0003a0062cdc19d0292570e730be8fc2 100644 --- a/src/main/java/org/olat/group/ui/edit/DisplayMemberSwitchForm.java +++ b/src/main/java/org/olat/group/ui/edit/DisplayMemberSwitchForm.java @@ -124,16 +124,13 @@ public class DisplayMemberSwitchForm extends FormBasicController { showWaitingList.select("xx", show); } - /** - * @see org.olat.core.gui.components.Form#validate(org.olat.core.gui.UserRequest) - */ - public boolean validate() { - return true; - } - public void setWaitingListReadOnly(boolean b) { showWaitingList.setEnabled(b); } + + public void setWaitingListVisible(boolean b) { + showWaitingList.setVisible(b); + } @Override protected void formOK(UserRequest ureq) {