001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials are made 005 * available under the terms of the GNU Lesser General Public License (LGPL) 006 * version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 011 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 012 * details. 013 * 014 * Contributors: Sun Seng David TAN <stan@nuxeo.com> 015 */ 016package org.nuxeo.ecm.user.center.profile; 017 018import java.util.Map; 019 020import org.apache.commons.logging.Log; 021import org.apache.commons.logging.LogFactory; 022import org.jboss.seam.ScopeType; 023import org.jboss.seam.annotations.In; 024import org.jboss.seam.annotations.Name; 025import org.jboss.seam.annotations.Scope; 026import org.jboss.seam.faces.FacesMessages; 027import org.jboss.seam.international.StatusMessage; 028import org.nuxeo.ecm.webapp.action.WebActionsBean; 029import org.nuxeo.ecm.webapp.locale.LocaleStartup; 030 031/** 032 * Seam component to manage user preferences editing. UI is showing user preferences in a separate screen than user 033 * profile, but storing data the same way it is stored with user profile. 034 * 035 * @since 5.6 036 */ 037@Name("userPreferencesActions") 038@Scope(ScopeType.CONVERSATION) 039public class UserPreferencesActions extends UserProfileActions { 040 041 public static final Log log = LogFactory.getLog(UserPreferencesActions.class); 042 043 private static final long serialVersionUID = 1L; 044 045 @In 046 protected transient WebActionsBean webActions; 047 048 @In(create = true, required = false) 049 protected FacesMessages facesMessages; 050 051 @In(create = true) 052 protected Map<String, String> messages; 053 054 public String navigateToPreferencesPage() { 055 webActions.setCurrentTabIds("MAIN_TABS:home,USER_CENTER:Preferences"); 056 return "view_home"; 057 } 058 059 /** 060 * Reset timezone from the cookie. The cookie need to be setted/reset before. (done in javascript) 061 * 062 * @since 5.6 063 */ 064 public void resetTimezone() { 065 LocaleStartup localeStartup = LocaleStartup.instance(); 066 if (localeStartup == null) { 067 log.warn("Locale Startup not available. Can't reset time zone"); 068 facesMessages.add(StatusMessage.Severity.WARN, messages.get("label.userPreferences.resetTimeZone.error")); 069 return; 070 } 071 // performing the locale update 072 localeStartup.setupLocale(documentManager); 073 // performing time zone update form cookie 074 localeStartup.setupTimeZone(documentManager); 075 facesMessages.add(StatusMessage.Severity.INFO, messages.get("label.userPreferences.resetTimeZone.done")); 076 } 077 078}