Skip to content
Snippets Groups Projects
Commit 43c1c885 authored by srosse's avatar srosse
Browse files

CL-526: add css for the logo

parent 525852bf
No related branches found
No related tags found
No related merge requests found
Showing
with 155 additions and 61 deletions
......@@ -31,6 +31,7 @@ import org.apache.commons.lang.StringEscapeUtils;
import org.olat.core.commons.fullWebApp.popup.BaseFullWebappPopupLayoutFactory;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.Component;
import org.olat.core.gui.components.panel.StackedPanel;
import org.olat.core.gui.components.velocity.VelocityContainer;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.Event;
......@@ -64,10 +65,17 @@ public class DisplayPortraitController extends BasicController implements Generi
private final String mapperPath;
private final UserAvatarMapper mapper;
private final OLATResourceable listenerOres;
private final StackedPanel mainPanel;
private final boolean useLarge;
private final boolean displayPortraitImage;
private final boolean isAnonymous;
private final Display displayImage;
public enum Display {
portrait,
logo,
none
}
/**
* most common used constructor<br />
......@@ -82,8 +90,9 @@ public class DisplayPortraitController extends BasicController implements Generi
* @param canLinkToHomePage
* if set to true, the portrait is linked to the users homepage
*/
public DisplayPortraitController(UserRequest ureq, WindowControl wControl, Identity portraitIdent, boolean useLarge, boolean canLinkToHomePage) {
this(ureq,wControl,portraitIdent,useLarge,canLinkToHomePage,false,true);
public DisplayPortraitController(UserRequest ureq, WindowControl wControl, Identity portraitIdent,
boolean useLarge, boolean canLinkToHomePage) {
this(ureq, wControl, portraitIdent, useLarge, canLinkToHomePage, false, Display.portrait);
}
/**
......@@ -106,18 +115,43 @@ public class DisplayPortraitController extends BasicController implements Generi
* 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 ) {
boolean useLarge, boolean canLinkToHomePage, boolean displayUserFullName, boolean displayPortraitImage) {
this(ureq, wControl, portraitIdent, useLarge, canLinkToHomePage, displayUserFullName, displayPortraitImage ? Display.portrait : Display.none);
}
/**
* constructor with more config options<br />
* use this if you want to display the full name of the user or the logo (additionally or only)
*
* @param ureq
* @param wControl
* @param portraitIdent
* the identity to display
* @param useLarge
* if set to true, the portrait-image is displayed as "big"
* @param canLinkToHomePage
* if set to true, the portrait is linked to the users homepage
* @param displayUserFullName
* if set to true, the users full name ("firstname lastname") is
* displayed as well
* @param displayImage
* if set to none, the portrait image will not be displayed, set to portrait, show the protrait
* set to logo, show the logo.
*/
public DisplayPortraitController(UserRequest ureq, WindowControl wControl, Identity portraitIdent,
boolean useLarge, boolean canLinkToHomePage, boolean displayUserFullName, Display displayImage) {
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;
this.displayImage = displayImage;
this.isAnonymous = ureq.getUserSession().getRoles().isGuestOnly();
mapper = new UserAvatarMapper(useLarge);
mapper = new UserAvatarMapper(useLarge, displayImage);
mapperPath = registerMapper(ureq, mapper);
myContent.contextPut("identityKey", portraitIdent.getKey().toString());
......@@ -126,9 +160,9 @@ public class DisplayPortraitController extends BasicController implements Generi
myContent.contextPut("fullName", fullName);
String altText = translate("title.homepage") + ": " + fullName;
myContent.contextPut("altText", StringEscapeUtils.escapeHtml(altText));
mainPanel = putInitialPanel(myContent);
loadPortrait();
putInitialPanel(myContent);
listenerOres = OresHelper.createOLATResourceableInstance("portrait", getIdentity().getKey());
CoordinatorManager.getInstance().getCoordinator().getEventBus().registerFor(this, portraitIdent, listenerOres);
......@@ -140,43 +174,54 @@ public class DisplayPortraitController extends BasicController implements Generi
}
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) {
gender = genderHander.getInternalValue(portraitIdent.getUser());
}
if (useLarge){
portrait = DisplayPortraitManager.getInstance().getBigPortrait(portraitIdent.getName());
if (portrait != null) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.AVATAR_BIG_CSS_CLASS);
} else if (isAnonymous) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.ANONYMOUS_BIG_CSS_CLASS);
} else if (gender.equals("-")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_BIG_CSS_CLASS);
} else if (gender.equals("male")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_MALE_BIG_CSS_CLASS);
} else if (gender.equals("female")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_FEMALE_BIG_CSS_CLASS);
File image = null;
if(displayImage != Display.none) {
if(displayImage == Display.logo) {
if (useLarge) {
image = DisplayPortraitManager.getInstance().getBigLogo(portraitIdent.getName());
myContent.contextPut("portraitCssClass", DisplayPortraitManager.LOGO_BIG_CSS_CLASS);
} else {
image = DisplayPortraitManager.getInstance().getSmallLogo(portraitIdent.getName());
myContent.contextPut("portraitCssClass", DisplayPortraitManager.LOGO_SMALL_CSS_CLASS);
}
} else {
portrait = DisplayPortraitManager.getInstance().getSmallPortrait(portraitIdent.getName());
if (portrait != null) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.AVATAR_SMALL_CSS_CLASS);
} else if (isAnonymous) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.ANONYMOUS_SMALL_CSS_CLASS);
} else if (gender.equals("-")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_SMALL_CSS_CLASS);
} else if (gender.equals("male")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_MALE_SMALL_CSS_CLASS);
} else if (gender.equals("female")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_FEMALE_SMALL_CSS_CLASS);
mainPanel.setVisible(image != null);
} else if(displayImage == Display.portrait) {
GenderPropertyHandler genderHander = (GenderPropertyHandler) UserManager.getInstance().getUserPropertiesConfig().getPropertyHandler(UserConstants.GENDER);
String gender = "-"; // use as default
if (genderHander != null) {
gender = genderHander.getInternalValue(portraitIdent.getUser());
}
if (useLarge) {
image = DisplayPortraitManager.getInstance().getBigPortrait(portraitIdent.getName());
if (image != null) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.AVATAR_BIG_CSS_CLASS);
} else if (isAnonymous) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.ANONYMOUS_BIG_CSS_CLASS);
} else if (gender.equals("-")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_BIG_CSS_CLASS);
} else if (gender.equals("male")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_MALE_BIG_CSS_CLASS);
} else if (gender.equals("female")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_FEMALE_BIG_CSS_CLASS);
}
} else {
image = DisplayPortraitManager.getInstance().getSmallPortrait(portraitIdent.getName());
if (image != null) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.AVATAR_SMALL_CSS_CLASS);
} else if (isAnonymous) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.ANONYMOUS_SMALL_CSS_CLASS);
} else if (gender.equals("-")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_SMALL_CSS_CLASS);
} else if (gender.equals("male")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_MALE_SMALL_CSS_CLASS);
} else if (gender.equals("female")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_FEMALE_SMALL_CSS_CLASS);
}
}
}
if (portrait != null) {
if (image != null) {
myContent.contextPut("mapperUrl", mapper.createPathFor(mapperPath, portraitIdent));
} else {
myContent.contextRemove("mapperUrl");
......@@ -185,7 +230,7 @@ public class DisplayPortraitController extends BasicController implements Generi
myContent.contextRemove("mapperUrl");
}
myContent.contextPut("hasPortrait", (portrait != null) ? Boolean.TRUE : Boolean.FALSE);
myContent.contextPut("hasPortrait", (image != null) ? Boolean.TRUE : Boolean.FALSE);
}
@Override
......
......@@ -61,6 +61,8 @@ public class DisplayPortraitManager extends BasicManager implements UserDataDele
// The following class names refer to CSS class names in olat.css
public static final String AVATAR_BIG_CSS_CLASS = "o_portrait_avatar";
public static final String AVATAR_SMALL_CSS_CLASS = "o_portrait_avatar_small";
public static final String LOGO_BIG_CSS_CLASS = "o_portrait_logo";
public static final String LOGO_SMALL_CSS_CLASS = "o_portrait_logo_small";
public static final String ANONYMOUS_BIG_CSS_CLASS = "o_portrait_anonymous";
public static final String ANONYMOUS_SMALL_CSS_CLASS = "o_portrait_anonymous_small";
public static final String DUMMY_BIG_CSS_CLASS = "o_portrait_dummy";
......@@ -104,6 +106,20 @@ public class DisplayPortraitManager extends BasicManager implements UserDataDele
return getPortraitResource(identityKey, PORTRAIT_BIG_FILENAME);
}
public MediaResource getSmallLogoResource(String username) {
return getPortraitResource(username, LOGO_SMALL_FILENAME);
}
public MediaResource getSmallLogoResource(Long identityKey) {
return getPortraitResource(identityKey, LOGO_SMALL_FILENAME);
}
public MediaResource getBigLogoResource(String String) {
return getPortraitResource(String, LOGO_BIG_FILENAME);
}
public MediaResource getBigLogoResource(Long identityKey) {
return getPortraitResource(identityKey, LOGO_BIG_FILENAME);
}
/**
* Get the portrait media resource by identity name (username)
* @param identity
......
......@@ -25,6 +25,7 @@ import org.olat.core.CoreSpringFactory;
import org.olat.core.dispatcher.mapper.Mapper;
import org.olat.core.gui.media.MediaResource;
import org.olat.core.id.Identity;
import org.olat.user.DisplayPortraitController.Display;
/**
*
......@@ -39,8 +40,14 @@ public class UserAvatarMapper implements Mapper {
private final UserManager userManager;
private final DisplayPortraitManager portraitManager;
private final boolean useLarge;
private final Display displayImage;
public UserAvatarMapper(boolean useLargePortrait) {
this(useLargePortrait, Display.portrait);
}
public UserAvatarMapper(boolean useLargePortrait, Display displayImage) {
this.displayImage = displayImage;
useLarge = useLargePortrait;
portraitManager = DisplayPortraitManager.getInstance();
userManager = CoreSpringFactory.getImpl(UserManager.class);
......@@ -58,11 +65,19 @@ public class UserAvatarMapper implements Mapper {
String idKey = relPath.substring(0, endKeyIndex);
Long key = Long.parseLong(idKey);
String username = userManager.getUsername(key);
if (useLarge) {
return portraitManager.getBigPortraitResource(username);
} else {
return portraitManager.getSmallPortraitResource(username);
}
if(displayImage == Display.portrait) {
if (useLarge) {
return portraitManager.getBigPortraitResource(username);
} else {
return portraitManager.getSmallPortraitResource(username);
}
} else if(displayImage == Display.logo) {
if (useLarge) {
return portraitManager.getBigLogoResource(username);
} else {
return portraitManager.getSmallLogoResource(username);
}
}
}
}
return null;
......
This diff is collapsed.
This diff is collapsed.
......@@ -2,7 +2,18 @@
text-align:center;
}
.o_bcard_logo {
position: absolute;
top:19px;
right:19px;
}
.o_bcard_title_with_logo {
padding-right: 86px;
}
.o_visitingcard .o_portrait_avatar,
.o_visitingcard .o_portrait_logo,
.o_visitingcard .o_portrait_dummy,
.o_visitingcard .o_portrait_dummy_female_big,
.o_visitingcard .o_portrait_dummy_male_big,
......@@ -10,8 +21,13 @@
@media (max-width: $screen-xs-max) {
.o_visitingcard .o_portrait_avatar,
.o_visitingcard .o_portrait_logo,
.o_visitingcard .o_portrait_dummy,
.o_visitingcard .o_portrait_dummy_female_big,
.o_visitingcard .o_portrait_dummy_male_big,
.o_visitingcard .o_portrait_anonymous { width: 50px; height: 50px; margin: 5px 5px 0 0;}
.o_bcard_title_with_logo {
padding-right: 70px;
}
}
\ No newline at end of file
......@@ -255,6 +255,7 @@ ul.o_dropdown {
.o_portrait_dummy,
.o_portrait_dummy_female_big,
.o_portrait_dummy_male_big,
.o_portrait_logo,
.o_portrait_anonymous {width: 100px; height: 100px;}
.o_portrait_dummy {background-image: url('#{$o-images-path}portrait/dummy.png');}
.o_portrait_dummy_female_big {background-image: url('#{$o-images-path}portrait/dummy_female_big.png');}
......@@ -265,6 +266,7 @@ ul.o_dropdown {
.o_portrait_dummy_small,
.o_portrait_dummy_female_small,
.o_portrait_dummy_male_small,
.o_portrait_logo_small,
.o_portrait_anonymous_small {width: 30px; height: 30px;}
.o_portrait_dummy_small {background-image: url('#{$o-images-path}portrait/dummy_small.png');}
.o_portrait_dummy_female_small {background-image: url('#{$o-images-path}portrait/dummy_female_small.png');}
......
This diff is collapsed.
source diff could not be displayed: it is too large. Options to address this: view the blob.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment