Merge pull request #5898 from monishdeb/master
[civicrm-core.git] / templates / CRM / common / jcalendar.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.6 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2015 |
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 {* CRM-15804 - CiviEvent Date Picker broken in modal dialog *}
53 {assign var='displayDate' value=$elementId|cat:"_display"|cat:"_$string"|uniqid}
54
55 {if $action neq 1028}
56 <input type="text" name="{$displayDate}" id="{$displayDate}" class="dateplugin" autocomplete="off"/>
57 {/if}
58
59 {if $batchUpdate AND $timeElement AND $tElement}
60 &nbsp;&nbsp;{$form.field.$elementIndex.$tElement.label}&nbsp;&nbsp;{$form.field.$elementIndex.$tElement.html|crmAddClass:six}
61 {elseif $timeElement AND !$tElement}
62 {if $form.$timeElement.label}
63 &nbsp;&nbsp;{$form.$timeElement.label}&nbsp;&nbsp;
64 {/if}
65 {$form.$timeElement.html|crmAddClass:six}
66 {/if}
67
68 {if $action neq 1028}
69 <a href="#" class="crm-hover-button crm-clear-link" title="{ts}Clear{/ts}"><span class="icon ui-icon-close"></span></a>
70 {/if}
71
72 <script type="text/javascript">
73 {literal}
74 CRM.$(function($) {
75 {/literal}
76 // Workaround for possible duplicate ids in the dom - select by name instead of id and exclude already initialized widgets
77 var $dateElement = $('input[name={$displayDate}].dateplugin:not(.hasDatepicker)');
78 {literal}
79 if (!$dateElement.length) {
80 return;
81 }
82 {/literal}
83 {if $timeElement}
84 var $timeElement = $dateElement.siblings("#{$timeElement}");
85 var time_format = $timeElement.attr('timeFormat');
86 {literal}
87 $timeElement.timeEntry({ show24Hours : time_format, spinnerImage: '' });
88 {/literal}
89 {else}
90 var $timeElement = $();
91 {/if}
92 var currentYear = new Date().getFullYear(),
93 $originalElement = $dateElement.siblings('#{$elementId}').hide(),
94 date_format = $originalElement.attr('format'),
95 altDateFormat = 'mm/dd/yy';
96 {literal}
97
98 if ( !( ( date_format == 'M yy' ) || ( date_format == 'yy' ) || ( date_format == 'yy-mm' ) ) ) {
99 $dateElement.addClass( 'dpDate' );
100 }
101
102 var yearRange = (currentYear - parseInt($originalElement.attr('startOffset'))) +
103 ':' + currentYear + parseInt($originalElement.attr('endOffset')),
104 startRangeYr = currentYear - parseInt($originalElement.attr('startOffset')),
105 endRangeYr = currentYear + parseInt($originalElement.attr('endOffset'));
106
107 $dateElement.datepicker({
108 closeAtTop: true,
109 dateFormat: date_format,
110 changeMonth: (date_format.indexOf('m') > -1),
111 changeYear: (date_format.indexOf('y') > -1),
112 altField: $originalElement,
113 altFormat: altDateFormat,
114 yearRange: yearRange,
115 minDate: new Date(startRangeYr, 1 - 1, 1),
116 maxDate: new Date(endRangeYr, 12 - 1, 31)
117 });
118
119 // format display date
120 var displayDateValue = $.datepicker.formatDate(date_format, $.datepicker.parseDate(altDateFormat, $originalElement.val()));
121 //support unsaved-changes warning: CRM-14353
122 $dateElement.val(displayDateValue).data('crm-initial-value', displayDateValue);
123
124 // Add clear button
125 $($timeElement).add($originalElement).add($dateElement).on('blur change', function() {
126 var vis = $dateElement.val() || $timeElement.val() ? '' : 'hidden';
127 $dateElement.siblings('.crm-clear-link').css('visibility', vis);
128 });
129 $originalElement.change();
130 });
131
132 {/literal}
133 </script>
134