Merge pull request #3601 from atif-shaikh/CRM-14942
[civicrm-core.git] / templates / CRM / common / jcalendar.tpl
index 98b67ed1681776781554ef0b46205c5d7c5fc988..b4e25f3d0dbd02e30298f4fdd47330ee1aa42daf 100644 (file)
@@ -1,8 +1,8 @@
 {*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -43,7 +43,9 @@
         {$form.$blockSection.$blockId.$tElement.html|crmAddClass:six}
     {/if}
 {else}
-    {assign var='elementId'   value=$form.$elementName.id}
+    {if !$elementId}
+      {assign var='elementId'   value=$form.$elementName.id}
+    {/if}
     {assign var="timeElement" value=$elementName|cat:'_time'}
     {$form.$elementName.html}
 {/if}
 {/if}
 
 {if $action neq 1028}
-    <span class="crm-clear-link">(<a href="#" onclick="clearDateTime( '{$elementId}' ); return false;">{ts}clear{/ts}</a>)</span>
+    <a href="#" class="crm-hover-button crm-clear-link" title="{ts}Clear{/ts}"><span class="icon close-icon"></span></a>
 {/if}
 
 <script type="text/javascript">
     {literal}
-    cj( function() {
+    CRM.$(function($) {
       {/literal}
       var element_date   = "#{$displayDate}";
+      var element_time  = "#{$elementId}_time";
       {if $timeElement}
-          var element_time  = "#{$timeElement}";
+          element_time  = "#{$timeElement}";
           var time_format   = cj( element_time ).attr('timeFormat');
           {literal}
               cj(element_time).timeEntry({ show24Hours : time_format, spinnerImage: '' });
       // format date according to display field
       displayDateValue = cj.datepicker.formatDate( date_format, displayDateValue );
       cj( element_date).val( displayDateValue );
+      //support unsaved-changes warning: CRM-14353
+      cj( element_date).data('crm-initial-value', displayDateValue);
 
       cj(element_date).click( function( ) {
           hideYear( this );
       cj('.ui-datepicker-trigger').click( function( ) {
           hideYear( cj(this).prev() );
       });
-    });
-
-    function hideYear( element ) {
+      function hideYear( element ) {
         var format = cj( element ).attr('format');
         if ( format == 'dd-mm' || format == 'mm/dd' ) {
-            cj(".ui-datepicker-year").css( 'display', 'none' );
+          cj(".ui-datepicker-year").css('display', 'none');
         }
-    }
+      }
+      cj(alt_field + ',' + element_date + ',' + element_time).on('blur change', function() {
+        var vis = cj(alt_field).val() || cj(element_time).val() ? '' : 'hidden';
+        cj(this).siblings('.crm-clear-link').css('visibility', vis);
+      });
+      cj(alt_field).change();
+    });
 
-    function clearDateTime( element ) {
-        cj('input#' + element + ',input#' + element + '_time' + ',input#' + element + '_display').val('');
-    }
     {/literal}
 </script>
 {/strip}