001/**
002 * Copyright 2005-2018 The Kuali Foundation
003 *
004 * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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 */
016package org.kuali.rice.krad.uif.widget;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.krad.datadictionary.parse.BeanTag;
020import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
021
022import java.util.HashMap;
023import java.util.Map;
024
025/**
026 * Growls sets up settings for growls global to the current view and its pages
027 *
028 * <p>
029 * Some basic options of the plugin are exposed through this class, however additional options
030 * can be passed through setComponentOptions as usual. However, the header and theme option is set
031 * by the growl processing in PageGroup automatically. See the jquery jGrowl plugin for more details.
032 * </p>
033 *
034 * @author Kuali Rice Team (rice.collab@kuali.org)
035 */
036@BeanTag(name = "growls", parent = "Uif-Growls")
037public class Growls extends WidgetBase {
038    private static final long serialVersionUID = -8701090110933484411L;
039
040    private boolean sticky;
041    private int timeShown;
042    private String position;
043
044    public Growls() {
045        super();
046    }
047
048    /**
049     * Override to add property values to the template options
050     *
051     * {@inheritDoc}
052     */
053    @Override
054    public Map<String, String> getTemplateOptions() {
055        Map<String, String> templateOptions = super.getTemplateOptions();
056
057        if (templateOptions == null) {
058            super.setTemplateOptions(templateOptions = new HashMap<String, String>());
059        }
060
061        if (!templateOptions.containsKey("sticky")) {
062            templateOptions.put("sticky", Boolean.toString(sticky));
063        }
064        if (!templateOptions.containsKey("life")) {
065            templateOptions.put("life", Integer.toString(timeShown));
066        }
067        if (StringUtils.isNotBlank(position) && !templateOptions.containsKey("position")) {
068            templateOptions.put("position", position);
069        }
070
071        return templateOptions;
072    }
073
074    /**
075     * If true, the growl will stick to the page until the user dismisses it
076     *
077     * @return the sticky
078     */
079    @BeanTagAttribute
080    public boolean isSticky() {
081        return this.sticky;
082    }
083
084    /**
085     * @param sticky the sticky to set
086     */
087    public void setSticky(boolean sticky) {
088        this.sticky = sticky;
089    }
090
091    /**
092     * The time growls are shown in milliseconds
093     *
094     * @return the timeShown
095     */
096    @BeanTagAttribute
097    public int getTimeShown() {
098        return this.timeShown;
099    }
100
101    /**
102     * @param timeShown the timeShown to set
103     */
104    public void setTimeShown(int timeShown) {
105        this.timeShown = timeShown;
106    }
107
108    /**
109     * The position for the growls to appear in the window
110     * There are five options available: top-left, top-right, bottom-left, bottom-right, center.
111     *
112     * @return the position
113     */
114    @BeanTagAttribute
115    public String getPosition() {
116        return this.position;
117    }
118
119    /**
120     * @param position the position to set
121     */
122    public void setPosition(String position) {
123        this.position = position;
124    }
125}