/** * Copyright (c) 2008-2012 The Sakai Foundation * * Licensed under the Educational Community License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.osedu.org/licenses/ECL-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.sakaiproject.profile2.tool.pages.panels; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.AjaxFallbackLink; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.model.ResourceModel; import org.apache.wicket.spring.injection.annot.SpringBean; import org.sakaiproject.profile2.logic.SakaiProxy; import org.sakaiproject.profile2.model.UserProfile; public class MyInterestsDisplay extends Panel { private static final long serialVersionUID = 1L; private static final Logger log = Logger.getLogger(MyInterestsDisplay.class); private int visibleFieldCount = 0; @SpringBean(name="org.sakaiproject.profile2.logic.SakaiProxy") private SakaiProxy sakaiProxy; public MyInterestsDisplay(final String id, final UserProfile userProfile) { super(id); //this panel stuff final Component thisPanel = this; //get userProfile from userProfileModel //UserProfile userProfile = (UserProfile) this.getModelObject(); //get info from userProfile since we need to validate it and turn things off if not set. //otherwise we could just use a propertymodel // favourites and other String favouriteBooks = userProfile.getFavouriteBooks(); String favouriteTvShows = userProfile.getFavouriteTvShows(); String favouriteMovies = userProfile.getFavouriteMovies(); String favouriteQuotes = userProfile.getFavouriteQuotes(); //heading add(new Label("heading", new ResourceModel("heading.interests"))); //favourite books WebMarkupContainer booksContainer = new WebMarkupContainer("booksContainer"); booksContainer.add(new Label("booksLabel", new ResourceModel("profile.favourite.books"))); booksContainer.add(new Label("favouriteBooks", favouriteBooks)); add(booksContainer); if(StringUtils.isBlank(favouriteBooks)) { booksContainer.setVisible(false); } else { visibleFieldCount++; } //favourite tv shows WebMarkupContainer tvContainer = new WebMarkupContainer("tvContainer"); tvContainer.add(new Label("tvLabel", new ResourceModel("profile.favourite.tv"))); tvContainer.add(new Label("favouriteTvShows", favouriteTvShows)); add(tvContainer); if(StringUtils.isBlank(favouriteTvShows)) { tvContainer.setVisible(false); } else { visibleFieldCount++; } //favourite movies WebMarkupContainer moviesContainer = new WebMarkupContainer("moviesContainer"); moviesContainer.add(new Label("moviesLabel", new ResourceModel("profile.favourite.movies"))); moviesContainer.add(new Label("favouriteMovies", favouriteMovies)); add(moviesContainer); if(StringUtils.isBlank(favouriteMovies)) { moviesContainer.setVisible(false); } else { visibleFieldCount++; } //favourite quotes WebMarkupContainer quotesContainer = new WebMarkupContainer("quotesContainer"); quotesContainer.add(new Label("quotesLabel", new ResourceModel("profile.favourite.quotes"))); quotesContainer.add(new Label("favouriteQuotes", favouriteQuotes)); add(quotesContainer); if(StringUtils.isBlank(favouriteQuotes)) { quotesContainer.setVisible(false); } else { visibleFieldCount++; } //edit button AjaxFallbackLink editButton = new AjaxFallbackLink("editButton", new ResourceModel("button.edit")) { private static final long serialVersionUID = 1L; public void onClick(AjaxRequestTarget target) { Component newPanel = new MyInterestsEdit(id, userProfile); newPanel.setOutputMarkupId(true); thisPanel.replaceWith(newPanel); if(target != null) { target.addComponent(newPanel); //resize iframe target.appendJavascript("setMainFrameHeight(window.name);"); } } }; editButton.add(new Label("editButtonLabel", new ResourceModel("button.edit"))); editButton.setOutputMarkupId(true); if(userProfile.isLocked() && !sakaiProxy.isSuperUser()) { editButton.setVisible(false); } add(editButton); //no fields message Label noFieldsMessage = new Label("noFieldsMessage", new ResourceModel("text.no.fields")); add(noFieldsMessage); if(visibleFieldCount > 0) { noFieldsMessage.setVisible(false); } } }