Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
819d0d41 | 3 | | CiviCRM version 4.5 | |
6a488035 | 4 | +--------------------------------------------------------------------+ |
819d0d41 | 5 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | {$form.field.$elementIndex.$tElement.label} {$form.field.$elementIndex.$tElement.html|crmAddClass:six} | |
59 | {elseif $timeElement AND !$tElement} | |
60 | {if $form.$timeElement.label} | |
61 | {$form.$timeElement.label} | |
62 | {/if} | |
63 | {$form.$timeElement.html|crmAddClass:six} | |
64 | {/if} | |
65 | ||
66 | {if $action neq 1028} | |
bcb4280c | 67 | <a href="#" class="crm-hover-button crm-clear-link" title="{ts}Clear{/ts}"><span class="icon close-icon"></span></a> |
6a488035 TO |
68 | {/if} |
69 | ||
70 | <script type="text/javascript"> | |
71 | {literal} | |
3cc60a06 | 72 | CRM.$(function($) { |
6a488035 TO |
73 | {/literal} |
74 | var element_date = "#{$displayDate}"; | |
bcb4280c | 75 | var element_time = "#{$elementId}_time"; |
6a488035 | 76 | {if $timeElement} |
bcb4280c | 77 | element_time = "#{$timeElement}"; |
6a488035 TO |
78 | var time_format = cj( element_time ).attr('timeFormat'); |
79 | {literal} | |
80 | cj(element_time).timeEntry({ show24Hours : time_format, spinnerImage: '' }); | |
81 | {/literal} | |
82 | {/if} | |
83 | var currentYear = new Date().getFullYear(); | |
84 | var alt_field = '#{$elementId}'; | |
85 | cj( alt_field ).hide(); | |
86 | var date_format = cj( alt_field ).attr('format'); | |
87 | ||
88 | var altDateFormat = 'mm/dd/yy'; | |
89 | {literal} | |
90 | switch ( date_format ) { | |
91 | case 'dd-mm': | |
92 | case 'mm/dd': | |
93 | altDateFormat = 'mm/dd'; | |
94 | break; | |
95 | } | |
96 | ||
97 | if ( !( ( date_format == 'M yy' ) || ( date_format == 'yy' ) || ( date_format == 'yy-mm' ) ) ) { | |
98 | cj( element_date ).addClass( 'dpDate' ); | |
99 | } | |
100 | ||
101 | {/literal} | |
102 | var yearRange = currentYear - parseInt( cj( alt_field ).attr('startOffset') ); | |
103 | yearRange += ':'; | |
104 | yearRange += currentYear + parseInt( cj( alt_field ).attr('endOffset' ) ); | |
105 | {literal} | |
106 | ||
0e9d07d2 BS |
107 | var startRangeYr = currentYear - parseInt( cj( alt_field ).attr('startOffset') ); |
108 | var endRangeYr = currentYear + parseInt( cj( alt_field ).attr('endOffset' ) ); | |
109 | ||
6a488035 TO |
110 | var lcMessage = {/literal}"{$config->lcMessages}"{literal}; |
111 | var localisation = lcMessage.split('_'); | |
112 | var dateValue = cj(alt_field).val( ); | |
113 | cj(element_date).datepicker({ | |
114 | closeAtTop : true, | |
115 | dateFormat : date_format, | |
116 | changeMonth : true, | |
117 | changeYear : true, | |
118 | altField : alt_field, | |
119 | altFormat : altDateFormat, | |
120 | yearRange : yearRange, | |
0e9d07d2 BS |
121 | regional : localisation[0], |
122 | minDate : new Date(startRangeYr, 1 - 1, 1), | |
123 | maxDate : new Date(endRangeYr, 12 - 1, 31) | |
6a488035 TO |
124 | }); |
125 | ||
126 | // set default value to display field, setDefault param for datepicker | |
127 | // is not working hence using below logic | |
128 | // parse the date | |
129 | var displayDateValue = cj.datepicker.parseDate( altDateFormat, dateValue ); | |
130 | ||
131 | // format date according to display field | |
132 | displayDateValue = cj.datepicker.formatDate( date_format, displayDateValue ); | |
133 | cj( element_date).val( displayDateValue ); | |
68d6459e | 134 | //support unsaved-changes warning: CRM-14353 |
135 | cj( element_date).data('crm-initial-value', displayDateValue); | |
6a488035 TO |
136 | |
137 | cj(element_date).click( function( ) { | |
138 | hideYear( this ); | |
139 | }); | |
140 | cj('.ui-datepicker-trigger').click( function( ) { | |
141 | hideYear( cj(this).prev() ); | |
142 | }); | |
bcb4280c | 143 | function hideYear( element ) { |
6a488035 TO |
144 | var format = cj( element ).attr('format'); |
145 | if ( format == 'dd-mm' || format == 'mm/dd' ) { | |
bcb4280c | 146 | cj(".ui-datepicker-year").css('display', 'none'); |
6a488035 | 147 | } |
bcb4280c CW |
148 | } |
149 | cj(alt_field + ',' + element_date + ',' + element_time).on('blur change', function() { | |
150 | var vis = cj(alt_field).val() || cj(element_time).val() ? '' : 'hidden'; | |
151 | cj(this).siblings('.crm-clear-link').css('visibility', vis); | |
152 | }); | |
153 | cj(alt_field).change(); | |
154 | }); | |
6a488035 | 155 | |
6a488035 TO |
156 | {/literal} |
157 | </script> | |
158 | {/strip} |