| 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 | {$form.field.$elementIndex.$tElement.label} {$form.field.$elementIndex.$tElement.html|crmAddClass:six} |
| 60 | {elseif $timeElement AND !$tElement} |
| 61 | {if $form.$timeElement.label} |
| 62 | {$form.$timeElement.label} |
| 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 | {literal} |
| 78 | if (!$dateElement.length) { |
| 79 | return; |
| 80 | } |
| 81 | {/literal} |
| 82 | {if $timeElement} |
| 83 | var $timeElement = $dateElement.siblings("#{$timeElement}"); |
| 84 | var time_format = $timeElement.attr('timeFormat'); |
| 85 | {literal} |
| 86 | $timeElement.timeEntry({ show24Hours : time_format, spinnerImage: '' }); |
| 87 | {/literal} |
| 88 | {else} |
| 89 | var $timeElement = $(); |
| 90 | {/if} |
| 91 | var currentYear = new Date().getFullYear(), |
| 92 | $originalElement = $dateElement.siblings('#{$elementId}').hide(), |
| 93 | date_format = $originalElement.attr('format'), |
| 94 | altDateFormat = 'mm/dd/yy'; |
| 95 | {literal} |
| 96 | |
| 97 | if ( !( ( date_format == 'M yy' ) || ( date_format == 'yy' ) || ( date_format == 'yy-mm' ) ) ) { |
| 98 | $dateElement.addClass( 'dpDate' ); |
| 99 | } |
| 100 | |
| 101 | var yearRange = (currentYear - parseInt($originalElement.attr('startOffset'))) + |
| 102 | ':' + currentYear + parseInt($originalElement.attr('endOffset')), |
| 103 | startRangeYr = currentYear - parseInt($originalElement.attr('startOffset')), |
| 104 | endRangeYr = currentYear + parseInt($originalElement.attr('endOffset')); |
| 105 | |
| 106 | $dateElement.datepicker({ |
| 107 | closeAtTop: true, |
| 108 | dateFormat: date_format, |
| 109 | changeMonth: (date_format.indexOf('m') > -1), |
| 110 | changeYear: (date_format.indexOf('y') > -1), |
| 111 | altField: $originalElement, |
| 112 | altFormat: altDateFormat, |
| 113 | yearRange: yearRange, |
| 114 | minDate: new Date(startRangeYr, 1 - 1, 1), |
| 115 | maxDate: new Date(endRangeYr, 12 - 1, 31) |
| 116 | }); |
| 117 | |
| 118 | // format display date |
| 119 | var displayDateValue = $.datepicker.formatDate(date_format, $.datepicker.parseDate(altDateFormat, $originalElement.val())); |
| 120 | //support unsaved-changes warning: CRM-14353 |
| 121 | $dateElement.val(displayDateValue).data('crm-initial-value', displayDateValue); |
| 122 | |
| 123 | // Add clear button |
| 124 | $($timeElement).add($originalElement).add($dateElement).on('blur change', function() { |
| 125 | var vis = $dateElement.val() || $timeElement.val() ? '' : 'hidden'; |
| 126 | $dateElement.siblings('.crm-clear-link').css('visibility', vis); |
| 127 | }); |
| 128 | $originalElement.change(); |
| 129 | }); |
| 130 | |
| 131 | {/literal} |
| 132 | </script> |
| 133 | |