Merge pull request #2021 from dlobo/CRM-13792
[civicrm-core.git] / templates / CRM / common / jcalendar.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
8 | |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
12 | |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 *}
26 {strip}
27 {if $batchUpdate}
28 {assign var='elementId' value=$form.field.$elementIndex.$elementName.id}
29 {assign var="tElement" value=$elementName|cat:"_time"}
30 {assign var="timeElement" value=field_`$elementIndex`_`$elementName`_time}
31 {$form.field.$elementIndex.$elementName.html}
32 {elseif $elementIndex}
33 {assign var='elementId' value=$form.$elementName.$elementIndex.id}
34 {assign var="timeElement" value=$elementName|cat:"_time.$elementIndex"}
35 {$form.$elementName.$elementIndex.html}
36 {elseif $blockId and $blockSection}
37 {assign var='elementId' value=$form.$blockSection.$blockId.$elementName.id}
38 {assign var="tElement" value=`$elementName`_time}
39 {$form.$blockSection.$blockId.$elementName.html}
40 {assign var="timeElement" value=`$blockSection`_`$blockId`_`$elementName`_time}
41 {if $tElement}
42   {$form.$blockSection.$blockId.$tElement.label}
43   {$form.$blockSection.$blockId.$tElement.html|crmAddClass:six}
44 {/if}
45 {else}
46 {assign var='elementId' value=$form.$elementName.id}
47 {assign var="timeElement" value=$elementName|cat:'_time'}
48 {$form.$elementName.html}
49 {/if}
50
51 {assign var='displayDate' value=$elementId|cat:"_display"}
52
53 {if $action neq 1028}
54 <input type="text" name="{$displayDate}" id="{$displayDate}" class="dateplugin" autocomplete="off"/>
55 {/if}
56
57 {if $batchUpdate AND $timeElement AND $tElement}
58 &nbsp;&nbsp;{$form.field.$elementIndex.$tElement.label}&nbsp;&nbsp;{$form.field.$elementIndex.$tElement.html|crmAddClass:six}
59 {elseif $timeElement AND !$tElement}
60 {if $form.$timeElement.label}
61 &nbsp;&nbsp;{$form.$timeElement.label}&nbsp;&nbsp;
62 {/if}
63 {$form.$timeElement.html|crmAddClass:six}
64 {/if}
65
66 {if $action neq 1028}
67 <span class="crm-clear-link">(<a href="#" onclick="clearDateTime( '{$elementId}' ); return false;">{ts}clear{/ts}</a>)</span>
68 {/if}
69
70 <script type="text/javascript">
71 {literal}
72 cj( function() {
73 {/literal}
74 var element_date = "#{$displayDate}";
75 {if $timeElement}
76 var element_time = "#{$timeElement}";
77 var time_format = cj( element_time ).attr('timeFormat');
78 {literal}
79 cj(element_time).timeEntry({ show24Hours : time_format, spinnerImage: '' });
80 {/literal}
81 {/if}
82 var currentYear = new Date().getFullYear();
83 var alt_field = '#{$elementId}';
84 cj( alt_field ).hide();
85 var date_format = cj( alt_field ).attr('format');
86
87 var altDateFormat = 'mm/dd/yy';
88 {literal}
89 switch ( date_format ) {
90 case 'dd-mm':
91 case 'mm/dd':
92 altDateFormat = 'mm/dd';
93 break;
94 }
95
96 if ( !( ( date_format == 'M yy' ) || ( date_format == 'yy' ) || ( date_format == 'yy-mm' ) ) ) {
97 cj( element_date ).addClass( 'dpDate' );
98 }
99
100 {/literal}
101 var yearRange = currentYear - parseInt( cj( alt_field ).attr('startOffset') );
102 yearRange += ':';
103 yearRange += currentYear + parseInt( cj( alt_field ).attr('endOffset' ) );
104 {literal}
105
106 var startRangeYr = currentYear - parseInt( cj( alt_field ).attr('startOffset') );
107 var endRangeYr = currentYear + parseInt( cj( alt_field ).attr('endOffset' ) );
108
109 var lcMessage = {/literal}"{$config->lcMessages}"{literal};
110 var localisation = lcMessage.split('_');
111 var dateValue = cj(alt_field).val( );
112 cj(element_date).datepicker({
113 closeAtTop : true,
114 dateFormat : date_format,
115 changeMonth : true,
116 changeYear : true,
117 altField : alt_field,
118 altFormat : altDateFormat,
119 yearRange : yearRange,
120 regional : localisation[0],
121 minDate : new Date(startRangeYr, 1 - 1, 1),
122 maxDate : new Date(endRangeYr, 12 - 1, 31)
123 });
124
125 // set default value to display field, setDefault param for datepicker
126 // is not working hence using below logic
127 // parse the date
128 var displayDateValue = cj.datepicker.parseDate( altDateFormat, dateValue );
129
130 // format date according to display field
131 displayDateValue = cj.datepicker.formatDate( date_format, displayDateValue );
132 cj( element_date).val( displayDateValue );
133
134 cj(element_date).click( function( ) {
135 hideYear( this );
136 });
137 cj('.ui-datepicker-trigger').click( function( ) {
138 hideYear( cj(this).prev() );
139 });
140 });
141
142 function hideYear( element ) {
143 var format = cj( element ).attr('format');
144 if ( format == 'dd-mm' || format == 'mm/dd' ) {
145 cj(".ui-datepicker-year").css( 'display', 'none' );
146 }
147 }
148
149 function clearDateTime( element ) {
150 cj('input#' + element + ',input#' + element + '_time' + ',input#' + element + '_display').val('');
151 }
152 {/literal}
153 </script>
154 {/strip}