diff --git a/src/main/java/org/olat/user/DisplayPortraitController.java b/src/main/java/org/olat/user/DisplayPortraitController.java index f99e480cf65018d3337b6554e4b3833f8e423197..a46c5b92b2c466b8c22a7f5b6cbafc90959e412f 100644 --- a/src/main/java/org/olat/user/DisplayPortraitController.java +++ b/src/main/java/org/olat/user/DisplayPortraitController.java @@ -39,8 +39,12 @@ import org.olat.core.gui.control.controller.BasicController; import org.olat.core.gui.control.creator.ControllerCreator; import org.olat.core.gui.control.generic.popup.PopupBrowserWindow; import org.olat.core.id.Identity; +import org.olat.core.id.OLATResourceable; import org.olat.core.id.UserConstants; import org.olat.core.logging.AssertException; +import org.olat.core.util.coordinate.CoordinatorManager; +import org.olat.core.util.event.GenericEventListener; +import org.olat.core.util.resource.OresHelper; import org.olat.user.propertyhandlers.GenderPropertyHandler; /** @@ -52,11 +56,17 @@ import org.olat.user.propertyhandlers.GenderPropertyHandler; * @author Alexander Schneider * */ -public class DisplayPortraitController extends BasicController { +public class DisplayPortraitController extends BasicController implements GenericEventListener { private VelocityContainer myContent; private Identity portraitIdent; + private final String mapperPath; + private final UserAvatarMapper mapper; + private final OLATResourceable listenerOres; + + private final boolean useLarge; + private final boolean displayPortraitImage; /** * most common used constructor<br /> @@ -75,8 +85,6 @@ public class DisplayPortraitController extends BasicController { this(ureq,wControl,portraitIdent,useLarge,canLinkToHomePage,false,true); } - - /** * constructor with more config options<br /> * use this if you want to display the full name of the user (additionally @@ -96,17 +104,42 @@ public class DisplayPortraitController extends BasicController { * @param displayPortraitImage * if set to false, the portrait image will not be displayed */ - public DisplayPortraitController(UserRequest ureq, WindowControl wControl, Identity portraitIdent, boolean useLarge, boolean canLinkToHomePage, boolean displayUserFullName, boolean displayPortraitImage ) { + public DisplayPortraitController(UserRequest ureq, WindowControl wControl, Identity portraitIdent, + boolean useLarge, boolean canLinkToHomePage, boolean displayUserFullName, boolean displayPortraitImage ) { super(ureq, wControl); myContent = createVelocityContainer("displayportrait"); myContent.contextPut("canLinkToHomePage", canLinkToHomePage ? Boolean.TRUE : Boolean.FALSE); if (portraitIdent == null) throw new AssertException("identity can not be null!"); + + this.useLarge = useLarge; this.portraitIdent = portraitIdent; + this.displayPortraitImage = displayPortraitImage; + + mapper = new UserAvatarMapper(useLarge); + mapperPath = registerMapper(ureq, mapper); + myContent.contextPut("identityKey", portraitIdent.getKey().toString()); + myContent.contextPut("displayUserFullName", displayUserFullName); + String fullName = UserManager.getInstance().getUserDisplayName(portraitIdent); + myContent.contextPut("fullName", fullName); + String altText = translate("title.homepage") + ": " + fullName; + myContent.contextPut("altText", StringEscapeUtils.escapeHtml(altText)); + loadPortrait(); + putInitialPanel(myContent); + + listenerOres = OresHelper.createOLATResourceableInstance("portrait", getIdentity().getKey()); + CoordinatorManager.getInstance().getCoordinator().getEventBus().registerFor(this, portraitIdent, listenerOres); + } + + @Override + protected void doDispose() { + CoordinatorManager.getInstance().getCoordinator().getEventBus().deregisterFor(this, listenerOres); + } + + private void loadPortrait() { File portrait = null; if(displayPortraitImage){ - GenderPropertyHandler genderHander = (GenderPropertyHandler) UserManager.getInstance().getUserPropertiesConfig().getPropertyHandler(UserConstants.GENDER); String gender = "-"; // use as default if (genderHander != null) { @@ -137,22 +170,31 @@ public class DisplayPortraitController extends BasicController { } } - if (portrait != null){ - UserAvatarMapper mapper = new UserAvatarMapper(useLarge); - String mapperPath = registerMapper(ureq, mapper); + if (portrait != null) { myContent.contextPut("mapperUrl", mapper.createPathFor(mapperPath, portraitIdent)); + } else { + myContent.contextRemove("mapperUrl"); } + } else { + myContent.contextRemove("mapperUrl"); } myContent.contextPut("hasPortrait", (portrait != null) ? Boolean.TRUE : Boolean.FALSE); - myContent.contextPut("identityKey", portraitIdent.getKey().toString()); - myContent.contextPut("displayUserFullName", displayUserFullName); - String fullName = UserManager.getInstance().getUserDisplayName(portraitIdent); - myContent.contextPut("fullName", fullName); - String altText = translate("title.homepage") + ": " + fullName; - myContent.contextPut("altText", StringEscapeUtils.escapeHtml(altText)); - - putInitialPanel(myContent); + } + + @Override + public void event(Event event) { + if("changed-portrait".equals(event.getCommand()) && event instanceof ProfileEvent) { + try { + ProfileEvent pe = (ProfileEvent)event; + if(portraitIdent.getKey().equals(pe.getIdentityKey())) { + loadPortrait(); + myContent.setDirty(true); + } + } catch (Exception e) { + logError("", e); + } + } } /** @@ -184,15 +226,4 @@ public class DisplayPortraitController extends BasicController { PopupBrowserWindow pbw = getWindowControl().getWindowBackOffice().getWindowManager().createNewPopupBrowserWindowFor(ureq, layoutCtrlr); pbw.open(ureq); } - - - /** - * - * @see org.olat.core.gui.control.DefaultController#doDispose(boolean) - */ - @Override - protected void doDispose() { - // nothing to do yet - } - -} +} \ No newline at end of file diff --git a/src/main/java/org/olat/user/ProfileEvent.java b/src/main/java/org/olat/user/ProfileEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..26015022d57027f844b46b98ff6d8a96ea07ed73 --- /dev/null +++ b/src/main/java/org/olat/user/ProfileEvent.java @@ -0,0 +1,43 @@ +/** + * <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.user; + +import org.olat.core.util.event.MultiUserEvent; + +/** + * + * Initial date: 08.12.2014<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class ProfileEvent extends MultiUserEvent { + + private static final long serialVersionUID = 5206023295883585889L; + private Long identityKey; + + public ProfileEvent(String cmd, Long identityKey) { + super(cmd); + this.identityKey = identityKey; + } + + public Long getIdentityKey() { + return identityKey; + } +} diff --git a/src/main/java/org/olat/user/ProfileFormController.java b/src/main/java/org/olat/user/ProfileFormController.java index 31193b2b563f1b176d08b77ff0ce9e33ba13c0ef..60fb68febde0955e172cc35a6c1dc02c2acf23c8 100644 --- a/src/main/java/org/olat/user/ProfileFormController.java +++ b/src/main/java/org/olat/user/ProfileFormController.java @@ -376,12 +376,19 @@ public class ProfileFormController extends FormBasicController { dps.deletePortrait(identityToModify); deletePortrait.setVisible(false); portraitUpload.setInitialFile(null); + notifyPortraitChanged(); } flc.setDirty(true); } super.formInnerEvent(ureq, source, event); } + + private void notifyPortraitChanged() { + ProfileEvent newPortraitEvent = new ProfileEvent("changed-portrait", identityToModify.getKey()); + OLATResourceable ores = OresHelper.createOLATResourceableInstance("portrait", getIdentity().getKey()); + CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(newPortraitEvent, ores); + } @Override protected void formOK(final UserRequest ureq) { @@ -398,6 +405,7 @@ public class ProfileFormController extends FormBasicController { String uploadedFilename = portraitUpload.getUploadFileName(); if(uploadedImage != null) { dps.setPortrait(uploadedImage, uploadedFilename, identityToModify.getName()); + notifyPortraitChanged(); } // Store the "about me" text.