Changeset 28765


Ignore:
Timestamp:
Jun 22, 2014, 2:44:43 PM (10 years ago)
Author:
mistic100
Message:

feature 3080: add cancel button, one minute granularity, fix missing css

Location:
trunk/admin/themes/default
Files:
5 edited

Legend:

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

    r28578 r28765  
    11jQuery.timepicker.log = jQuery.noop; // that's ugly, but the timepicker is acting weird and throws parsing errors
    22
    3 jQuery.fn.pwgDatepicker = function(options) {
    4   options = options || {};
    5  
     3jQuery.fn.pwgDatepicker = function(settings) {
     4  var options = jQuery.extend(true, {
     5    showTimepicker: false,
     6    cancelButton: false,
     7  }, settings || {});
     8
    69  return this.each(function() {
    710    var $this = jQuery(this),
    8         $target = jQuery('[name="'+ jQuery(this).data('datepicker') +'"]'),
    9         linked = !!$target.length;
     11        originalValue = $this.val(),
     12        originalDate,
     13        $target = jQuery('[name="'+ $this.data('datepicker') +'"]'),
     14        linked = !!$target.length,
     15        $start, $end;
    1016   
    11     if (linked) { // get value before init
    12       var value = $target.val().split(' ');
     17    if (linked) {
     18      originalValue = $target.val();
    1319    }
    1420
    1521    // custom setter
    1622    function set(date, init) {
     23      if (date === '') date = null;
    1724      $this.datetimepicker('setDate', date);
    1825     
    19       if ($this.data('datepicker-start')) {
     26      if ($this.data('datepicker-start') && $start) {
    2027        $start.datetimepicker('option', 'maxDate', date);
    2128      }
    22       else if ($this.data('datepicker-end')) {
     29      else if ($this.data('datepicker-end') && $end) {
    2330        if (!init) { // on init, "end" is not initialized yet (assuming "start" is before "end" in the DOM)
    2431          $end.datetimepicker('option', 'minDate', date);
     
    2936        $target.val('');
    3037      }
     38    }
     39
     40    // and custom cancel button
     41    if (options.cancelButton) {
     42      options.beforeShow = options.onChangeMonthYear = function() {
     43        setTimeout(function() {
     44          var buttonPane = $this.datepicker('widget')
     45              .find('.ui-datepicker-buttonpane');
     46         
     47          if (buttonPane.find('.pwg-datepicker-cancel').length == 0) {
     48            $('<button type="button">'+ options.cancelButton +'</button>')
     49              .on('click', function() {
     50                set(originalDate, false);
     51                $this.datepicker('hide').blur();
     52              })
     53              .addClass('pwg-datepicker-cancel ui-state-error ui-corner-all')
     54              .appendTo(buttonPane);
     55          }
     56        }, 1);
     57      };
    3158    }
    3259
     
    4370      changeMonth : true,
    4471      changeYear: true,
    45       showTimepicker: false,
    4672      altFieldTimeOnly: false,
    4773      showSecond: false,
    48       alwaysSetTime: false,
    49       stepMinute: 5
     74      alwaysSetTime: false
    5075    }, options));
    5176   
    5277    // attach range pickers
    5378    if ($this.data('datepicker-start')) {
    54       var $start = jQuery('[data-datepicker="'+ jQuery(this).data('datepicker-start') +'"]');
     79      $start = jQuery('[data-datepicker="'+ $this.data('datepicker-start') +'"]');
    5580     
    5681      $this.datetimepicker('option', 'onClose', function(date) {
     
    6186    }
    6287    else if ($this.data('datepicker-end')) {
    63       var $end = jQuery('[data-datepicker="'+ jQuery(this).data('datepicker-end') +'"]');
     88      $end = jQuery('[data-datepicker="'+ $this.data('datepicker-end') +'"]');
    6489     
    6590      $this.datetimepicker('option', 'onClose', function(date) {
     
    78103    // set value from linked input
    79104    if (linked) {
    80       if (value[0].length == 10 && (!options.showTimepicker || value.length==1)) {
    81         set(jQuery.datepicker.parseDate('yy-mm-dd', value[0]), true);
     105      var splitted = originalValue.split(' ');
     106      if (splitted.length == 2 && options.showTimepicker) {
     107        set(jQuery.datepicker.parseDateTime('yy-mm-dd', 'HH:mm:ss', originalValue), true);
    82108      }
    83       else if (value.length == 2 && options.showTimepicker) {
    84         set(jQuery.datepicker.parseDateTime('yy-mm-dd', 'HH:mm:ss', value.join(' ')), true);
     109      else if (splitted[0].length == 10) {
     110        set(jQuery.datepicker.parseDate('yy-mm-dd', splitted[0]), true);
    85111      }
    86112      else {
     
    88114      }
    89115    }
     116   
     117    originalDate = $this.datetimepicker('getDate');
    90118   
    91119    // autoSize not handled by timepicker
  • trunk/admin/themes/default/template/batch_manager_global.tpl

    r28703 r28765  
    6565
    6666jQuery(document).ready(function() {ldelim}
    67   jQuery('[data-datepicker]').pwgDatepicker({ showTimepicker: true });
     67  jQuery('[data-datepicker]').pwgDatepicker({
     68    showTimepicker: true,
     69    cancelButton: '{'Cancel'|translate}'
     70  });
    6871
    6972  jQuery("a.preview-box").colorbox();
  • trunk/admin/themes/default/template/batch_manager_unit.tpl

    r28703 r28765  
    2424{* <!-- DATEPICKER --> *}
    2525jQuery(function(){ {* <!-- onLoad needed to wait localization loads --> *}
    26   jQuery('[data-datepicker]').pwgDatepicker({ showTimepicker: true });
     26  jQuery('[data-datepicker]').pwgDatepicker({
     27    showTimepicker: true,
     28    cancelButton: '{'Cancel'|translate}'
     29  });
    2730});
    2831
  • trunk/admin/themes/default/template/include/datepicker.inc.tpl

    r28500 r28765  
    1212{/if}
    1313
     14{combine_css path="themes/default/js/ui/theme/jquery.ui.theme.css"}
    1415{combine_css path="themes/default/js/ui/theme/jquery.ui.slider.css"}
    1516{combine_css path="themes/default/js/ui/theme/jquery.ui.datepicker.css"}
  • trunk/admin/themes/default/template/picture_modify.tpl

    r28703 r28765  
    3333{* <!-- DATEPICKER --> *}
    3434jQuery(function(){ {* <!-- onLoad needed to wait localization loads --> *}
    35   jQuery('[data-datepicker]').pwgDatepicker({ showTimepicker: true });
     35  jQuery('[data-datepicker]').pwgDatepicker({
     36    showTimepicker: true,
     37    cancelButton: '{'Cancel'|translate}'
     38  });
    3639});
    3740}());
Note: See TracChangeset for help on using the changeset viewer.