⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmscalendarwidget.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/widgets/CmsCalendarWidget.java,v $
 * Date   : $Date: 2006/09/22 15:17:03 $
 * Version: $Revision: 1.14 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.widgets;

import org.opencms.file.CmsObject;
import org.opencms.i18n.CmsMessages;
import org.opencms.main.CmsLog;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsWorkplace;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;

import org.apache.commons.logging.Log;

/**
 * Provides a DHTML calendar widget, for use on a widget dialog.<p>
 *
 * @author Alexander Kandzior 
 * 
 * @version $Revision: 1.14 $ 
 * 
 * @since 6.0.0 
 */
public class CmsCalendarWidget extends A_CmsWidget {

    /** The log object for this class. */
    private static final Log LOG = CmsLog.getLog(CmsCalendarWidget.class);

    /**
     * Creates a new calendar widget.<p>
     */
    public CmsCalendarWidget() {

        // empty constructor is required for class registration
        this("");
    }

    /**
     * Creates a new calendar widget with the given configuration.<p>
     * 
     * @param configuration the configuration to use
     */
    public CmsCalendarWidget(String configuration) {

        super(configuration);
    }

	/**
     * Creates the HTML JavaScript and stylesheet includes required by the calendar for the head of the page.<p>
     * 
     * The default <code>"opencms"</code> style is used.<p>
     * 
     * @param locale the locale to use for the calendar
     * 
     * @return the necessary HTML code for the js and stylesheet includes
     * 
     * @see #calendarIncludes(Locale, String)
     */
    public static String calendarIncludes(Locale locale) {

        return calendarIncludes(locale, "opencms");
    }

    /**
     * Creates the HTML JavaScript and stylesheet includes required by the calendar for the head of the page.<p>
     * 
     * @param locale the locale to use for the calendar
     * @param style the name of the used calendar style, e.g. "system", "blue"
     * 
     * @return the necessary HTML code for the js and stylesheet includes
     */
    public static String calendarIncludes(Locale locale, String style) {

        StringBuffer result = new StringBuffer(512);
        String calendarPath = CmsWorkplace.getSkinUri() + "components/js_calendar/";
        if (CmsStringUtil.isEmpty(style)) {
            style = "system";
        }
        result.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"");
        result.append(calendarPath);
        result.append("calendar-");
        result.append(style);
        result.append(".css\">\n");
        result.append("<script type=\"text/javascript\" src=\"");
        result.append(calendarPath);
        result.append("calendar.js\"></script>\n");
        result.append("<script type=\"text/javascript\" src=\"");
        result.append(calendarPath);
        result.append("lang/calendar-");
        result.append(locale.getLanguage());
        result.append(".js\"></script>\n");
        result.append("<script type=\"text/javascript\" src=\"");
        result.append(calendarPath);
        result.append("calendar-setup.js\"></script>\n");
        return result.toString();
    }

    /**
     * Generates the HTML to initialize the JavaScript calendar element on the end of a page.<p>
     * 
     * This method must be called at the end of a HTML page, e.g. before the closing &lt;body&gt; tag.<p>
     * 
     * @param messages the messages to use (for date and time formats)
     * @param inputFieldId the ID of the input field where the date is pasted to
     * @param triggerButtonId the ID of the button which triggers the calendar
     * @param align initial position of the calendar popup element
     * @param singleClick if true, a single click selects a date and closes the calendar, otherwise calendar is closed by doubleclick
     * @param weekNumbers show the week numbers in the calendar or not
     * @param mondayFirst show monday as first day of week
     * @param dateStatusFunc name of the function which determines if/how a date should be disabled
     * @param showTime true if the time selector should be shown, otherwise false
     * @return the HTML code to initialize a calendar poup element
     */
    public static String calendarInit(
        CmsMessages messages,
        String inputFieldId,
        String triggerButtonId,
        String align,
        boolean singleClick,
        boolean weekNumbers,
        boolean mondayFirst,
        String dateStatusFunc,
        boolean showTime) {

        StringBuffer result = new StringBuffer(512);
        if (CmsStringUtil.isEmpty(align)) {
            align = "Bc";
        }
        result.append("<script type=\"text/javascript\">\n");
        result.append("<!--\n");
        result.append("\tCalendar.setup({\n");
        result.append("\t\tinputField     :    \"");
        result.append(inputFieldId);
        result.append("\",\n");
        result.append("\t\tifFormat       :    \"");
        result.append(messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_DATE_FORMAT_0));
        if (showTime) {
            result.append(" ");
            result.append(messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_TIME_FORMAT_0));
        }
        result.append("\",\n");
        result.append("\t\tbutton         :    \"");
        result.append(triggerButtonId);
        result.append("\",\n");
        result.append("\t\talign          :    \"");
        result.append(align);
        result.append("\",\n");
        result.append("\t\tsingleClick    :    ");
        result.append(singleClick);
        result.append(",\n");
        result.append("\t\tweekNumbers    :    ");
        result.append(weekNumbers);
        result.append(",\n");
        result.append("\t\tmondayFirst    :    ");
        result.append(mondayFirst);
        result.append(",\n");
        result.append("\t\tshowsTime      :    " + showTime);
        if (showTime
            && (messages.key(org.opencms.workplace.Messages.GUI_CALENDAR_TIMEFORMAT_0).toLowerCase().indexOf("p") != -1)) {
            result.append(",\n\t\ttimeFormat     :    \"12\"");
        }
        if (CmsStringUtil.isNotEmpty(dateStatusFunc)) {
            result.append(",\n\t\tdateStatusFunc :    ");
            result.append(dateStatusFunc);
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -