Ignore:
Timestamp:
May 18, 2014, 12:58:53 PM (10 years ago)
Author:
mistic100
Message:

feature 2679 : allow to change creation time

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/themes/default/js/datepicker.js

    r28497 r28500  
     1jQuery.timepicker.log = jQuery.noop; // that's ugly, but the timepicker is acting weird and throws parsing errors
     2
    13jQuery.fn.pwgDatepicker = function(options) {
    24  options = options || {};
     
    57    var $this = jQuery(this),
    68        $target = jQuery('[name="'+ jQuery(this).data('datepicker') +'"]'),
    7         value = $target.val().split('-');
     9        linked = !!$target.length;
    810   
    9     function set(date) {
    10       $this.datepicker('setDate', date);
     11    if (linked) { // get value before init
     12      var value = $target.val().split(' ');
     13    }
     14
     15    // custom setter
     16    function set(date, init) {
     17      $this.datetimepicker('setDate', date);
    1118     
    1219      if ($this.data('datepicker-start')) {
    13         $start.datepicker('option', 'maxDate', date);
     20        $start.datetimepicker('option', 'maxDate', date);
    1421      }
    1522      else if ($this.data('datepicker-end')) {
    16         $end.datepicker('option', 'minDate', date);
     23        if (!init) { // on init, "end" is not initialized yet (assuming "start" is before "end" in the DOM)
     24          $end.datetimepicker('option', 'minDate', date);
     25        }
     26      }
     27     
     28      if (!date && linked) {
     29        $target.val('');
    1730      }
    1831    }
    1932
    2033    // init picker
    21     $this.datepicker(jQuery.extend({
    22       dateFormat: 'DD d MM yy',
    23       altField: $target,
     34    $this.datetimepicker(jQuery.extend({
     35      dateFormat: linked ? 'DD d MM yy' : 'yy-mm-dd',
     36      timeFormat: 'HH:mm',
     37     
     38      altField: linked ? $target : null,
    2439      altFormat: 'yy-mm-dd',
     40      altTimeFormat: options.showTimepicker ? 'HH:mm:ss' : '',
     41     
    2542      autoSize: true,
    2643      changeMonth : true,
    27       changeYear: true
     44      changeYear: true,
     45      showTimepicker: false,
     46      altFieldTimeOnly: false,
     47      showSecond: false,
     48      alwaysSetTime: false,
     49      stepMinute: 5
    2850    }, options));
    2951   
    30     // attach linked picker (for ranges)
     52    // attach range pickers
    3153    if ($this.data('datepicker-start')) {
    3254      var $start = jQuery('[data-datepicker="'+ jQuery(this).data('datepicker-start') +'"]');
    3355     
    34       $this.datepicker('option', 'onClose', function(date) {
    35         $start.datepicker('option', 'maxDate', date);
     56      $this.datetimepicker('option', 'onClose', function(date) {
     57        $start.datetimepicker('option', 'maxDate', date);
    3658      });
     59     
     60      $this.datetimepicker('option', 'minDate', $start.datetimepicker('getDate'));
    3761    }
    3862    else if ($this.data('datepicker-end')) {
    3963      var $end = jQuery('[data-datepicker="'+ jQuery(this).data('datepicker-end') +'"]');
    4064     
    41       $this.datepicker('option', 'onClose', function(date) {
    42         $end.datepicker('option', 'minDate', date);
     65      $this.datetimepicker('option', 'onClose', function(date) {
     66        $end.datetimepicker('option', 'minDate', date);
    4367      });
    4468    }
     
    4872      jQuery('#'+ $this.data('datepicker-unset')).on('click', function(e) {
    4973        e.preventDefault();
    50        
    51         $target.val('');
    52         set(null);
     74        set(null, false);
    5375      });
    5476    }
    5577   
    5678    // set value from linked input
    57     if (value.length == 3) {
    58       set(new Date(value[0], value[1]-1, value[2]));
     79    if (linked) {
     80      if (value[0].length == 10 && !options.showTimepicker) {
     81        set(jQuery.datepicker.parseDate('yy-mm-dd', value[0]), true);
     82      }
     83      else if (value.length == 2 && options.showTimepicker) {
     84        set(jQuery.datepicker.parseDateTime('yy-mm-dd', 'HH:mm:ss', value.join(' ')), true);
     85      }
     86      else {
     87        set(null, true);
     88      }
     89    }
     90   
     91    // autoSize not handled by timepicker
     92    if (options.showTimepicker) {
     93      $this.attr('size', parseInt($this.attr('size'))+6);
    5994    }
    6095  });
Note: See TracChangeset for help on using the changeset viewer.