Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2014-10-14-11-24-52
[civicrm-core.git] / templates / CRM / common / jcalendar.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2014 |
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 {if $batchUpdate}
27 {assign var='elementId' value=$form.field.$elementIndex.$elementName.id}
28 {assign var="tElement" value=$elementName|cat:"_time"}
29 {assign var="timeElement" value=field_`$elementIndex`_`$elementName`_time}
30 {$form.field.$elementIndex.$elementName.html}
31 {elseif $elementIndex}
32 {assign var='elementId' value=$form.$elementName.$elementIndex.id}
33 {assign var="timeElement" value=$elementName|cat:"_time.$elementIndex"}
34 {$form.$elementName.$elementIndex.html}
35 {elseif $blockId and $blockSection}
36 {assign var='elementId' value=$form.$blockSection.$blockId.$elementName.id}
37 {assign var="tElement" value=`$elementName`_time}
38 {$form.$blockSection.$blockId.$elementName.html}
39 {assign var="timeElement" value=`$blockSection`_`$blockId`_`$elementName`_time}
40 {if $tElement}
41   {$form.$blockSection.$blockId.$tElement.label}
42   {$form.$blockSection.$blockId.$tElement.html|crmAddClass:six}
43 {/if}
44 {else}
45 {if !$elementId}
46 {assign var='elementId' value=$form.$elementName.id}
47 {/if}
48 {assign var="timeElement" value=$elementName|cat:'_time'}
49 {$form.$elementName.html}
50 {/if}
51
52 {assign var='displayDate' value=$elementId|cat:"_display"}
53
54 {if $action neq 1028}
55 <input type="text" name="{$displayDate}" id="{$displayDate}" class="dateplugin" autocomplete="off"/>
56 {/if}
57
58 {if $batchUpdate AND $timeElement AND $tElement}
59 &nbsp;&nbsp;{$form.field.$elementIndex.$tElement.label}&nbsp;&nbsp;{$form.field.$elementIndex.$tElement.html|crmAddClass:six}
60 {elseif $timeElement AND !$tElement}
61 {if $form.$timeElement.label}
62 &nbsp;&nbsp;{$form.$timeElement.label}&nbsp;&nbsp;
63 {/if}
64 {$form.$timeElement.html|crmAddClass:six}
65 {/if}
66
67 {if $action neq 1028}
68 <a href="#" class="crm-hover-button crm-clear-link" title="{ts}Clear{/ts}"><span class="icon close-icon"></span></a>
69 {/if}
70
71 <script type="text/javascript">
72 {literal}
73 CRM.$(function($) {
74 {/literal}
75 // Workaround for possible duplicate ids in the dom - select by name instead of id and exclude already initialized widgets
76 var $dateElement = $('input[name={$displayDate}].dateplugin:not(.hasDatepicker)');
77 {if $timeElement}
78 var $timeElement = $dateElement.siblings("#{$timeElement}");
79 var time_format = $timeElement.attr('timeFormat');
80 {literal}
81 $timeElement.timeEntry({ show24Hours : time_format, spinnerImage: '' });
82 {/literal}
83 {else}
84 var $timeElement = $();
85 {/if}
86 var currentYear = new Date().getFullYear(),
87 $originalElement = $dateElement.siblings('#{$elementId}').hide(),
88 date_format = $originalElement.attr('format'),
89 altDateFormat = 'mm/dd/yy';
90 {literal}
91
92 if ( !( ( date_format == 'M yy' ) || ( date_format == 'yy' ) || ( date_format == 'yy-mm' ) ) ) {
93 $dateElement.addClass( 'dpDate' );
94 }
95
96 var yearRange = (currentYear - parseInt($originalElement.attr('startOffset'))) +
97 ':' + currentYear + parseInt($originalElement.attr('endOffset')),
98 startRangeYr = currentYear - parseInt($originalElement.attr('startOffset')),
99 endRangeYr = currentYear + parseInt($originalElement.attr('endOffset'));
100
101 $dateElement.datepicker({
102 closeAtTop: true,
103 dateFormat: date_format,
104 changeMonth: (date_format.indexOf('m') > -1),
105 changeYear: (date_format.indexOf('y') > -1),
106 altField: $originalElement,
107 altFormat: altDateFormat,
108 yearRange: yearRange,
109 minDate: new Date(startRangeYr, 1 - 1, 1),
110 maxDate: new Date(endRangeYr, 12 - 1, 31)
111 });
112
113 // format display date
114 var displayDateValue = $.datepicker.formatDate(date_format, $.datepicker.parseDate(altDateFormat, $originalElement.val()));
115 //support unsaved-changes warning: CRM-14353
116 $dateElement.val(displayDateValue).data('crm-initial-value', displayDateValue);
117
118 // Add clear button
119 $($timeElement).add($originalElement).add($dateElement).on('blur change', function() {
120 var vis = $dateElement.val() || $timeElement.val() ? '' : 'hidden';
121 $dateElement.siblings('.crm-clear-link').css('visibility', vis);
122 });
123 $originalElement.change();
124 });
125
126 {/literal}
127 </script>
128