1 /*********************************************************************************
2 * SugarCRM is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Affero General Public License version 3 as published by the
7 * Free Software Foundation with the addition of the following permission added
8 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * You should have received a copy of the GNU Affero General Public License along with
18 * this program; if not, see http://www.gnu.org/licenses or write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU Affero General Public License version 3.
29 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30 * these Appropriate Legal Notices must retain the display of the "Powered by
31 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32 * technical reasons, the Appropriate Legal Notices must display the words
33 * "Powered by SugarCRM".
34 ********************************************************************************/
37 Calendar = function() {};
39 Calendar.setup = function (params) {
41 YAHOO.util.Event.onDOMReady(function(){
43 var Event = YAHOO.util.Event;
44 var Dom = YAHOO.util.Dom;
47 var showButton = params.button ? params.button : params.buttonObj;
48 var userDateFormat = params.ifFormat ? params.ifFormat : (params.daFormat ? params.daFormat : "m/d/Y");
49 var inputField = params.inputField ? params.inputField : params.inputFieldObj;
50 var dateFormat = userDateFormat.substr(0,10);
51 var date_field_delimiter = /([-.\\/])/.exec(dateFormat)[0];
52 dateFormat = dateFormat.replace(/[^a-zA-Z]/g,'');
54 var monthPos = dateFormat.search(/m/);
55 var dayPos = dateFormat.search(/d/);
56 var yearPos = dateFormat.search(/Y/);
58 Event.on(Dom.get(showButton), "click", function() {
62 dialog = new YAHOO.widget.SimpleDialog("container_" + showButton, {
64 context:[showButton, "tl", "bl"],
71 dialog.setHeader(SUGAR.language.get('app_strings', 'LBL_MASSUPDATE_DATE'));
72 dialog.setBody('<div id="' + showButton + '_div"></div>');
73 dialog.render(document.body);
75 dialog.showEvent.subscribe(function() {
76 if (YAHOO.env.ua.ie) {
77 // Since we're hiding the table using yui-overlay-hidden, we
78 // want to let the dialog know that the content size has changed, when
80 dialog.fireEvent("changeContent");
84 // Hide Calendar if we click anywhere in the document other than the calendar
85 Event.on(document, "click", function(e) {
92 var el = Event.getTarget(e);
93 var dialogEl = dialog.element;
94 if (el != dialogEl && !Dom.isAncestor(dialogEl, el) && el != Dom.get(showButton) && !Dom.isAncestor(Dom.get(showButton), el)) {
102 // Lazy Calendar Creation - Wait to create the Calendar until the first time the button is clicked.
107 month: SUGAR.language.get('app_strings', 'LBL_CHOOSE_MONTH'),
108 year: SUGAR.language.get('app_strings', 'LBL_ENTER_YEAR'),
109 submit: SUGAR.language.get('app_strings', 'LBL_EMAIL_OK'),
110 cancel: SUGAR.language.get('app_strings', 'LBL_CANCEL_BUTTON_LABEL'),
111 invalidYear: SUGAR.language.get('app_strings', 'LBL_ENTER_VALID_YEAR')
113 monthFormat: YAHOO.widget.Calendar.SHORT,
117 calendar = new YAHOO.widget.Calendar(showButton + '_div', {
119 hide_blank_weeks:true,
123 calendar.cfg.setProperty('DATE_FIELD_DELIMITER', date_field_delimiter);
124 calendar.cfg.setProperty('MDY_DAY_POSITION', dayPos+1);
125 calendar.cfg.setProperty('MDY_MONTH_POSITION', monthPos+1);
126 calendar.cfg.setProperty('MDY_YEAR_POSITION', yearPos+1);
128 //Configure the month and days label with localization support where defined
129 if(typeof SUGAR.language.languages['app_list_strings'] != 'undefined' && SUGAR.language.languages['app_list_strings']['dom_cal_month_long'] != 'undefined')
131 if(SUGAR.language.languages['app_list_strings']['dom_cal_month_long'].length == 13)
133 SUGAR.language.languages['app_list_strings']['dom_cal_month_long'].shift();
135 calendar.cfg.setProperty('MONTHS_LONG', SUGAR.language.languages['app_list_strings']['dom_cal_month_long']);
138 if(typeof SUGAR.language.languages['app_list_strings'] != 'undefined' && typeof SUGAR.language.languages['app_list_strings']['dom_cal_day_short'] != 'undefined')
140 if(SUGAR.language.languages['app_list_strings']['dom_cal_day_short'].length == 8)
142 SUGAR.language.languages['app_list_strings']['dom_cal_day_short'].shift();
144 calendar.cfg.setProperty('WEEKDAYS_SHORT', SUGAR.language.languages['app_list_strings']['dom_cal_day_short']);
147 calendar.selectEvent.subscribe(function() {
148 var input = Dom.get(inputField);
149 if (calendar.getSelectedDates().length > 0) {
151 var selDate = calendar.getSelectedDates()[0];
152 var monthVal = selDate.getMonth() + 1; //Add one for month value
155 monthVal = '0' + monthVal;
158 var dateVal = selDate.getDate();
162 dateVal = '0' + dateVal;
165 var yearVal = selDate.getFullYear();
170 } else if(dayPos == 0) {
177 selDate += date_field_delimiter + monthVal;
178 } else if(dayPos == 1) {
179 selDate += date_field_delimiter + dateVal;
181 selDate += date_field_delimiter + yearVal;
185 selDate += date_field_delimiter + monthVal;
186 } else if(dayPos == 2) {
187 selDate += date_field_delimiter + dateVal;
189 selDate += date_field_delimiter + yearVal;
192 input.value = selDate;
194 if(params.comboObject)
196 params.comboObject.update();
203 //Fire any on-change events for this input field
204 SUGAR.util.callOnChangeListers(input);
207 calendar.renderEvent.subscribe(function() {
208 // Tell Dialog it's contents have changed, which allows
209 // container to redraw the underlay (for IE6/Safari2)
210 dialog.fireEvent("changeContent");
215 var seldate = calendar.getSelectedDates();
216 if (Dom.get(inputField).value.length > 0) {
217 val = new Date(Dom.get(inputField).value);
218 if(!isNaN(val.getTime()))
220 calendar.cfg.setProperty("selected", Dom.get(inputField).value);
221 seldate = Dom.get(inputField).value.split(date_field_delimiter);
222 calendar.cfg.setProperty("pagedate", seldate[monthPos] + calendar.cfg.getProperty("DATE_FIELD_DELIMITER") + seldate[yearPos]);
224 } else if (seldate.length > 0) {
225 // Set the pagedate to show the selected date if it exists
226 calendar.cfg.setProperty("selected", seldate[0]);
227 var month = seldate[0].getMonth() + 1;
228 var year = seldate[0].getFullYear();
229 calendar.cfg.setProperty("pagedate", month + calendar.cfg.getProperty("DATE_FIELD_DELIMITER") + year);