001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors: Sun Seng David TAN <stan@nuxeo.com>
017 */
018package org.nuxeo.ecm.user.center.profile;
019
020import java.util.Map;
021
022import org.apache.commons.logging.Log;
023import org.apache.commons.logging.LogFactory;
024import org.jboss.seam.ScopeType;
025import org.jboss.seam.annotations.In;
026import org.jboss.seam.annotations.Name;
027import org.jboss.seam.annotations.Scope;
028import org.jboss.seam.faces.FacesMessages;
029import org.jboss.seam.international.StatusMessage;
030import org.nuxeo.ecm.webapp.action.WebActionsBean;
031import org.nuxeo.ecm.webapp.locale.LocaleStartup;
032
033/**
034 * Seam component to manage user preferences editing. UI is showing user preferences in a separate screen than user
035 * profile, but storing data the same way it is stored with user profile.
036 *
037 * @since 5.6
038 */
039@Name("userPreferencesActions")
040@Scope(ScopeType.CONVERSATION)
041public class UserPreferencesActions extends UserProfileActions {
042
043    public static final Log log = LogFactory.getLog(UserPreferencesActions.class);
044
045    private static final long serialVersionUID = 1L;
046
047    @In
048    protected transient WebActionsBean webActions;
049
050    @In(create = true, required = false)
051    protected FacesMessages facesMessages;
052
053    @In(create = true)
054    protected Map<String, String> messages;
055
056    public String navigateToPreferencesPage() {
057        webActions.setCurrentTabIds("MAIN_TABS:home,USER_CENTER:Preferences");
058        return "view_home";
059    }
060
061    /**
062     * Reset timezone from the cookie. The cookie need to be setted/reset before. (done in javascript)
063     *
064     * @since 5.6
065     */
066    public void resetTimezone() {
067        LocaleStartup localeStartup = LocaleStartup.instance();
068        if (localeStartup == null) {
069            log.warn("Locale Startup not available. Can't reset time zone");
070            facesMessages.add(StatusMessage.Severity.WARN, messages.get("label.userPreferences.resetTimeZone.error"));
071            return;
072        }
073        // performing the locale update
074        localeStartup.setupLocale(documentManager);
075        // performing time zone update form cookie
076        localeStartup.setupTimeZone(documentManager);
077        facesMessages.add(StatusMessage.Severity.INFO, messages.get("label.userPreferences.resetTimeZone.done"));
078    }
079
080}