Sha256: e459d6d0e278d3de2851f2fe6202c6f07ec07e1450b6d58052b6f46377dce3a6

Contents?: true

Size: 1.81 KB

Versions: 25

Compression:

Stored size: 1.81 KB

Contents

spud.admin.date_picker = {};

(function() {
  var picker = spud.admin.date_picker;

  parsePickerDate = function(value) {
    var date = new Date();

    var currentDateTimeComponents = value.split(" ");
    var dateComponents = currentDateTimeComponents[0].split("-");
    if(dateComponents.length >= 3) {
      date = new Date(parseInt(dateComponents[0],10),parseInt(dateComponents[1],10) - 1,parseInt(dateComponents[2],10));
    }
    return date;
  };

  picker.init = function(selector) {
      selector = (typeof(selector) == 'undefined') ? '.spud_form_date_picker, .tb-form-date-picker' : selector;
      $(selector).each(function() {
        var $this = $(this);
        var baseName = $this.attr('name');
        $this.attr('name',baseName.replace("[","_").replace("]",""));
        $this.datepicker({
          'format': 'yyyy-mm-dd',
          'autoclose': true
        });
        $this.val($this.val().split(" ")[0]);
        var date = parsePickerDate($this.val());

        var yearField = $("<input type='hidden'/>");
          yearField.attr('name',baseName.replace(']',"(1i)]"));
          yearField.val(date.getFullYear());
        var monthField = $("<input type='hidden'/>");
          monthField.attr('name',baseName.replace(']',"(2i)]"));
          monthField.val(date.getMonth() + 1);
        var dayField = $("<input type='hidden'/>");
          dayField.attr('name',baseName.replace(']',"(3i)]"));
          dayField.val(date.getUTCDate());
        yearField.insertAfter($this);
        monthField.insertAfter($this);
        dayField.insertAfter($this);


        $this.bind('change', function(evt) {
          var date = parsePickerDate($(this).val());
          yearField.val(date.getFullYear());
          monthField.val(date.getMonth() + 1);
          dayField.val(date.getUTCDate());

        });


      });

  };
})();

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
tb_core-1.4.3.1 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.4.3 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.4.2 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.4.1 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.4.0.1 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.4.beta2 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.4.beta1 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.3.10 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.3.9 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.3.7 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.3.6 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.3.5 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.3.4 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.3.3 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.3.2 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.3.1 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.3.0 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.3.0.beta2 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.3.0.beta1 app/assets/javascripts/admin/core/date_picker.js
tb_core-1.2.8 app/assets/javascripts/admin/core/date_picker.js