3 Modification information for LGPL compliance
5 r56990 - 2010-06-16 13:05:36 -0700 (Wed, 16 Jun 2010) - kjing - snapshot "Mango" svn branch to a new one for GitHub sync
7 r56989 - 2010-06-16 13:01:33 -0700 (Wed, 16 Jun 2010) - kjing - defunt "Mango" svn dev branch before github cutover
9 r55980 - 2010-04-19 13:31:28 -0700 (Mon, 19 Apr 2010) - kjing - create Mango (6.1) based on windex
11 r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3 tags and updated the build system
13 r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development
15 r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372
17 r42807 - 2008-12-29 11:16:59 -0800 (Mon, 29 Dec 2008) - dwong - Branch from trunk/sugarcrm r42806 to branches/tokyo/sugarcrm
19 r27708 - 2007-10-05 15:45:31 -0700 (Fri, 05 Oct 2007) - julian - Fix for bug #13416: jscalendar does not honor 'First Day of Week' value in I18N files (CONTRIBUTED CODE)
21 r25053 - 2007-08-03 09:24:58 -0700 (Fri, 03 Aug 2007) - clee - Fix to accomodate for ifFormat parameter that is used by modules when calling Calendar.setup code in Javascript.
23 r24533 - 2007-07-23 01:35:36 -0700 (Mon, 23 Jul 2007) - clee - Added fixes for IE javascript errors where calendar selection causes other form fields to be disabled/readonly.
28 /* Copyright Mihai Bazon, 2002, 2003 | http://dynarch.com/mishoo/
29 * ---------------------------------------------------------------------------
33 * Details and latest version at:
34 * http://dynarch.com/mishoo/calendar.epl
36 * This script is distributed under the GNU Lesser General Public License.
37 * Read the entire license text here: http://www.gnu.org/licenses/lgpl.html
39 * This file defines helper functions for setting up the calendar. They are
40 * intended to help non-programmers get a working calendar on their site
41 * quickly. This script should not be seen as part of the calendar. It just
42 * shows you what one can do with the calendar, while in the same time
43 * providing a quick and simple method for setting it up. If you need
44 * exhaustive customization of the calendar creation process feel free to
45 * modify this code to suit your needs (this is recommended and much better
46 * than modifying calendar.js itself).
52 * This function "patches" an input field (or other element) to use a calendar
53 * widget for date selection.
55 * The "params" is a single object that can have the following properties:
57 * prop. name | description
58 * -------------------------------------------------------------------------------------------------
59 * inputField | the ID of an input field to store the date
60 * displayArea | the ID of a DIV or other element to show the date
61 * button | ID of a button or other element that will trigger the calendar
62 * eventName | event that will trigger the calendar, without the "on" prefix (default: "click")
63 * ifFormat | date format that will be stored in the input field
64 * daFormat | the date format that will be used to display the date in displayArea
65 * singleClick | (true/false) wether the calendar is in single click mode or not (default: true)
66 * firstDay | numeric: 0 to 6. "0" means display Sunday first, "1" means display Monday first, etc.
67 * align | alignment (default: "Br"); if you don't know what's this see the calendar documentation
68 * range | array with 2 elements. Default: [1900, 2999] -- the range of years available
69 * weekNumbers | (true/false) if it's true (default) the calendar will display week numbers
70 * flat | null or element ID; if not null the calendar will be a flat calendar having the parent with the given ID
71 * flatCallback | function that receives a JS Date object and returns an URL to point the browser to (for flat calendar)
72 * disableFunc | function that receives a JS Date object and should return true if that date has to be disabled in the calendar
73 * onSelect | function that gets called when a date is selected. You don't _have_ to supply this (the default is generally okay)
74 * onClose | function that gets called when the calendar is closed. [default]
75 * onUpdate | function that gets called after the date is updated in the input field. Receives a reference to the calendar.
76 * date | the date that the calendar will be initially displayed to
77 * showsTime | default: false; if true the calendar will include a time selector
78 * timeFormat | the time format; can be "12" or "24", default is "12"
79 * electric | if true (default) then given fields/date areas are updated for each move; otherwise they're updated only on close
80 * step | configures the step of the years in drop-down boxes; default: 2
81 * position | configures the calendar absolute position; default: null
82 * cache | if "true" (but default: "false") it will reuse the same calendar object, where possible
83 * showOthers | if "true" (but default: "false") it will show days from other months too
85 * None of them is required, they all have default values. However, if you
86 * pass none of "inputField", "displayArea" or "button" you'll get a warning
87 * saying "nothing to setup".
90 Calendar.setup = function (params) {
91 function param_default(pname, def) { if (typeof params[pname] == "undefined") { params[pname] = def; } };
94 param_default("inputFieldObj", null);
95 param_default("displayAreaObj", null);
96 param_default("buttonObj", null);
98 param_default("inputField", null);
99 param_default("displayArea", null);
100 param_default("button", null);
101 param_default("eventName", "click");
102 param_default("ifFormat", "%Y/%m/%d");
103 param_default("daFormat", "%Y/%m/%d");
104 param_default("singleClick", true);
105 param_default("disableFunc", null);
106 param_default("dateStatusFunc", params["disableFunc"]); // takes precedence if both are defined
107 param_default("firstDay", isNaN(Calendar._FD)? 0 : Calendar._FD); // defaults to "Sunday" first. Uses Calendar._FD as default value.
108 param_default("align", "Br");
109 param_default("range", [1900, 2999]);
110 param_default("weekNumbers", true);
111 param_default("flat", null);
112 param_default("flatCallback", null);
113 param_default("onSelect", null);
114 param_default("onClose", null);
115 param_default("onOpen", null);
116 param_default("onUpdate", null);
117 param_default("date", null);
118 param_default("showsTime", false);
119 param_default("timeFormat", "24");
120 param_default("electric", true);
121 param_default("step", 2);
122 param_default("position", null);
123 param_default("cache", false);
124 param_default("showOthers", false);
126 var tmp = ["inputField", "displayArea", "button"];
130 if ( params[tmp[i]+'Obj'] == null
131 && typeof params[tmp[i]] == "string")
133 params[tmp[i]] = document.getElementById(params[tmp[i]]);
137 params[tmp[i]] = params[tmp[i]+'Obj'];
141 if (!(params.flat || params.inputField || params.displayArea || params.button)) {
142 // alert("Calendar.setup:\n Nothing to setup (no fields found). Please check your code");
146 function onSelect(cal) {
149 var update = (cal.dateClicked || p.electric);
150 if (update && p.flat) {
151 if (typeof p.flatCallback == "function")
154 alert("No flatCallback given -- doing nothing.");
157 if (update && p.inputField) {
158 //p.inputField.value = cal.date.print(p.ifFormat);
159 val = cal.date.print(p.daFormat);
160 val = val.substring(0,10);
161 p.inputField.value = val;
163 if (typeof p.inputField.onchange == "function")
164 p.inputField.onchange();
166 if (update && p.displayArea)
167 p.displayArea.innerHTML = cal.date.print(p.daFormat);
168 if (update && p.singleClick && cal.dateClicked)
169 cal.callCloseHandler();
170 if (update && typeof p.onUpdate == "function")
173 if (params.flat != null) {
175 if (typeof params.flat == "string")
176 params.flat = document.getElementById(params.flat);
178 alert("Calendar.setup:\n Flat specified but can't find parent.");
181 var cal = new Calendar(params.firstDay, params.date, params.onSelect || onSelect);
182 cal.showsTime = params.showsTime;
183 cal.time24 = (params.timeFormat == "24");
185 cal.weekNumbers = params.weekNumbers;
186 cal.setRange(params.range[0], params.range[1]);
187 cal.setDateStatusHandler(params.dateStatusFunc);
188 cal.create(params.flat);
193 var triggerEl = params.button || params.displayArea || params.inputField;
194 triggerEl["on" + params.eventName] = function() {
198 var dateEl = params.inputField || params.displayArea;
199 var dateFmt = ((typeof params.ifFormat != "undefined") && params.ifFormat != "%Y/%m/%d") ? params.ifFormat : params.daFormat;
200 params.daFormat = dateFmt;
202 if(dateFmt.indexOf(" ") > -1) {
203 dateFmt = dateFmt.substring(0, dateFmt.indexOf(" "));
206 var mustCreate = false;
207 var cal = window.calendar;
208 if (!(cal && params.cache)) {
209 window.calendar = cal = new Calendar(params.firstDay,
211 params.onSelect || onSelect,
212 params.onClose || function(cal) { cal.hide(); },
214 cal.showsTime = params.showsTime;
215 cal.time24 = (params.timeFormat == "24");
216 cal.weekNumbers = params.weekNumbers;
220 cal.setDate(params.date);
223 cal.showsOtherMonths = params.showOthers;
224 cal.yearStep = params.step;
225 cal.setRange(params.range[0], params.range[1]);
227 cal.setDateStatusHandler(params.dateStatusFunc);
228 cal.setDateFormat(dateFmt);
231 cal.parseDate(dateEl.value || dateEl.innerHTML);
233 if (!params.position)
234 cal.showAtElement(params.button || params.displayArea || params.inputField, params.align);
236 cal.showAt(params.position[0], params.position[1]);