Sha256: 5722a3adf67d32fac87c8062a206de1bc6258a2f78bdf1ecd91c2c0aacd508b4

Contents?: true

Size: 1.94 KB

Versions: 72

Compression:

Stored size: 1.94 KB

Contents

var datepickers = datepickers || {
  init: function() {
    this.load_ranges();
    this.load_regulars();
    $('.date_picker, .date_range_picker').find('.input-group-addon').on(
      'click',
      this.icon_click_listener
    );
  },

  icon_click_listener: function(e) {
    e.preventDefault();
    $(this).parents('.input-group').find('input').trigger('focus');
  },

  load_ranges: function() {
    if(typeof this.starts_on === 'undefined' || typeof this.stops_on === 'undefined') return;

    $('.date_range_picker input').each(function(){
      var input = $(this);

      if(input.data('start') !== null) {
        datepickers.starts_on(input.data('start')).datepicker().on(
          'changeDate',
          datepickers.starts_on_change_date_listener
        );
      }

      if(input.data('stop') !== null) {
        datepickers.stops_on(input.data('stop')).datepicker({
          weekStart: 1,
          autoclose: true
        }).on('changeDate', datepickers.stops_on_change_date_listener);
      }
    });
  },

  load_regulars: function() {
    var inputs = $('.date_picker input');
    if(typeof inputs.datepicker !== 'function') return;
    inputs.datepicker();
  },

  starts_on: function(id) {
    return $('.date_range_picker input[data-start="'+ id +'"]');
  },

  starts_on_change_date_listener: function(selected) {
    var input = $(this);
    var date = new Date(selected.date.valueOf());
    date.setDate(date.getDate(new Date(selected.date.valueOf())));
    datepickers.stops_on(input.data('start')).datepicker('setStartDate', date);
  },

  stops_on: function(id) {
    return $('.date_range_picker input[data-stop="'+ id +'"]');
  },

  stops_on_change_date_listener: function(selected) {
    var input = $(this);
    var date = new Date(selected.date.valueOf());
    date.setDate(date.getDate(new Date(selected.date.valueOf())));
    datepickers.starts_on(input.data('stop')).datepicker('setEndDate', date);
  }
};

$(function(){ datepickers.init(); });

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
udongo-7.9.0 app/assets/javascripts/backend/datepickers.js
udongo-7.8.1 app/assets/javascripts/backend/datepickers.js
udongo-7.8.0 app/assets/javascripts/backend/datepickers.js
udongo-7.7.2 app/assets/javascripts/backend/datepickers.js
udongo-7.7.1 app/assets/javascripts/backend/datepickers.js
udongo-7.7.0 app/assets/javascripts/backend/datepickers.js
udongo-7.6.2 app/assets/javascripts/backend/datepickers.js
udongo-7.6.1 app/assets/javascripts/backend/datepickers.js
udongo-7.6.0 app/assets/javascripts/backend/datepickers.js
udongo-7.5.1 app/assets/javascripts/backend/datepickers.js
udongo-7.5.0 app/assets/javascripts/backend/datepickers.js
udongo-7.4.2 app/assets/javascripts/backend/datepickers.js
udongo-7.4.1 app/assets/javascripts/backend/datepickers.js
udongo-7.4.0 app/assets/javascripts/backend/datepickers.js
udongo-7.3.5 app/assets/javascripts/backend/datepickers.js
udongo-7.3.4 app/assets/javascripts/backend/datepickers.js
udongo-7.3.3 app/assets/javascripts/backend/datepickers.js
udongo-7.3.2 app/assets/javascripts/backend/datepickers.js
udongo-7.3.1 app/assets/javascripts/backend/datepickers.js
udongo-7.2.1 app/assets/javascripts/backend/datepickers.js