/*
 * ICESOFT COMMERCIAL SOURCE CODE LICENSE V 1.1
 *
 * The contents of this file are subject to the ICEsoft Commercial Source
 * Code License Agreement V1.1 (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.icesoft.com/license/commercial-source-v1.1.html
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations under
 * the License.
 *
 * Copyright 2009-2015 ICEsoft Technologies Canada, Corp. All Rights Reserved.
 */
package com.icesoft.faces.facelets.example.schedule;

import com.icesoft.faces.application.showcase.util.FacesUtils;
import com.icesoft.faces.application.showcase.view.bean.BeanNames;
import com.icesoft.faces.facelets.component.schedule.CalendarController;
import com.icesoft.faces.facelets.component.util.CalendarViewUtil;

import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import java.io.Serializable;
import java.util.TimeZone;

/**
 * Session scope user information.
 */
public class ScheduleUser implements Serializable {

    private SelectItem[] timezones = {new SelectItem(TimeZone.getDefault().getID()),
            new SelectItem("America/Los_Angeles"),
            new SelectItem("America/Sao_Paulo"),
            new SelectItem("Europe/London"),
            new SelectItem("Europe/Brussels"),
            new SelectItem("Asia/Tokyo")};

    private String selectedTimezoneId = TimeZone.getDefault().getID();
    private boolean use24HourClock;


    public void timezoneValueChanged(ValueChangeEvent evt) {
        // Set the timezone in the CalendarViewUtil
        CalendarViewUtil cvu = (CalendarViewUtil) FacesUtils.getManagedBean(BeanNames.CALENDAR_VIEW_UTIL);
        cvu.setTimeZoneId((String) evt.getNewValue());
        // Refresh the data formatted with our new timezone
        CalendarController calendarController = (CalendarController) FacesUtils.getManagedBean(BeanNames.CALENDAR_CONTROLLER);
        calendarController.getCurrentCalViewController().initialize();
    }

    public SelectItem[] getTimezones() {
        return timezones;
    }

    public void setTimezones(SelectItem[] timezones) {
        this.timezones = timezones;
    }

    public String getSelectedTimezoneId() {
        return selectedTimezoneId;
    }

    public void setSelectedTimezoneId(String selectedTimezoneId) {
        this.selectedTimezoneId = selectedTimezoneId;
    }

    public boolean isUse24HourClock() {
        return use24HourClock;
    }

    public void setUse24HourClock(boolean use24HourClock) {
        this.use24HourClock = use24HourClock;
    }

}