annotate .svn/pristine/d0/d0f8878bdc56439db6ee9330f7bfbb77c7251f27.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 /* Copyright Mihai Bazon, 2002, 2003 | http://dynarch.com/mishoo/
Chris@909 2 * ---------------------------------------------------------------------------
Chris@909 3 *
Chris@909 4 * The DHTML Calendar
Chris@909 5 *
Chris@909 6 * Details and latest version at:
Chris@909 7 * http://dynarch.com/mishoo/calendar.epl
Chris@909 8 *
Chris@909 9 * This script is distributed under the GNU Lesser General Public License.
Chris@909 10 * Read the entire license text here: http://www.gnu.org/licenses/lgpl.html
Chris@909 11 *
Chris@909 12 * This file defines helper functions for setting up the calendar. They are
Chris@909 13 * intended to help non-programmers get a working calendar on their site
Chris@909 14 * quickly. This script should not be seen as part of the calendar. It just
Chris@909 15 * shows you what one can do with the calendar, while in the same time
Chris@909 16 * providing a quick and simple method for setting it up. If you need
Chris@909 17 * exhaustive customization of the calendar creation process feel free to
Chris@909 18 * modify this code to suit your needs (this is recommended and much better
Chris@909 19 * than modifying calendar.js itself).
Chris@909 20 */
Chris@909 21
Chris@909 22 // $Id: calendar-setup.js,v 1.25 2005/03/07 09:51:33 mishoo Exp $
Chris@909 23
Chris@909 24 /**
Chris@909 25 * This function "patches" an input field (or other element) to use a calendar
Chris@909 26 * widget for date selection.
Chris@909 27 *
Chris@909 28 * The "params" is a single object that can have the following properties:
Chris@909 29 *
Chris@909 30 * prop. name | description
Chris@909 31 * -------------------------------------------------------------------------------------------------
Chris@909 32 * inputField | the ID of an input field to store the date
Chris@909 33 * displayArea | the ID of a DIV or other element to show the date
Chris@909 34 * button | ID of a button or other element that will trigger the calendar
Chris@909 35 * eventName | event that will trigger the calendar, without the "on" prefix (default: "click")
Chris@909 36 * ifFormat | date format that will be stored in the input field
Chris@909 37 * daFormat | the date format that will be used to display the date in displayArea
Chris@909 38 * singleClick | (true/false) wether the calendar is in single click mode or not (default: true)
Chris@909 39 * firstDay | numeric: 0 to 6. "0" means display Sunday first, "1" means display Monday first, etc.
Chris@909 40 * align | alignment (default: "Br"); if you don't know what's this see the calendar documentation
Chris@909 41 * range | array with 2 elements. Default: [1900, 2999] -- the range of years available
Chris@909 42 * weekNumbers | (true/false) if it's true (default) the calendar will display week numbers
Chris@909 43 * flat | null or element ID; if not null the calendar will be a flat calendar having the parent with the given ID
Chris@909 44 * flatCallback | function that receives a JS Date object and returns an URL to point the browser to (for flat calendar)
Chris@909 45 * disableFunc | function that receives a JS Date object and should return true if that date has to be disabled in the calendar
Chris@909 46 * onSelect | function that gets called when a date is selected. You don't _have_ to supply this (the default is generally okay)
Chris@909 47 * onClose | function that gets called when the calendar is closed. [default]
Chris@909 48 * onUpdate | function that gets called after the date is updated in the input field. Receives a reference to the calendar.
Chris@909 49 * date | the date that the calendar will be initially displayed to
Chris@909 50 * showsTime | default: false; if true the calendar will include a time selector
Chris@909 51 * timeFormat | the time format; can be "12" or "24", default is "12"
Chris@909 52 * electric | if true (default) then given fields/date areas are updated for each move; otherwise they're updated only on close
Chris@909 53 * step | configures the step of the years in drop-down boxes; default: 2
Chris@909 54 * position | configures the calendar absolute position; default: null
Chris@909 55 * cache | if "true" (but default: "false") it will reuse the same calendar object, where possible
Chris@909 56 * showOthers | if "true" (but default: "false") it will show days from other months too
Chris@909 57 *
Chris@909 58 * None of them is required, they all have default values. However, if you
Chris@909 59 * pass none of "inputField", "displayArea" or "button" you'll get a warning
Chris@909 60 * saying "nothing to setup".
Chris@909 61 */
Chris@909 62 Calendar.setup = function (params) {
Chris@909 63 function param_default(pname, def) { if (typeof params[pname] == "undefined") { params[pname] = def; } };
Chris@909 64
Chris@909 65 param_default("inputField", null);
Chris@909 66 param_default("displayArea", null);
Chris@909 67 param_default("button", null);
Chris@909 68 param_default("eventName", "click");
Chris@909 69 param_default("ifFormat", "%Y/%m/%d");
Chris@909 70 param_default("daFormat", "%Y/%m/%d");
Chris@909 71 param_default("singleClick", true);
Chris@909 72 param_default("disableFunc", null);
Chris@909 73 param_default("dateStatusFunc", params["disableFunc"]); // takes precedence if both are defined
Chris@909 74 param_default("dateText", null);
Chris@909 75 param_default("firstDay", null);
Chris@909 76 param_default("align", "Br");
Chris@909 77 param_default("range", [1900, 2999]);
Chris@909 78 param_default("weekNumbers", true);
Chris@909 79 param_default("flat", null);
Chris@909 80 param_default("flatCallback", null);
Chris@909 81 param_default("onSelect", null);
Chris@909 82 param_default("onClose", null);
Chris@909 83 param_default("onUpdate", null);
Chris@909 84 param_default("date", null);
Chris@909 85 param_default("showsTime", false);
Chris@909 86 param_default("timeFormat", "24");
Chris@909 87 param_default("electric", true);
Chris@909 88 param_default("step", 2);
Chris@909 89 param_default("position", null);
Chris@909 90 param_default("cache", false);
Chris@909 91 param_default("showOthers", false);
Chris@909 92 param_default("multiple", null);
Chris@909 93
Chris@909 94 var tmp = ["inputField", "displayArea", "button"];
Chris@909 95 for (var i in tmp) {
Chris@909 96 if (typeof params[tmp[i]] == "string") {
Chris@909 97 params[tmp[i]] = document.getElementById(params[tmp[i]]);
Chris@909 98 }
Chris@909 99 }
Chris@909 100 if (!(params.flat || params.multiple || params.inputField || params.displayArea || params.button)) {
Chris@909 101 alert("Calendar.setup:\n Nothing to setup (no fields found). Please check your code");
Chris@909 102 return false;
Chris@909 103 }
Chris@909 104
Chris@909 105 function onSelect(cal) {
Chris@909 106 var p = cal.params;
Chris@909 107 var update = (cal.dateClicked || p.electric);
Chris@909 108 if (update && p.inputField) {
Chris@909 109 p.inputField.value = cal.date.print(p.ifFormat);
Chris@909 110 if (typeof p.inputField.onchange == "function")
Chris@909 111 p.inputField.onchange();
Chris@909 112 }
Chris@909 113 if (update && p.displayArea)
Chris@909 114 p.displayArea.innerHTML = cal.date.print(p.daFormat);
Chris@909 115 if (update && typeof p.onUpdate == "function")
Chris@909 116 p.onUpdate(cal);
Chris@909 117 if (update && p.flat) {
Chris@909 118 if (typeof p.flatCallback == "function")
Chris@909 119 p.flatCallback(cal);
Chris@909 120 }
Chris@909 121 if (update && p.singleClick && cal.dateClicked)
Chris@909 122 cal.callCloseHandler();
Chris@909 123 };
Chris@909 124
Chris@909 125 if (params.flat != null) {
Chris@909 126 if (typeof params.flat == "string")
Chris@909 127 params.flat = document.getElementById(params.flat);
Chris@909 128 if (!params.flat) {
Chris@909 129 alert("Calendar.setup:\n Flat specified but can't find parent.");
Chris@909 130 return false;
Chris@909 131 }
Chris@909 132 var cal = new Calendar(params.firstDay, params.date, params.onSelect || onSelect);
Chris@909 133 cal.showsOtherMonths = params.showOthers;
Chris@909 134 cal.showsTime = params.showsTime;
Chris@909 135 cal.time24 = (params.timeFormat == "24");
Chris@909 136 cal.params = params;
Chris@909 137 cal.weekNumbers = params.weekNumbers;
Chris@909 138 cal.setRange(params.range[0], params.range[1]);
Chris@909 139 cal.setDateStatusHandler(params.dateStatusFunc);
Chris@909 140 cal.getDateText = params.dateText;
Chris@909 141 if (params.ifFormat) {
Chris@909 142 cal.setDateFormat(params.ifFormat);
Chris@909 143 }
Chris@909 144 if (params.inputField && typeof params.inputField.value == "string") {
Chris@909 145 cal.parseDate(params.inputField.value);
Chris@909 146 }
Chris@909 147 cal.create(params.flat);
Chris@909 148 cal.show();
Chris@909 149 return false;
Chris@909 150 }
Chris@909 151
Chris@909 152 var triggerEl = params.button || params.displayArea || params.inputField;
Chris@909 153 triggerEl["on" + params.eventName] = function() {
Chris@909 154 var dateEl = params.inputField || params.displayArea;
Chris@909 155 var dateFmt = params.inputField ? params.ifFormat : params.daFormat;
Chris@909 156 var mustCreate = false;
Chris@909 157 var cal = window.calendar;
Chris@909 158 if (dateEl)
Chris@909 159 params.date = Date.parseDate(dateEl.value || dateEl.innerHTML, dateFmt);
Chris@909 160 if (!(cal && params.cache)) {
Chris@909 161 window.calendar = cal = new Calendar(params.firstDay,
Chris@909 162 params.date,
Chris@909 163 params.onSelect || onSelect,
Chris@909 164 params.onClose || function(cal) { cal.hide(); });
Chris@909 165 cal.showsTime = params.showsTime;
Chris@909 166 cal.time24 = (params.timeFormat == "24");
Chris@909 167 cal.weekNumbers = params.weekNumbers;
Chris@909 168 mustCreate = true;
Chris@909 169 } else {
Chris@909 170 if (params.date)
Chris@909 171 cal.setDate(params.date);
Chris@909 172 cal.hide();
Chris@909 173 }
Chris@909 174 if (params.multiple) {
Chris@909 175 cal.multiple = {};
Chris@909 176 for (var i = params.multiple.length; --i >= 0;) {
Chris@909 177 var d = params.multiple[i];
Chris@909 178 var ds = d.print("%Y%m%d");
Chris@909 179 cal.multiple[ds] = d;
Chris@909 180 }
Chris@909 181 }
Chris@909 182 cal.showsOtherMonths = params.showOthers;
Chris@909 183 cal.yearStep = params.step;
Chris@909 184 cal.setRange(params.range[0], params.range[1]);
Chris@909 185 cal.params = params;
Chris@909 186 cal.setDateStatusHandler(params.dateStatusFunc);
Chris@909 187 cal.getDateText = params.dateText;
Chris@909 188 cal.setDateFormat(dateFmt);
Chris@909 189 if (mustCreate)
Chris@909 190 cal.create();
Chris@909 191 cal.refresh();
Chris@909 192 if (!params.position)
Chris@909 193 cal.showAtElement(params.button || params.displayArea || params.inputField);
Chris@909 194 else
Chris@909 195 cal.showAt(params.position[0], params.position[1]);
Chris@909 196 return false;
Chris@909 197 };
Chris@909 198
Chris@909 199 return cal;
Chris@909 200 };