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