reports_kits 0.7.5 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/.rubocop.yml +85 -0
  4. data/.travis.yml +21 -0
  5. data/Appraisals +27 -0
  6. data/Gemfile +3 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +35 -0
  9. data/Rakefile +2 -0
  10. data/app/assets/javascripts/reports_kits/application.js +14 -0
  11. data/app/assets/javascripts/reports_kits/lib/_init.js +9 -0
  12. data/app/assets/javascripts/reports_kits/lib/chart.js +73 -0
  13. data/app/assets/javascripts/reports_kits/lib/report.js +135 -0
  14. data/app/assets/javascripts/reports_kits/lib/table.js +87 -0
  15. data/app/assets/javascripts/reports_kits/vendor/chart.js +12269 -0
  16. data/app/assets/javascripts/reports_kits/vendor/daterangepicker.js +1627 -0
  17. data/app/assets/javascripts/reports_kits/vendor/jquery.tablesorter.min.js +4 -0
  18. data/app/assets/javascripts/reports_kits/vendor/moment.js +4040 -0
  19. data/app/assets/javascripts/reports_kits/vendor/select2.full.js +6436 -0
  20. data/app/assets/stylesheets/reports_kits/application.css.scss +3 -0
  21. data/app/assets/stylesheets/reports_kits/reports.css.sass +33 -0
  22. data/app/assets/stylesheets/reports_kits/select2_overrides.css.sass +7 -0
  23. data/app/assets/stylesheets/reports_kits/vendor/daterangepicker.css +269 -0
  24. data/app/assets/stylesheets/reports_kits/vendor/select2-bootstrap.css +721 -0
  25. data/app/assets/stylesheets/reports_kits/vendor/select2.css +484 -0
  26. data/config/initializers/mime_types.rb +1 -0
  27. data/config/routes.rb +10 -0
  28. data/docs/images/demo.gif +0 -0
  29. data/docs/images/users_by_created_at.png +0 -0
  30. data/gemfiles/mysql.gemfile +7 -0
  31. data/gemfiles/mysql.gemfile.lock +167 -0
  32. data/gemfiles/postgresql.gemfile +7 -0
  33. data/gemfiles/postgresql.gemfile.lock +165 -0
  34. data/gemfiles/postgresql_rails_5.1.4.gemfile +8 -0
  35. data/gemfiles/postgresql_rails_5.1.4.gemfile.lock +168 -0
  36. data/gemfiles/rails_4_mysql.gemfile +8 -0
  37. data/gemfiles/rails_4_mysql.gemfile.lock +165 -0
  38. data/gemfiles/rails_4_postgresql.gemfile +8 -0
  39. data/gemfiles/rails_4_postgresql.gemfile.lock +163 -0
  40. data/gemfiles/rails_5.1.4_postgresql.gemfile +8 -0
  41. data/gemfiles/rails_5.1.4_postgresql.gemfile.lock +169 -0
  42. data/gemfiles/rails_5_mysql.gemfile +8 -0
  43. data/gemfiles/rails_5_mysql.gemfile.lock +171 -0
  44. data/gemfiles/rails_5_postgresql.gemfile +8 -0
  45. data/gemfiles/rails_5_postgresql.gemfile.lock +169 -0
  46. data/lib/reports_kits/base_controller.rb +17 -0
  47. data/lib/reports_kits/cache.rb +37 -0
  48. data/lib/reports_kits/configuration.rb +50 -0
  49. data/lib/reports_kits/engine.rb +21 -0
  50. data/lib/reports_kits/entity.rb +3 -0
  51. data/lib/reports_kits/filters_controller.rb +11 -0
  52. data/lib/reports_kits/form_builder.rb +66 -0
  53. data/lib/reports_kits/helper.rb +24 -0
  54. data/lib/reports_kits/model.rb +16 -0
  55. data/lib/reports_kits/model_configuration.rb +28 -0
  56. data/lib/reports_kits/normalized_params.rb +16 -0
  57. data/lib/reports_kits/order.rb +33 -0
  58. data/lib/reports_kits/relative_time.rb +42 -0
  59. data/lib/reports_kits/report_builder.rb +88 -0
  60. data/lib/reports_kits/reports/abstract_series.rb +9 -0
  61. data/lib/reports_kits/reports/adapters/mysql.rb +26 -0
  62. data/lib/reports_kits/reports/adapters/postgresql.rb +26 -0
  63. data/lib/reports_kits/reports/composite_series.rb +48 -0
  64. data/lib/reports_kits/reports/contextual_filter.rb +19 -0
  65. data/lib/reports_kits/reports/data/add_table_aggregations.rb +105 -0
  66. data/lib/reports_kits/reports/data/aggregate_composite.rb +97 -0
  67. data/lib/reports_kits/reports/data/aggregate_one_dimension.rb +39 -0
  68. data/lib/reports_kits/reports/data/aggregate_two_dimensions.rb +39 -0
  69. data/lib/reports_kits/reports/data/chart_data_for_data_method.rb +62 -0
  70. data/lib/reports_kits/reports/data/chart_options.rb +155 -0
  71. data/lib/reports_kits/reports/data/format_one_dimension.rb +140 -0
  72. data/lib/reports_kits/reports/data/format_table.rb +63 -0
  73. data/lib/reports_kits/reports/data/format_two_dimensions.rb +143 -0
  74. data/lib/reports_kits/reports/data/generate.rb +156 -0
  75. data/lib/reports_kits/reports/data/generate_for_properties.rb +97 -0
  76. data/lib/reports_kits/reports/data/normalize_properties.rb +62 -0
  77. data/lib/reports_kits/reports/data/populate_one_dimension.rb +54 -0
  78. data/lib/reports_kits/reports/data/populate_two_dimensions.rb +104 -0
  79. data/lib/reports_kits/reports/data/utils.rb +178 -0
  80. data/lib/reports_kits/reports/dimension.rb +27 -0
  81. data/lib/reports_kits/reports/dimension_with_series.rb +144 -0
  82. data/lib/reports_kits/reports/filter.rb +29 -0
  83. data/lib/reports_kits/reports/filter_types/base.rb +48 -0
  84. data/lib/reports_kits/reports/filter_types/boolean.rb +47 -0
  85. data/lib/reports_kits/reports/filter_types/datetime.rb +51 -0
  86. data/lib/reports_kits/reports/filter_types/number.rb +30 -0
  87. data/lib/reports_kits/reports/filter_types/records.rb +26 -0
  88. data/lib/reports_kits/reports/filter_types/string.rb +38 -0
  89. data/lib/reports_kits/reports/filter_with_series.rb +97 -0
  90. data/lib/reports_kits/reports/generate_autocomplete_method_results.rb +29 -0
  91. data/lib/reports_kits/reports/generate_autocomplete_results.rb +57 -0
  92. data/lib/reports_kits/reports/inferrable_configuration.rb +116 -0
  93. data/lib/reports_kits/reports/model_settings.rb +30 -0
  94. data/lib/reports_kits/reports/properties.rb +10 -0
  95. data/lib/reports_kits/reports/properties_to_filter.rb +40 -0
  96. data/lib/reports_kits/reports/series.rb +121 -0
  97. data/lib/reports_kits/reports_controller.rb +65 -0
  98. data/lib/reports_kits/utils.rb +11 -0
  99. data/lib/reports_kits/value.rb +3 -0
  100. data/lib/reports_kits/version.rb +3 -0
  101. data/lib/reports_kits.rb +79 -0
  102. data/reports_kits.gemspec +26 -0
  103. data/spec/factories/issue_factory.rb +4 -0
  104. data/spec/factories/issues_label_factory.rb +4 -0
  105. data/spec/factories/label_factory.rb +4 -0
  106. data/spec/factories/pro_repo_factory.rb +5 -0
  107. data/spec/factories/repo_factory.rb +5 -0
  108. data/spec/factories/tag_factory.rb +4 -0
  109. data/spec/fixtures/generate_inputs.yml +254 -0
  110. data/spec/fixtures/generate_outputs.yml +1216 -0
  111. data/spec/reports_kit/form_builder_spec.rb +26 -0
  112. data/spec/reports_kit/relative_time_spec.rb +29 -0
  113. data/spec/reports_kit/reports/data/generate/contextual_filters_spec.rb +60 -0
  114. data/spec/reports_kit/reports/data/generate_spec.rb +1371 -0
  115. data/spec/reports_kit/reports/data/normalize_properties_spec.rb +196 -0
  116. data/spec/reports_kit/reports/dimension_with_series_spec.rb +67 -0
  117. data/spec/reports_kit/reports/filter_with_series_spec.rb +39 -0
  118. data/spec/reports_kit/reports/generate_autocomplete_results_spec.rb +69 -0
  119. data/spec/spec_helper.rb +77 -0
  120. data/spec/support/config.rb +41 -0
  121. data/spec/support/example_data_methods.rb +25 -0
  122. data/spec/support/factory_girl.rb +5 -0
  123. data/spec/support/helpers.rb +25 -0
  124. data/spec/support/models/issue.rb +14 -0
  125. data/spec/support/models/issues_label.rb +4 -0
  126. data/spec/support/models/label.rb +5 -0
  127. data/spec/support/models/pro/repo.rb +5 -0
  128. data/spec/support/models/pro/special_issue.rb +4 -0
  129. data/spec/support/models/repo.rb +13 -0
  130. data/spec/support/models/tag.rb +4 -0
  131. data/spec/support/schema.rb +39 -0
  132. metadata +134 -4
@@ -0,0 +1,1627 @@
1
+ /**
2
+ * @version: 2.1.25
3
+ * @author: Dan Grossman http://www.dangrossman.info/
4
+ * @copyright: Copyright (c) 2012-2017 Dan Grossman. All rights reserved.
5
+ * @license: Licensed under the MIT license. See http://www.opensource.org/licenses/mit-license.php
6
+ * @website: http://www.daterangepicker.com/
7
+ */
8
+ // Follow the UMD template https://github.com/umdjs/umd/blob/master/templates/returnExportsGlobal.js
9
+ (function (root, factory) {
10
+ if (typeof define === 'function' && define.amd) {
11
+ // AMD. Make globaly available as well
12
+ define(['moment', 'jquery'], function (moment, jquery) {
13
+ return (root.daterangepicker = factory(moment, jquery));
14
+ });
15
+ } else if (typeof module === 'object' && module.exports) {
16
+ // Node / Browserify
17
+ //isomorphic issue
18
+ var jQuery = (typeof window != 'undefined') ? window.jQuery : undefined;
19
+ if (!jQuery) {
20
+ jQuery = require('jquery');
21
+ if (!jQuery.fn) jQuery.fn = {};
22
+ }
23
+ var moment = (typeof window != 'undefined' && typeof window.moment != 'undefined') ? window.moment : require('moment');
24
+ module.exports = factory(moment, jQuery);
25
+ } else {
26
+ // Browser globals
27
+ root.daterangepicker = factory(root.moment, root.jQuery);
28
+ }
29
+ }(this, function(moment, $) {
30
+ var DateRangePicker = function(element, options, cb) {
31
+
32
+ //default settings for options
33
+ this.parentEl = 'body';
34
+ this.element = $(element);
35
+ this.startDate = moment().startOf('day');
36
+ this.endDate = moment().endOf('day');
37
+ this.minDate = false;
38
+ this.maxDate = false;
39
+ this.dateLimit = false;
40
+ this.autoApply = false;
41
+ this.singleDatePicker = false;
42
+ this.showDropdowns = false;
43
+ this.showWeekNumbers = false;
44
+ this.showISOWeekNumbers = false;
45
+ this.showCustomRangeLabel = true;
46
+ this.timePicker = false;
47
+ this.timePicker24Hour = false;
48
+ this.timePickerIncrement = 1;
49
+ this.timePickerSeconds = false;
50
+ this.linkedCalendars = true;
51
+ this.autoUpdateInput = true;
52
+ this.alwaysShowCalendars = false;
53
+ this.ranges = {};
54
+
55
+ this.opens = 'right';
56
+ if (this.element.hasClass('pull-right'))
57
+ this.opens = 'left';
58
+
59
+ this.drops = 'down';
60
+ if (this.element.hasClass('dropup'))
61
+ this.drops = 'up';
62
+
63
+ this.buttonClasses = 'btn btn-sm';
64
+ this.applyClass = 'btn-success';
65
+ this.cancelClass = 'btn-default';
66
+
67
+ this.locale = {
68
+ direction: 'ltr',
69
+ format: moment.localeData().longDateFormat('L'),
70
+ separator: ' - ',
71
+ applyLabel: 'Apply',
72
+ cancelLabel: 'Cancel',
73
+ weekLabel: 'W',
74
+ customRangeLabel: 'Custom Range',
75
+ daysOfWeek: moment.weekdaysMin(),
76
+ monthNames: moment.monthsShort(),
77
+ firstDay: moment.localeData().firstDayOfWeek()
78
+ };
79
+
80
+ this.callback = function() { };
81
+
82
+ //some state information
83
+ this.isShowing = false;
84
+ this.leftCalendar = {};
85
+ this.rightCalendar = {};
86
+
87
+ //custom options from user
88
+ if (typeof options !== 'object' || options === null)
89
+ options = {};
90
+
91
+ //allow setting options with data attributes
92
+ //data-api options will be overwritten with custom javascript options
93
+ options = $.extend(this.element.data(), options);
94
+
95
+ //html template for the picker UI
96
+ if (typeof options.template !== 'string' && !(options.template instanceof $))
97
+ options.template = '<div class="daterangepicker dropdown-menu">' +
98
+ '<div class="calendar left">' +
99
+ '<div class="daterangepicker_input">' +
100
+ '<input class="input-mini form-control" type="text" name="daterangepicker_start" value="" />' +
101
+ '<i class="fa fa-calendar glyphicon glyphicon-calendar"></i>' +
102
+ '<div class="calendar-time">' +
103
+ '<div></div>' +
104
+ '<i class="fa fa-clock-o glyphicon glyphicon-time"></i>' +
105
+ '</div>' +
106
+ '</div>' +
107
+ '<div class="calendar-table"></div>' +
108
+ '</div>' +
109
+ '<div class="calendar right">' +
110
+ '<div class="daterangepicker_input">' +
111
+ '<input class="input-mini form-control" type="text" name="daterangepicker_end" value="" />' +
112
+ '<i class="fa fa-calendar glyphicon glyphicon-calendar"></i>' +
113
+ '<div class="calendar-time">' +
114
+ '<div></div>' +
115
+ '<i class="fa fa-clock-o glyphicon glyphicon-time"></i>' +
116
+ '</div>' +
117
+ '</div>' +
118
+ '<div class="calendar-table"></div>' +
119
+ '</div>' +
120
+ '<div class="ranges">' +
121
+ '<div class="range_inputs">' +
122
+ '<button class="applyBtn" disabled="disabled" type="button"></button> ' +
123
+ '<button class="cancelBtn" type="button"></button>' +
124
+ '</div>' +
125
+ '</div>' +
126
+ '</div>';
127
+
128
+ this.parentEl = (options.parentEl && $(options.parentEl).length) ? $(options.parentEl) : $(this.parentEl);
129
+ this.container = $(options.template).appendTo(this.parentEl);
130
+
131
+ //
132
+ // handle all the possible options overriding defaults
133
+ //
134
+
135
+ if (typeof options.locale === 'object') {
136
+
137
+ if (typeof options.locale.direction === 'string')
138
+ this.locale.direction = options.locale.direction;
139
+
140
+ if (typeof options.locale.format === 'string')
141
+ this.locale.format = options.locale.format;
142
+
143
+ if (typeof options.locale.separator === 'string')
144
+ this.locale.separator = options.locale.separator;
145
+
146
+ if (typeof options.locale.daysOfWeek === 'object')
147
+ this.locale.daysOfWeek = options.locale.daysOfWeek.slice();
148
+
149
+ if (typeof options.locale.monthNames === 'object')
150
+ this.locale.monthNames = options.locale.monthNames.slice();
151
+
152
+ if (typeof options.locale.firstDay === 'number')
153
+ this.locale.firstDay = options.locale.firstDay;
154
+
155
+ if (typeof options.locale.applyLabel === 'string')
156
+ this.locale.applyLabel = options.locale.applyLabel;
157
+
158
+ if (typeof options.locale.cancelLabel === 'string')
159
+ this.locale.cancelLabel = options.locale.cancelLabel;
160
+
161
+ if (typeof options.locale.weekLabel === 'string')
162
+ this.locale.weekLabel = options.locale.weekLabel;
163
+
164
+ if (typeof options.locale.customRangeLabel === 'string'){
165
+ //Support unicode chars in the custom range name.
166
+ var elem = document.createElement('textarea');
167
+ elem.innerHTML = options.locale.customRangeLabel;
168
+ var rangeHtml = elem.value;
169
+ this.locale.customRangeLabel = rangeHtml;
170
+ }
171
+ }
172
+ this.container.addClass(this.locale.direction);
173
+
174
+ if (typeof options.startDate === 'string')
175
+ this.startDate = moment(options.startDate, this.locale.format);
176
+
177
+ if (typeof options.endDate === 'string')
178
+ this.endDate = moment(options.endDate, this.locale.format);
179
+
180
+ if (typeof options.minDate === 'string')
181
+ this.minDate = moment(options.minDate, this.locale.format);
182
+
183
+ if (typeof options.maxDate === 'string')
184
+ this.maxDate = moment(options.maxDate, this.locale.format);
185
+
186
+ if (typeof options.startDate === 'object')
187
+ this.startDate = moment(options.startDate);
188
+
189
+ if (typeof options.endDate === 'object')
190
+ this.endDate = moment(options.endDate);
191
+
192
+ if (typeof options.minDate === 'object')
193
+ this.minDate = moment(options.minDate);
194
+
195
+ if (typeof options.maxDate === 'object')
196
+ this.maxDate = moment(options.maxDate);
197
+
198
+ // sanity check for bad options
199
+ if (this.minDate && this.startDate.isBefore(this.minDate))
200
+ this.startDate = this.minDate.clone();
201
+
202
+ // sanity check for bad options
203
+ if (this.maxDate && this.endDate.isAfter(this.maxDate))
204
+ this.endDate = this.maxDate.clone();
205
+
206
+ if (typeof options.applyClass === 'string')
207
+ this.applyClass = options.applyClass;
208
+
209
+ if (typeof options.cancelClass === 'string')
210
+ this.cancelClass = options.cancelClass;
211
+
212
+ if (typeof options.dateLimit === 'object')
213
+ this.dateLimit = options.dateLimit;
214
+
215
+ if (typeof options.opens === 'string')
216
+ this.opens = options.opens;
217
+
218
+ if (typeof options.drops === 'string')
219
+ this.drops = options.drops;
220
+
221
+ if (typeof options.showWeekNumbers === 'boolean')
222
+ this.showWeekNumbers = options.showWeekNumbers;
223
+
224
+ if (typeof options.showISOWeekNumbers === 'boolean')
225
+ this.showISOWeekNumbers = options.showISOWeekNumbers;
226
+
227
+ if (typeof options.buttonClasses === 'string')
228
+ this.buttonClasses = options.buttonClasses;
229
+
230
+ if (typeof options.buttonClasses === 'object')
231
+ this.buttonClasses = options.buttonClasses.join(' ');
232
+
233
+ if (typeof options.showDropdowns === 'boolean')
234
+ this.showDropdowns = options.showDropdowns;
235
+
236
+ if (typeof options.showCustomRangeLabel === 'boolean')
237
+ this.showCustomRangeLabel = options.showCustomRangeLabel;
238
+
239
+ if (typeof options.singleDatePicker === 'boolean') {
240
+ this.singleDatePicker = options.singleDatePicker;
241
+ if (this.singleDatePicker)
242
+ this.endDate = this.startDate.clone();
243
+ }
244
+
245
+ if (typeof options.timePicker === 'boolean')
246
+ this.timePicker = options.timePicker;
247
+
248
+ if (typeof options.timePickerSeconds === 'boolean')
249
+ this.timePickerSeconds = options.timePickerSeconds;
250
+
251
+ if (typeof options.timePickerIncrement === 'number')
252
+ this.timePickerIncrement = options.timePickerIncrement;
253
+
254
+ if (typeof options.timePicker24Hour === 'boolean')
255
+ this.timePicker24Hour = options.timePicker24Hour;
256
+
257
+ if (typeof options.autoApply === 'boolean')
258
+ this.autoApply = options.autoApply;
259
+
260
+ if (typeof options.autoUpdateInput === 'boolean')
261
+ this.autoUpdateInput = options.autoUpdateInput;
262
+
263
+ if (typeof options.linkedCalendars === 'boolean')
264
+ this.linkedCalendars = options.linkedCalendars;
265
+
266
+ if (typeof options.isInvalidDate === 'function')
267
+ this.isInvalidDate = options.isInvalidDate;
268
+
269
+ if (typeof options.isCustomDate === 'function')
270
+ this.isCustomDate = options.isCustomDate;
271
+
272
+ if (typeof options.alwaysShowCalendars === 'boolean')
273
+ this.alwaysShowCalendars = options.alwaysShowCalendars;
274
+
275
+ // update day names order to firstDay
276
+ if (this.locale.firstDay != 0) {
277
+ var iterator = this.locale.firstDay;
278
+ while (iterator > 0) {
279
+ this.locale.daysOfWeek.push(this.locale.daysOfWeek.shift());
280
+ iterator--;
281
+ }
282
+ }
283
+
284
+ var start, end, range;
285
+
286
+ //if no start/end dates set, check if an input element contains initial values
287
+ if (typeof options.startDate === 'undefined' && typeof options.endDate === 'undefined') {
288
+ if ($(this.element).is('input[type=text]')) {
289
+ var val = $(this.element).val(),
290
+ split = val.split(this.locale.separator);
291
+
292
+ start = end = null;
293
+
294
+ if (split.length == 2) {
295
+ start = moment(split[0], this.locale.format);
296
+ end = moment(split[1], this.locale.format);
297
+ } else if (this.singleDatePicker && val !== "") {
298
+ start = moment(val, this.locale.format);
299
+ end = moment(val, this.locale.format);
300
+ }
301
+ if (start !== null && end !== null) {
302
+ this.setStartDate(start);
303
+ this.setEndDate(end);
304
+ }
305
+ }
306
+ }
307
+
308
+ if (typeof options.ranges === 'object') {
309
+ for (range in options.ranges) {
310
+
311
+ if (typeof options.ranges[range][0] === 'string')
312
+ start = moment(options.ranges[range][0], this.locale.format);
313
+ else
314
+ start = moment(options.ranges[range][0]);
315
+
316
+ if (typeof options.ranges[range][1] === 'string')
317
+ end = moment(options.ranges[range][1], this.locale.format);
318
+ else
319
+ end = moment(options.ranges[range][1]);
320
+
321
+ // If the start or end date exceed those allowed by the minDate or dateLimit
322
+ // options, shorten the range to the allowable period.
323
+ if (this.minDate && start.isBefore(this.minDate))
324
+ start = this.minDate.clone();
325
+
326
+ var maxDate = this.maxDate;
327
+ if (this.dateLimit && maxDate && start.clone().add(this.dateLimit).isAfter(maxDate))
328
+ maxDate = start.clone().add(this.dateLimit);
329
+ if (maxDate && end.isAfter(maxDate))
330
+ end = maxDate.clone();
331
+
332
+ // If the end of the range is before the minimum or the start of the range is
333
+ // after the maximum, don't display this range option at all.
334
+ if ((this.minDate && end.isBefore(this.minDate, this.timepicker ? 'minute' : 'day'))
335
+ || (maxDate && start.isAfter(maxDate, this.timepicker ? 'minute' : 'day')))
336
+ continue;
337
+
338
+ //Support unicode chars in the range names.
339
+ var elem = document.createElement('textarea');
340
+ elem.innerHTML = range;
341
+ var rangeHtml = elem.value;
342
+
343
+ this.ranges[rangeHtml] = [start, end];
344
+ }
345
+
346
+ var list = '<ul>';
347
+ for (range in this.ranges) {
348
+ list += '<li data-range-key="' + range + '">' + range + '</li>';
349
+ }
350
+ if (this.showCustomRangeLabel) {
351
+ list += '<li data-range-key="' + this.locale.customRangeLabel + '">' + this.locale.customRangeLabel + '</li>';
352
+ }
353
+ list += '</ul>';
354
+ this.container.find('.ranges').prepend(list);
355
+ }
356
+
357
+ if (typeof cb === 'function') {
358
+ this.callback = cb;
359
+ }
360
+
361
+ if (!this.timePicker) {
362
+ this.startDate = this.startDate.startOf('day');
363
+ this.endDate = this.endDate.endOf('day');
364
+ this.container.find('.calendar-time').hide();
365
+ }
366
+
367
+ //can't be used together for now
368
+ if (this.timePicker && this.autoApply)
369
+ this.autoApply = false;
370
+
371
+ if (this.autoApply && typeof options.ranges !== 'object') {
372
+ this.container.find('.ranges').hide();
373
+ } else if (this.autoApply) {
374
+ this.container.find('.applyBtn, .cancelBtn').addClass('hide');
375
+ }
376
+
377
+ if (this.singleDatePicker) {
378
+ this.container.addClass('single');
379
+ this.container.find('.calendar.left').addClass('single');
380
+ this.container.find('.calendar.left').show();
381
+ this.container.find('.calendar.right').hide();
382
+ this.container.find('.daterangepicker_input input, .daterangepicker_input > i').hide();
383
+ if (this.timePicker) {
384
+ this.container.find('.ranges ul').hide();
385
+ } else {
386
+ this.container.find('.ranges').hide();
387
+ }
388
+ }
389
+
390
+ if ((typeof options.ranges === 'undefined' && !this.singleDatePicker) || this.alwaysShowCalendars) {
391
+ this.container.addClass('show-calendar');
392
+ }
393
+
394
+ this.container.addClass('opens' + this.opens);
395
+
396
+ //swap the position of the predefined ranges if opens right
397
+ if (typeof options.ranges !== 'undefined' && this.opens == 'right') {
398
+ this.container.find('.ranges').prependTo( this.container.find('.calendar.left').parent() );
399
+ }
400
+
401
+ //apply CSS classes and labels to buttons
402
+ this.container.find('.applyBtn, .cancelBtn').addClass(this.buttonClasses);
403
+ if (this.applyClass.length)
404
+ this.container.find('.applyBtn').addClass(this.applyClass);
405
+ if (this.cancelClass.length)
406
+ this.container.find('.cancelBtn').addClass(this.cancelClass);
407
+ this.container.find('.applyBtn').html(this.locale.applyLabel);
408
+ this.container.find('.cancelBtn').html(this.locale.cancelLabel);
409
+
410
+ //
411
+ // event listeners
412
+ //
413
+
414
+ this.container.find('.calendar')
415
+ .on('click.daterangepicker', '.prev', $.proxy(this.clickPrev, this))
416
+ .on('click.daterangepicker', '.next', $.proxy(this.clickNext, this))
417
+ .on('mousedown.daterangepicker', 'td.available', $.proxy(this.clickDate, this))
418
+ .on('mouseenter.daterangepicker', 'td.available', $.proxy(this.hoverDate, this))
419
+ .on('mouseleave.daterangepicker', 'td.available', $.proxy(this.updateFormInputs, this))
420
+ .on('change.daterangepicker', 'select.yearselect', $.proxy(this.monthOrYearChanged, this))
421
+ .on('change.daterangepicker', 'select.monthselect', $.proxy(this.monthOrYearChanged, this))
422
+ .on('change.daterangepicker', 'select.hourselect,select.minuteselect,select.secondselect,select.ampmselect', $.proxy(this.timeChanged, this))
423
+ .on('click.daterangepicker', '.daterangepicker_input input', $.proxy(this.showCalendars, this))
424
+ .on('focus.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsFocused, this))
425
+ .on('blur.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsBlurred, this))
426
+ .on('change.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsChanged, this));
427
+
428
+ this.container.find('.ranges')
429
+ .on('click.daterangepicker', 'button.applyBtn', $.proxy(this.clickApply, this))
430
+ .on('click.daterangepicker', 'button.cancelBtn', $.proxy(this.clickCancel, this))
431
+ .on('click.daterangepicker', 'li', $.proxy(this.clickRange, this))
432
+ .on('mouseenter.daterangepicker', 'li', $.proxy(this.hoverRange, this))
433
+ .on('mouseleave.daterangepicker', 'li', $.proxy(this.updateFormInputs, this));
434
+
435
+ if (this.element.is('input') || this.element.is('button')) {
436
+ this.element.on({
437
+ 'click.daterangepicker': $.proxy(this.show, this),
438
+ 'focus.daterangepicker': $.proxy(this.show, this),
439
+ 'keyup.daterangepicker': $.proxy(this.elementChanged, this),
440
+ 'keydown.daterangepicker': $.proxy(this.keydown, this)
441
+ });
442
+ } else {
443
+ this.element.on('click.daterangepicker', $.proxy(this.toggle, this));
444
+ }
445
+
446
+ //
447
+ // if attached to a text input, set the initial value
448
+ //
449
+
450
+ if (this.element.is('input') && !this.singleDatePicker && this.autoUpdateInput) {
451
+ this.element.val(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));
452
+ this.element.trigger('change');
453
+ } else if (this.element.is('input') && this.autoUpdateInput) {
454
+ this.element.val(this.startDate.format(this.locale.format));
455
+ this.element.trigger('change');
456
+ }
457
+
458
+ };
459
+
460
+ DateRangePicker.prototype = {
461
+
462
+ constructor: DateRangePicker,
463
+
464
+ setStartDate: function(startDate) {
465
+ if (typeof startDate === 'string')
466
+ this.startDate = moment(startDate, this.locale.format);
467
+
468
+ if (typeof startDate === 'object')
469
+ this.startDate = moment(startDate);
470
+
471
+ if (!this.timePicker)
472
+ this.startDate = this.startDate.startOf('day');
473
+
474
+ if (this.timePicker && this.timePickerIncrement)
475
+ this.startDate.minute(Math.round(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
476
+
477
+ if (this.minDate && this.startDate.isBefore(this.minDate)) {
478
+ this.startDate = this.minDate.clone();
479
+ if (this.timePicker && this.timePickerIncrement)
480
+ this.startDate.minute(Math.round(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
481
+ }
482
+
483
+ if (this.maxDate && this.startDate.isAfter(this.maxDate)) {
484
+ this.startDate = this.maxDate.clone();
485
+ if (this.timePicker && this.timePickerIncrement)
486
+ this.startDate.minute(Math.floor(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
487
+ }
488
+
489
+ if (!this.isShowing)
490
+ this.updateElement();
491
+
492
+ this.updateMonthsInView();
493
+ },
494
+
495
+ setEndDate: function(endDate) {
496
+ if (typeof endDate === 'string')
497
+ this.endDate = moment(endDate, this.locale.format);
498
+
499
+ if (typeof endDate === 'object')
500
+ this.endDate = moment(endDate);
501
+
502
+ if (!this.timePicker)
503
+ this.endDate = this.endDate.endOf('day');
504
+
505
+ if (this.timePicker && this.timePickerIncrement)
506
+ this.endDate.minute(Math.round(this.endDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
507
+
508
+ if (this.endDate.isBefore(this.startDate))
509
+ this.endDate = this.startDate.clone();
510
+
511
+ if (this.maxDate && this.endDate.isAfter(this.maxDate))
512
+ this.endDate = this.maxDate.clone();
513
+
514
+ if (this.dateLimit && this.startDate.clone().add(this.dateLimit).isBefore(this.endDate))
515
+ this.endDate = this.startDate.clone().add(this.dateLimit);
516
+
517
+ this.previousRightTime = this.endDate.clone();
518
+
519
+ if (!this.isShowing)
520
+ this.updateElement();
521
+
522
+ this.updateMonthsInView();
523
+ },
524
+
525
+ isInvalidDate: function() {
526
+ return false;
527
+ },
528
+
529
+ isCustomDate: function() {
530
+ return false;
531
+ },
532
+
533
+ updateView: function() {
534
+ if (this.timePicker) {
535
+ this.renderTimePicker('left');
536
+ this.renderTimePicker('right');
537
+ if (!this.endDate) {
538
+ this.container.find('.right .calendar-time select').attr('disabled', 'disabled').addClass('disabled');
539
+ } else {
540
+ this.container.find('.right .calendar-time select').removeAttr('disabled').removeClass('disabled');
541
+ }
542
+ }
543
+ if (this.endDate) {
544
+ this.container.find('input[name="daterangepicker_end"]').removeClass('active');
545
+ this.container.find('input[name="daterangepicker_start"]').addClass('active');
546
+ } else {
547
+ this.container.find('input[name="daterangepicker_end"]').addClass('active');
548
+ this.container.find('input[name="daterangepicker_start"]').removeClass('active');
549
+ }
550
+ this.updateMonthsInView();
551
+ this.updateCalendars();
552
+ this.updateFormInputs();
553
+ },
554
+
555
+ updateMonthsInView: function() {
556
+ if (this.endDate) {
557
+
558
+ //if both dates are visible already, do nothing
559
+ if (!this.singleDatePicker && this.leftCalendar.month && this.rightCalendar.month &&
560
+ (this.startDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.startDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM'))
561
+ &&
562
+ (this.endDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.endDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM'))
563
+ ) {
564
+ return;
565
+ }
566
+
567
+ this.leftCalendar.month = this.startDate.clone().date(2);
568
+ if (!this.linkedCalendars && (this.endDate.month() != this.startDate.month() || this.endDate.year() != this.startDate.year())) {
569
+ this.rightCalendar.month = this.endDate.clone().date(2);
570
+ } else {
571
+ this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month');
572
+ }
573
+
574
+ } else {
575
+ if (this.leftCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM') && this.rightCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM')) {
576
+ this.leftCalendar.month = this.startDate.clone().date(2);
577
+ this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month');
578
+ }
579
+ }
580
+ if (this.maxDate && this.linkedCalendars && !this.singleDatePicker && this.rightCalendar.month > this.maxDate) {
581
+ this.rightCalendar.month = this.maxDate.clone().date(2);
582
+ this.leftCalendar.month = this.maxDate.clone().date(2).subtract(1, 'month');
583
+ }
584
+ },
585
+
586
+ updateCalendars: function() {
587
+
588
+ if (this.timePicker) {
589
+ var hour, minute, second;
590
+ if (this.endDate) {
591
+ hour = parseInt(this.container.find('.left .hourselect').val(), 10);
592
+ minute = parseInt(this.container.find('.left .minuteselect').val(), 10);
593
+ second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0;
594
+ if (!this.timePicker24Hour) {
595
+ var ampm = this.container.find('.left .ampmselect').val();
596
+ if (ampm === 'PM' && hour < 12)
597
+ hour += 12;
598
+ if (ampm === 'AM' && hour === 12)
599
+ hour = 0;
600
+ }
601
+ } else {
602
+ hour = parseInt(this.container.find('.right .hourselect').val(), 10);
603
+ minute = parseInt(this.container.find('.right .minuteselect').val(), 10);
604
+ second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;
605
+ if (!this.timePicker24Hour) {
606
+ var ampm = this.container.find('.right .ampmselect').val();
607
+ if (ampm === 'PM' && hour < 12)
608
+ hour += 12;
609
+ if (ampm === 'AM' && hour === 12)
610
+ hour = 0;
611
+ }
612
+ }
613
+ this.leftCalendar.month.hour(hour).minute(minute).second(second);
614
+ this.rightCalendar.month.hour(hour).minute(minute).second(second);
615
+ }
616
+
617
+ this.renderCalendar('left');
618
+ this.renderCalendar('right');
619
+
620
+ //highlight any predefined range matching the current start and end dates
621
+ this.container.find('.ranges li').removeClass('active');
622
+ if (this.endDate == null) return;
623
+
624
+ this.calculateChosenLabel();
625
+ },
626
+
627
+ renderCalendar: function(side) {
628
+
629
+ //
630
+ // Build the matrix of dates that will populate the calendar
631
+ //
632
+
633
+ var calendar = side == 'left' ? this.leftCalendar : this.rightCalendar;
634
+ var month = calendar.month.month();
635
+ var year = calendar.month.year();
636
+ var hour = calendar.month.hour();
637
+ var minute = calendar.month.minute();
638
+ var second = calendar.month.second();
639
+ var daysInMonth = moment([year, month]).daysInMonth();
640
+ var firstDay = moment([year, month, 1]);
641
+ var lastDay = moment([year, month, daysInMonth]);
642
+ var lastMonth = moment(firstDay).subtract(1, 'month').month();
643
+ var lastYear = moment(firstDay).subtract(1, 'month').year();
644
+ var daysInLastMonth = moment([lastYear, lastMonth]).daysInMonth();
645
+ var dayOfWeek = firstDay.day();
646
+
647
+ //initialize a 6 rows x 7 columns array for the calendar
648
+ var calendar = [];
649
+ calendar.firstDay = firstDay;
650
+ calendar.lastDay = lastDay;
651
+
652
+ for (var i = 0; i < 6; i++) {
653
+ calendar[i] = [];
654
+ }
655
+
656
+ //populate the calendar with date objects
657
+ var startDay = daysInLastMonth - dayOfWeek + this.locale.firstDay + 1;
658
+ if (startDay > daysInLastMonth)
659
+ startDay -= 7;
660
+
661
+ if (dayOfWeek == this.locale.firstDay)
662
+ startDay = daysInLastMonth - 6;
663
+
664
+ var curDate = moment([lastYear, lastMonth, startDay, 12, minute, second]);
665
+
666
+ var col, row;
667
+ for (var i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add(24, 'hour')) {
668
+ if (i > 0 && col % 7 === 0) {
669
+ col = 0;
670
+ row++;
671
+ }
672
+ calendar[row][col] = curDate.clone().hour(hour).minute(minute).second(second);
673
+ curDate.hour(12);
674
+
675
+ if (this.minDate && calendar[row][col].format('YYYY-MM-DD') == this.minDate.format('YYYY-MM-DD') && calendar[row][col].isBefore(this.minDate) && side == 'left') {
676
+ calendar[row][col] = this.minDate.clone();
677
+ }
678
+
679
+ if (this.maxDate && calendar[row][col].format('YYYY-MM-DD') == this.maxDate.format('YYYY-MM-DD') && calendar[row][col].isAfter(this.maxDate) && side == 'right') {
680
+ calendar[row][col] = this.maxDate.clone();
681
+ }
682
+
683
+ }
684
+
685
+ //make the calendar object available to hoverDate/clickDate
686
+ if (side == 'left') {
687
+ this.leftCalendar.calendar = calendar;
688
+ } else {
689
+ this.rightCalendar.calendar = calendar;
690
+ }
691
+
692
+ //
693
+ // Display the calendar
694
+ //
695
+
696
+ var minDate = side == 'left' ? this.minDate : this.startDate;
697
+ var maxDate = this.maxDate;
698
+ var selected = side == 'left' ? this.startDate : this.endDate;
699
+ var arrow = this.locale.direction == 'ltr' ? {left: 'chevron-left', right: 'chevron-right'} : {left: 'chevron-right', right: 'chevron-left'};
700
+
701
+ var html = '<table class="table-condensed">';
702
+ html += '<thead>';
703
+ html += '<tr>';
704
+
705
+ // add empty cell for week number
706
+ if (this.showWeekNumbers || this.showISOWeekNumbers)
707
+ html += '<th></th>';
708
+
709
+ if ((!minDate || minDate.isBefore(calendar.firstDay)) && (!this.linkedCalendars || side == 'left')) {
710
+ html += '<th class="prev available"><i class="fa fa-' + arrow.left + ' glyphicon glyphicon-' + arrow.left + '"></i></th>';
711
+ } else {
712
+ html += '<th></th>';
713
+ }
714
+
715
+ var dateHtml = this.locale.monthNames[calendar[1][1].month()] + calendar[1][1].format(" YYYY");
716
+
717
+ if (this.showDropdowns) {
718
+ var currentMonth = calendar[1][1].month();
719
+ var currentYear = calendar[1][1].year();
720
+ var maxYear = (maxDate && maxDate.year()) || (currentYear + 5);
721
+ var minYear = (minDate && minDate.year()) || (currentYear - 50);
722
+ var inMinYear = currentYear == minYear;
723
+ var inMaxYear = currentYear == maxYear;
724
+
725
+ var monthHtml = '<select class="monthselect">';
726
+ for (var m = 0; m < 12; m++) {
727
+ if ((!inMinYear || m >= minDate.month()) && (!inMaxYear || m <= maxDate.month())) {
728
+ monthHtml += "<option value='" + m + "'" +
729
+ (m === currentMonth ? " selected='selected'" : "") +
730
+ ">" + this.locale.monthNames[m] + "</option>";
731
+ } else {
732
+ monthHtml += "<option value='" + m + "'" +
733
+ (m === currentMonth ? " selected='selected'" : "") +
734
+ " disabled='disabled'>" + this.locale.monthNames[m] + "</option>";
735
+ }
736
+ }
737
+ monthHtml += "</select>";
738
+
739
+ var yearHtml = '<select class="yearselect">';
740
+ for (var y = minYear; y <= maxYear; y++) {
741
+ yearHtml += '<option value="' + y + '"' +
742
+ (y === currentYear ? ' selected="selected"' : '') +
743
+ '>' + y + '</option>';
744
+ }
745
+ yearHtml += '</select>';
746
+
747
+ dateHtml = monthHtml + yearHtml;
748
+ }
749
+
750
+ html += '<th colspan="5" class="month">' + dateHtml + '</th>';
751
+ if ((!maxDate || maxDate.isAfter(calendar.lastDay)) && (!this.linkedCalendars || side == 'right' || this.singleDatePicker)) {
752
+ html += '<th class="next available"><i class="fa fa-' + arrow.right + ' glyphicon glyphicon-' + arrow.right + '"></i></th>';
753
+ } else {
754
+ html += '<th></th>';
755
+ }
756
+
757
+ html += '</tr>';
758
+ html += '<tr>';
759
+
760
+ // add week number label
761
+ if (this.showWeekNumbers || this.showISOWeekNumbers)
762
+ html += '<th class="week">' + this.locale.weekLabel + '</th>';
763
+
764
+ $.each(this.locale.daysOfWeek, function(index, dayOfWeek) {
765
+ html += '<th>' + dayOfWeek + '</th>';
766
+ });
767
+
768
+ html += '</tr>';
769
+ html += '</thead>';
770
+ html += '<tbody>';
771
+
772
+ //adjust maxDate to reflect the dateLimit setting in order to
773
+ //grey out end dates beyond the dateLimit
774
+ if (this.endDate == null && this.dateLimit) {
775
+ var maxLimit = this.startDate.clone().add(this.dateLimit).endOf('day');
776
+ if (!maxDate || maxLimit.isBefore(maxDate)) {
777
+ maxDate = maxLimit;
778
+ }
779
+ }
780
+
781
+ for (var row = 0; row < 6; row++) {
782
+ html += '<tr>';
783
+
784
+ // add week number
785
+ if (this.showWeekNumbers)
786
+ html += '<td class="week">' + calendar[row][0].week() + '</td>';
787
+ else if (this.showISOWeekNumbers)
788
+ html += '<td class="week">' + calendar[row][0].isoWeek() + '</td>';
789
+
790
+ for (var col = 0; col < 7; col++) {
791
+
792
+ var classes = [];
793
+
794
+ //highlight today's date
795
+ if (calendar[row][col].isSame(new Date(), "day"))
796
+ classes.push('today');
797
+
798
+ //highlight weekends
799
+ if (calendar[row][col].isoWeekday() > 5)
800
+ classes.push('weekend');
801
+
802
+ //grey out the dates in other months displayed at beginning and end of this calendar
803
+ if (calendar[row][col].month() != calendar[1][1].month())
804
+ classes.push('off');
805
+
806
+ //don't allow selection of dates before the minimum date
807
+ if (this.minDate && calendar[row][col].isBefore(this.minDate, 'day'))
808
+ classes.push('off', 'disabled');
809
+
810
+ //don't allow selection of dates after the maximum date
811
+ if (maxDate && calendar[row][col].isAfter(maxDate, 'day'))
812
+ classes.push('off', 'disabled');
813
+
814
+ //don't allow selection of date if a custom function decides it's invalid
815
+ if (this.isInvalidDate(calendar[row][col]))
816
+ classes.push('off', 'disabled');
817
+
818
+ //highlight the currently selected start date
819
+ if (calendar[row][col].format('YYYY-MM-DD') == this.startDate.format('YYYY-MM-DD'))
820
+ classes.push('active', 'start-date');
821
+
822
+ //highlight the currently selected end date
823
+ if (this.endDate != null && calendar[row][col].format('YYYY-MM-DD') == this.endDate.format('YYYY-MM-DD'))
824
+ classes.push('active', 'end-date');
825
+
826
+ //highlight dates in-between the selected dates
827
+ if (this.endDate != null && calendar[row][col] > this.startDate && calendar[row][col] < this.endDate)
828
+ classes.push('in-range');
829
+
830
+ //apply custom classes for this date
831
+ var isCustom = this.isCustomDate(calendar[row][col]);
832
+ if (isCustom !== false) {
833
+ if (typeof isCustom === 'string')
834
+ classes.push(isCustom);
835
+ else
836
+ Array.prototype.push.apply(classes, isCustom);
837
+ }
838
+
839
+ var cname = '', disabled = false;
840
+ for (var i = 0; i < classes.length; i++) {
841
+ cname += classes[i] + ' ';
842
+ if (classes[i] == 'disabled')
843
+ disabled = true;
844
+ }
845
+ if (!disabled)
846
+ cname += 'available';
847
+
848
+ html += '<td class="' + cname.replace(/^\s+|\s+$/g, '') + '" data-title="' + 'r' + row + 'c' + col + '">' + calendar[row][col].date() + '</td>';
849
+
850
+ }
851
+ html += '</tr>';
852
+ }
853
+
854
+ html += '</tbody>';
855
+ html += '</table>';
856
+
857
+ this.container.find('.calendar.' + side + ' .calendar-table').html(html);
858
+
859
+ },
860
+
861
+ renderTimePicker: function(side) {
862
+
863
+ // Don't bother updating the time picker if it's currently disabled
864
+ // because an end date hasn't been clicked yet
865
+ if (side == 'right' && !this.endDate) return;
866
+
867
+ var html, selected, minDate, maxDate = this.maxDate;
868
+
869
+ if (this.dateLimit && (!this.maxDate || this.startDate.clone().add(this.dateLimit).isAfter(this.maxDate)))
870
+ maxDate = this.startDate.clone().add(this.dateLimit);
871
+
872
+ if (side == 'left') {
873
+ selected = this.startDate.clone();
874
+ minDate = this.minDate;
875
+ } else if (side == 'right') {
876
+ selected = this.endDate.clone();
877
+ minDate = this.startDate;
878
+
879
+ //Preserve the time already selected
880
+ var timeSelector = this.container.find('.calendar.right .calendar-time div');
881
+ if (timeSelector.html() != '') {
882
+
883
+ selected.hour(timeSelector.find('.hourselect option:selected').val() || selected.hour());
884
+ selected.minute(timeSelector.find('.minuteselect option:selected').val() || selected.minute());
885
+ selected.second(timeSelector.find('.secondselect option:selected').val() || selected.second());
886
+
887
+ if (!this.timePicker24Hour) {
888
+ var ampm = timeSelector.find('.ampmselect option:selected').val();
889
+ if (ampm === 'PM' && selected.hour() < 12)
890
+ selected.hour(selected.hour() + 12);
891
+ if (ampm === 'AM' && selected.hour() === 12)
892
+ selected.hour(0);
893
+ }
894
+
895
+ }
896
+
897
+ if (selected.isBefore(this.startDate))
898
+ selected = this.startDate.clone();
899
+
900
+ if (maxDate && selected.isAfter(maxDate))
901
+ selected = maxDate.clone();
902
+
903
+ }
904
+
905
+ //
906
+ // hours
907
+ //
908
+
909
+ html = '<select class="hourselect">';
910
+
911
+ var start = this.timePicker24Hour ? 0 : 1;
912
+ var end = this.timePicker24Hour ? 23 : 12;
913
+
914
+ for (var i = start; i <= end; i++) {
915
+ var i_in_24 = i;
916
+ if (!this.timePicker24Hour)
917
+ i_in_24 = selected.hour() >= 12 ? (i == 12 ? 12 : i + 12) : (i == 12 ? 0 : i);
918
+
919
+ var time = selected.clone().hour(i_in_24);
920
+ var disabled = false;
921
+ if (minDate && time.minute(59).isBefore(minDate))
922
+ disabled = true;
923
+ if (maxDate && time.minute(0).isAfter(maxDate))
924
+ disabled = true;
925
+
926
+ if (i_in_24 == selected.hour() && !disabled) {
927
+ html += '<option value="' + i + '" selected="selected">' + i + '</option>';
928
+ } else if (disabled) {
929
+ html += '<option value="' + i + '" disabled="disabled" class="disabled">' + i + '</option>';
930
+ } else {
931
+ html += '<option value="' + i + '">' + i + '</option>';
932
+ }
933
+ }
934
+
935
+ html += '</select> ';
936
+
937
+ //
938
+ // minutes
939
+ //
940
+
941
+ html += ': <select class="minuteselect">';
942
+
943
+ for (var i = 0; i < 60; i += this.timePickerIncrement) {
944
+ var padded = i < 10 ? '0' + i : i;
945
+ var time = selected.clone().minute(i);
946
+
947
+ var disabled = false;
948
+ if (minDate && time.second(59).isBefore(minDate))
949
+ disabled = true;
950
+ if (maxDate && time.second(0).isAfter(maxDate))
951
+ disabled = true;
952
+
953
+ if (selected.minute() == i && !disabled) {
954
+ html += '<option value="' + i + '" selected="selected">' + padded + '</option>';
955
+ } else if (disabled) {
956
+ html += '<option value="' + i + '" disabled="disabled" class="disabled">' + padded + '</option>';
957
+ } else {
958
+ html += '<option value="' + i + '">' + padded + '</option>';
959
+ }
960
+ }
961
+
962
+ html += '</select> ';
963
+
964
+ //
965
+ // seconds
966
+ //
967
+
968
+ if (this.timePickerSeconds) {
969
+ html += ': <select class="secondselect">';
970
+
971
+ for (var i = 0; i < 60; i++) {
972
+ var padded = i < 10 ? '0' + i : i;
973
+ var time = selected.clone().second(i);
974
+
975
+ var disabled = false;
976
+ if (minDate && time.isBefore(minDate))
977
+ disabled = true;
978
+ if (maxDate && time.isAfter(maxDate))
979
+ disabled = true;
980
+
981
+ if (selected.second() == i && !disabled) {
982
+ html += '<option value="' + i + '" selected="selected">' + padded + '</option>';
983
+ } else if (disabled) {
984
+ html += '<option value="' + i + '" disabled="disabled" class="disabled">' + padded + '</option>';
985
+ } else {
986
+ html += '<option value="' + i + '">' + padded + '</option>';
987
+ }
988
+ }
989
+
990
+ html += '</select> ';
991
+ }
992
+
993
+ //
994
+ // AM/PM
995
+ //
996
+
997
+ if (!this.timePicker24Hour) {
998
+ html += '<select class="ampmselect">';
999
+
1000
+ var am_html = '';
1001
+ var pm_html = '';
1002
+
1003
+ if (minDate && selected.clone().hour(12).minute(0).second(0).isBefore(minDate))
1004
+ am_html = ' disabled="disabled" class="disabled"';
1005
+
1006
+ if (maxDate && selected.clone().hour(0).minute(0).second(0).isAfter(maxDate))
1007
+ pm_html = ' disabled="disabled" class="disabled"';
1008
+
1009
+ if (selected.hour() >= 12) {
1010
+ html += '<option value="AM"' + am_html + '>AM</option><option value="PM" selected="selected"' + pm_html + '>PM</option>';
1011
+ } else {
1012
+ html += '<option value="AM" selected="selected"' + am_html + '>AM</option><option value="PM"' + pm_html + '>PM</option>';
1013
+ }
1014
+
1015
+ html += '</select>';
1016
+ }
1017
+
1018
+ this.container.find('.calendar.' + side + ' .calendar-time div').html(html);
1019
+
1020
+ },
1021
+
1022
+ updateFormInputs: function() {
1023
+
1024
+ //ignore mouse movements while an above-calendar text input has focus
1025
+ if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus"))
1026
+ return;
1027
+
1028
+ this.container.find('input[name=daterangepicker_start]').val(this.startDate.format(this.locale.format));
1029
+ if (this.endDate)
1030
+ this.container.find('input[name=daterangepicker_end]').val(this.endDate.format(this.locale.format));
1031
+
1032
+ if (this.singleDatePicker || (this.endDate && (this.startDate.isBefore(this.endDate) || this.startDate.isSame(this.endDate)))) {
1033
+ this.container.find('button.applyBtn').removeAttr('disabled');
1034
+ } else {
1035
+ this.container.find('button.applyBtn').attr('disabled', 'disabled');
1036
+ }
1037
+
1038
+ },
1039
+
1040
+ move: function() {
1041
+ var parentOffset = { top: 0, left: 0 },
1042
+ containerTop;
1043
+ var parentRightEdge = $(window).width();
1044
+ if (!this.parentEl.is('body')) {
1045
+ parentOffset = {
1046
+ top: this.parentEl.offset().top - this.parentEl.scrollTop(),
1047
+ left: this.parentEl.offset().left - this.parentEl.scrollLeft()
1048
+ };
1049
+ parentRightEdge = this.parentEl[0].clientWidth + this.parentEl.offset().left;
1050
+ }
1051
+
1052
+ if (this.drops == 'up')
1053
+ containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top;
1054
+ else
1055
+ containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top;
1056
+ this.container[this.drops == 'up' ? 'addClass' : 'removeClass']('dropup');
1057
+
1058
+ if (this.opens == 'left') {
1059
+ this.container.css({
1060
+ top: containerTop,
1061
+ right: parentRightEdge - this.element.offset().left - this.element.outerWidth(),
1062
+ left: 'auto'
1063
+ });
1064
+ if (this.container.offset().left < 0) {
1065
+ this.container.css({
1066
+ right: 'auto',
1067
+ left: 9
1068
+ });
1069
+ }
1070
+ } else if (this.opens == 'center') {
1071
+ this.container.css({
1072
+ top: containerTop,
1073
+ left: this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2
1074
+ - this.container.outerWidth() / 2,
1075
+ right: 'auto'
1076
+ });
1077
+ if (this.container.offset().left < 0) {
1078
+ this.container.css({
1079
+ right: 'auto',
1080
+ left: 9
1081
+ });
1082
+ }
1083
+ } else {
1084
+ this.container.css({
1085
+ top: containerTop,
1086
+ left: this.element.offset().left - parentOffset.left,
1087
+ right: 'auto'
1088
+ });
1089
+ if (this.container.offset().left + this.container.outerWidth() > $(window).width()) {
1090
+ this.container.css({
1091
+ left: 'auto',
1092
+ right: 0
1093
+ });
1094
+ }
1095
+ }
1096
+ },
1097
+
1098
+ show: function(e) {
1099
+ if (this.isShowing) return;
1100
+
1101
+ // Create a click proxy that is private to this instance of datepicker, for unbinding
1102
+ this._outsideClickProxy = $.proxy(function(e) { this.outsideClick(e); }, this);
1103
+
1104
+ // Bind global datepicker mousedown for hiding and
1105
+ $(document)
1106
+ .on('mousedown.daterangepicker', this._outsideClickProxy)
1107
+ // also support mobile devices
1108
+ .on('touchend.daterangepicker', this._outsideClickProxy)
1109
+ // also explicitly play nice with Bootstrap dropdowns, which stopPropagation when clicking them
1110
+ .on('click.daterangepicker', '[data-toggle=dropdown]', this._outsideClickProxy)
1111
+ // and also close when focus changes to outside the picker (eg. tabbing between controls)
1112
+ .on('focusin.daterangepicker', this._outsideClickProxy);
1113
+
1114
+ // Reposition the picker if the window is resized while it's open
1115
+ $(window).on('resize.daterangepicker', $.proxy(function(e) { this.move(e); }, this));
1116
+
1117
+ this.oldStartDate = this.startDate.clone();
1118
+ this.oldEndDate = this.endDate.clone();
1119
+ this.previousRightTime = this.endDate.clone();
1120
+
1121
+ this.updateView();
1122
+ this.container.show();
1123
+ this.move();
1124
+ this.element.trigger('show.daterangepicker', this);
1125
+ this.isShowing = true;
1126
+ },
1127
+
1128
+ hide: function(e) {
1129
+ if (!this.isShowing) return;
1130
+
1131
+ //incomplete date selection, revert to last values
1132
+ if (!this.endDate) {
1133
+ this.startDate = this.oldStartDate.clone();
1134
+ this.endDate = this.oldEndDate.clone();
1135
+ }
1136
+
1137
+ //if a new date range was selected, invoke the user callback function
1138
+ if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))
1139
+ this.callback(this.startDate, this.endDate, this.chosenLabel);
1140
+
1141
+ //if picker is attached to a text input, update it
1142
+ this.updateElement();
1143
+
1144
+ $(document).off('.daterangepicker');
1145
+ $(window).off('.daterangepicker');
1146
+ this.container.hide();
1147
+ this.element.trigger('hide.daterangepicker', this);
1148
+ this.isShowing = false;
1149
+ },
1150
+
1151
+ toggle: function(e) {
1152
+ if (this.isShowing) {
1153
+ this.hide();
1154
+ } else {
1155
+ this.show();
1156
+ }
1157
+ },
1158
+
1159
+ outsideClick: function(e) {
1160
+ var target = $(e.target);
1161
+ // if the page is clicked anywhere except within the daterangerpicker/button
1162
+ // itself then call this.hide()
1163
+ if (
1164
+ // ie modal dialog fix
1165
+ e.type == "focusin" ||
1166
+ target.closest(this.element).length ||
1167
+ target.closest(this.container).length ||
1168
+ target.closest('.calendar-table').length
1169
+ ) return;
1170
+ this.hide();
1171
+ this.element.trigger('outsideClick.daterangepicker', this);
1172
+ },
1173
+
1174
+ showCalendars: function() {
1175
+ this.container.addClass('show-calendar');
1176
+ this.move();
1177
+ this.element.trigger('showCalendar.daterangepicker', this);
1178
+ },
1179
+
1180
+ hideCalendars: function() {
1181
+ this.container.removeClass('show-calendar');
1182
+ this.element.trigger('hideCalendar.daterangepicker', this);
1183
+ },
1184
+
1185
+ hoverRange: function(e) {
1186
+
1187
+ //ignore mouse movements while an above-calendar text input has focus
1188
+ if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus"))
1189
+ return;
1190
+
1191
+ var label = e.target.getAttribute('data-range-key');
1192
+
1193
+ if (label == this.locale.customRangeLabel) {
1194
+ this.updateView();
1195
+ } else {
1196
+ var dates = this.ranges[label];
1197
+ this.container.find('input[name=daterangepicker_start]').val(dates[0].format(this.locale.format));
1198
+ this.container.find('input[name=daterangepicker_end]').val(dates[1].format(this.locale.format));
1199
+ }
1200
+
1201
+ },
1202
+
1203
+ clickRange: function(e) {
1204
+ var label = e.target.getAttribute('data-range-key');
1205
+ this.chosenLabel = label;
1206
+ if (label == this.locale.customRangeLabel) {
1207
+ this.showCalendars();
1208
+ } else {
1209
+ var dates = this.ranges[label];
1210
+ this.startDate = dates[0];
1211
+ this.endDate = dates[1];
1212
+
1213
+ if (!this.timePicker) {
1214
+ this.startDate.startOf('day');
1215
+ this.endDate.endOf('day');
1216
+ }
1217
+
1218
+ if (!this.alwaysShowCalendars)
1219
+ this.hideCalendars();
1220
+ this.clickApply();
1221
+ }
1222
+ },
1223
+
1224
+ clickPrev: function(e) {
1225
+ var cal = $(e.target).parents('.calendar');
1226
+ if (cal.hasClass('left')) {
1227
+ this.leftCalendar.month.subtract(1, 'month');
1228
+ if (this.linkedCalendars)
1229
+ this.rightCalendar.month.subtract(1, 'month');
1230
+ } else {
1231
+ this.rightCalendar.month.subtract(1, 'month');
1232
+ }
1233
+ this.updateCalendars();
1234
+ },
1235
+
1236
+ clickNext: function(e) {
1237
+ var cal = $(e.target).parents('.calendar');
1238
+ if (cal.hasClass('left')) {
1239
+ this.leftCalendar.month.add(1, 'month');
1240
+ } else {
1241
+ this.rightCalendar.month.add(1, 'month');
1242
+ if (this.linkedCalendars)
1243
+ this.leftCalendar.month.add(1, 'month');
1244
+ }
1245
+ this.updateCalendars();
1246
+ },
1247
+
1248
+ hoverDate: function(e) {
1249
+
1250
+ //ignore mouse movements while an above-calendar text input has focus
1251
+ //if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus"))
1252
+ // return;
1253
+
1254
+ //ignore dates that can't be selected
1255
+ if (!$(e.target).hasClass('available')) return;
1256
+
1257
+ //have the text inputs above calendars reflect the date being hovered over
1258
+ var title = $(e.target).attr('data-title');
1259
+ var row = title.substr(1, 1);
1260
+ var col = title.substr(3, 1);
1261
+ var cal = $(e.target).parents('.calendar');
1262
+ var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];
1263
+
1264
+ if (this.endDate && !this.container.find('input[name=daterangepicker_start]').is(":focus")) {
1265
+ this.container.find('input[name=daterangepicker_start]').val(date.format(this.locale.format));
1266
+ } else if (!this.endDate && !this.container.find('input[name=daterangepicker_end]').is(":focus")) {
1267
+ this.container.find('input[name=daterangepicker_end]').val(date.format(this.locale.format));
1268
+ }
1269
+
1270
+ //highlight the dates between the start date and the date being hovered as a potential end date
1271
+ var leftCalendar = this.leftCalendar;
1272
+ var rightCalendar = this.rightCalendar;
1273
+ var startDate = this.startDate;
1274
+ if (!this.endDate) {
1275
+ this.container.find('.calendar tbody td').each(function(index, el) {
1276
+
1277
+ //skip week numbers, only look at dates
1278
+ if ($(el).hasClass('week')) return;
1279
+
1280
+ var title = $(el).attr('data-title');
1281
+ var row = title.substr(1, 1);
1282
+ var col = title.substr(3, 1);
1283
+ var cal = $(el).parents('.calendar');
1284
+ var dt = cal.hasClass('left') ? leftCalendar.calendar[row][col] : rightCalendar.calendar[row][col];
1285
+
1286
+ if ((dt.isAfter(startDate) && dt.isBefore(date)) || dt.isSame(date, 'day')) {
1287
+ $(el).addClass('in-range');
1288
+ } else {
1289
+ $(el).removeClass('in-range');
1290
+ }
1291
+
1292
+ });
1293
+ }
1294
+
1295
+ },
1296
+
1297
+ clickDate: function(e) {
1298
+
1299
+ if (!$(e.target).hasClass('available')) return;
1300
+
1301
+ var title = $(e.target).attr('data-title');
1302
+ var row = title.substr(1, 1);
1303
+ var col = title.substr(3, 1);
1304
+ var cal = $(e.target).parents('.calendar');
1305
+ var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];
1306
+
1307
+ //
1308
+ // this function needs to do a few things:
1309
+ // * alternate between selecting a start and end date for the range,
1310
+ // * if the time picker is enabled, apply the hour/minute/second from the select boxes to the clicked date
1311
+ // * if autoapply is enabled, and an end date was chosen, apply the selection
1312
+ // * if single date picker mode, and time picker isn't enabled, apply the selection immediately
1313
+ // * if one of the inputs above the calendars was focused, cancel that manual input
1314
+ //
1315
+
1316
+ if (this.endDate || date.isBefore(this.startDate, 'day')) { //picking start
1317
+ if (this.timePicker) {
1318
+ var hour = parseInt(this.container.find('.left .hourselect').val(), 10);
1319
+ if (!this.timePicker24Hour) {
1320
+ var ampm = this.container.find('.left .ampmselect').val();
1321
+ if (ampm === 'PM' && hour < 12)
1322
+ hour += 12;
1323
+ if (ampm === 'AM' && hour === 12)
1324
+ hour = 0;
1325
+ }
1326
+ var minute = parseInt(this.container.find('.left .minuteselect').val(), 10);
1327
+ var second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0;
1328
+ date = date.clone().hour(hour).minute(minute).second(second);
1329
+ }
1330
+ this.endDate = null;
1331
+ this.setStartDate(date.clone());
1332
+ } else if (!this.endDate && date.isBefore(this.startDate)) {
1333
+ //special case: clicking the same date for start/end,
1334
+ //but the time of the end date is before the start date
1335
+ this.setEndDate(this.startDate.clone());
1336
+ } else { // picking end
1337
+ if (this.timePicker) {
1338
+ var hour = parseInt(this.container.find('.right .hourselect').val(), 10);
1339
+ if (!this.timePicker24Hour) {
1340
+ var ampm = this.container.find('.right .ampmselect').val();
1341
+ if (ampm === 'PM' && hour < 12)
1342
+ hour += 12;
1343
+ if (ampm === 'AM' && hour === 12)
1344
+ hour = 0;
1345
+ }
1346
+ var minute = parseInt(this.container.find('.right .minuteselect').val(), 10);
1347
+ var second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;
1348
+ date = date.clone().hour(hour).minute(minute).second(second);
1349
+ }
1350
+ this.setEndDate(date.clone());
1351
+ if (this.autoApply) {
1352
+ this.calculateChosenLabel();
1353
+ this.clickApply();
1354
+ }
1355
+ }
1356
+
1357
+ if (this.singleDatePicker) {
1358
+ this.setEndDate(this.startDate);
1359
+ if (!this.timePicker)
1360
+ this.clickApply();
1361
+ }
1362
+
1363
+ this.updateView();
1364
+
1365
+ //This is to cancel the blur event handler if the mouse was in one of the inputs
1366
+ e.stopPropagation();
1367
+
1368
+ },
1369
+
1370
+ calculateChosenLabel: function () {
1371
+ var customRange = true;
1372
+ var i = 0;
1373
+ for (var range in this.ranges) {
1374
+ if (this.timePicker) {
1375
+ if (this.startDate.isSame(this.ranges[range][0]) && this.endDate.isSame(this.ranges[range][1])) {
1376
+ customRange = false;
1377
+ this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html();
1378
+ break;
1379
+ }
1380
+ } else {
1381
+ //ignore times when comparing dates if time picker is not enabled
1382
+ if (this.startDate.format('YYYY-MM-DD') == this.ranges[range][0].format('YYYY-MM-DD') && this.endDate.format('YYYY-MM-DD') == this.ranges[range][1].format('YYYY-MM-DD')) {
1383
+ customRange = false;
1384
+ this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html();
1385
+ break;
1386
+ }
1387
+ }
1388
+ i++;
1389
+ }
1390
+ if (customRange) {
1391
+ if (this.showCustomRangeLabel) {
1392
+ this.chosenLabel = this.container.find('.ranges li:last').addClass('active').html();
1393
+ } else {
1394
+ this.chosenLabel = null;
1395
+ }
1396
+ this.showCalendars();
1397
+ }
1398
+ },
1399
+
1400
+ clickApply: function(e) {
1401
+ this.hide();
1402
+ this.element.trigger('apply.daterangepicker', this);
1403
+ },
1404
+
1405
+ clickCancel: function(e) {
1406
+ this.startDate = this.oldStartDate;
1407
+ this.endDate = this.oldEndDate;
1408
+ this.hide();
1409
+ this.element.trigger('cancel.daterangepicker', this);
1410
+ },
1411
+
1412
+ monthOrYearChanged: function(e) {
1413
+ var isLeft = $(e.target).closest('.calendar').hasClass('left'),
1414
+ leftOrRight = isLeft ? 'left' : 'right',
1415
+ cal = this.container.find('.calendar.'+leftOrRight);
1416
+
1417
+ // Month must be Number for new moment versions
1418
+ var month = parseInt(cal.find('.monthselect').val(), 10);
1419
+ var year = cal.find('.yearselect').val();
1420
+
1421
+ if (!isLeft) {
1422
+ if (year < this.startDate.year() || (year == this.startDate.year() && month < this.startDate.month())) {
1423
+ month = this.startDate.month();
1424
+ year = this.startDate.year();
1425
+ }
1426
+ }
1427
+
1428
+ if (this.minDate) {
1429
+ if (year < this.minDate.year() || (year == this.minDate.year() && month < this.minDate.month())) {
1430
+ month = this.minDate.month();
1431
+ year = this.minDate.year();
1432
+ }
1433
+ }
1434
+
1435
+ if (this.maxDate) {
1436
+ if (year > this.maxDate.year() || (year == this.maxDate.year() && month > this.maxDate.month())) {
1437
+ month = this.maxDate.month();
1438
+ year = this.maxDate.year();
1439
+ }
1440
+ }
1441
+
1442
+ if (isLeft) {
1443
+ this.leftCalendar.month.month(month).year(year);
1444
+ if (this.linkedCalendars)
1445
+ this.rightCalendar.month = this.leftCalendar.month.clone().add(1, 'month');
1446
+ } else {
1447
+ this.rightCalendar.month.month(month).year(year);
1448
+ if (this.linkedCalendars)
1449
+ this.leftCalendar.month = this.rightCalendar.month.clone().subtract(1, 'month');
1450
+ }
1451
+ this.updateCalendars();
1452
+ },
1453
+
1454
+ timeChanged: function(e) {
1455
+
1456
+ var cal = $(e.target).closest('.calendar'),
1457
+ isLeft = cal.hasClass('left');
1458
+
1459
+ var hour = parseInt(cal.find('.hourselect').val(), 10);
1460
+ var minute = parseInt(cal.find('.minuteselect').val(), 10);
1461
+ var second = this.timePickerSeconds ? parseInt(cal.find('.secondselect').val(), 10) : 0;
1462
+
1463
+ if (!this.timePicker24Hour) {
1464
+ var ampm = cal.find('.ampmselect').val();
1465
+ if (ampm === 'PM' && hour < 12)
1466
+ hour += 12;
1467
+ if (ampm === 'AM' && hour === 12)
1468
+ hour = 0;
1469
+ }
1470
+
1471
+ if (isLeft) {
1472
+ var start = this.startDate.clone();
1473
+ start.hour(hour);
1474
+ start.minute(minute);
1475
+ start.second(second);
1476
+ this.setStartDate(start);
1477
+ if (this.singleDatePicker) {
1478
+ this.endDate = this.startDate.clone();
1479
+ } else if (this.endDate && this.endDate.format('YYYY-MM-DD') == start.format('YYYY-MM-DD') && this.endDate.isBefore(start)) {
1480
+ this.setEndDate(start.clone());
1481
+ }
1482
+ } else if (this.endDate) {
1483
+ var end = this.endDate.clone();
1484
+ end.hour(hour);
1485
+ end.minute(minute);
1486
+ end.second(second);
1487
+ this.setEndDate(end);
1488
+ }
1489
+
1490
+ //update the calendars so all clickable dates reflect the new time component
1491
+ this.updateCalendars();
1492
+
1493
+ //update the form inputs above the calendars with the new time
1494
+ this.updateFormInputs();
1495
+
1496
+ //re-render the time pickers because changing one selection can affect what's enabled in another
1497
+ this.renderTimePicker('left');
1498
+ this.renderTimePicker('right');
1499
+
1500
+ },
1501
+
1502
+ formInputsChanged: function(e) {
1503
+ var isRight = $(e.target).closest('.calendar').hasClass('right');
1504
+ var start = moment(this.container.find('input[name="daterangepicker_start"]').val(), this.locale.format);
1505
+ var end = moment(this.container.find('input[name="daterangepicker_end"]').val(), this.locale.format);
1506
+
1507
+ if (start.isValid() && end.isValid()) {
1508
+
1509
+ if (isRight && end.isBefore(start))
1510
+ start = end.clone();
1511
+
1512
+ this.setStartDate(start);
1513
+ this.setEndDate(end);
1514
+
1515
+ if (isRight) {
1516
+ this.container.find('input[name="daterangepicker_start"]').val(this.startDate.format(this.locale.format));
1517
+ } else {
1518
+ this.container.find('input[name="daterangepicker_end"]').val(this.endDate.format(this.locale.format));
1519
+ }
1520
+
1521
+ }
1522
+
1523
+ this.updateView();
1524
+ },
1525
+
1526
+ formInputsFocused: function(e) {
1527
+
1528
+ // Highlight the focused input
1529
+ this.container.find('input[name="daterangepicker_start"], input[name="daterangepicker_end"]').removeClass('active');
1530
+ $(e.target).addClass('active');
1531
+
1532
+ // Set the state such that if the user goes back to using a mouse,
1533
+ // the calendars are aware we're selecting the end of the range, not
1534
+ // the start. This allows someone to edit the end of a date range without
1535
+ // re-selecting the beginning, by clicking on the end date input then
1536
+ // using the calendar.
1537
+ var isRight = $(e.target).closest('.calendar').hasClass('right');
1538
+ if (isRight) {
1539
+ this.endDate = null;
1540
+ this.setStartDate(this.startDate.clone());
1541
+ this.updateView();
1542
+ }
1543
+
1544
+ },
1545
+
1546
+ formInputsBlurred: function(e) {
1547
+
1548
+ // this function has one purpose right now: if you tab from the first
1549
+ // text input to the second in the UI, the endDate is nulled so that
1550
+ // you can click another, but if you tab out without clicking anything
1551
+ // or changing the input value, the old endDate should be retained
1552
+
1553
+ if (!this.endDate) {
1554
+ var val = this.container.find('input[name="daterangepicker_end"]').val();
1555
+ var end = moment(val, this.locale.format);
1556
+ if (end.isValid()) {
1557
+ this.setEndDate(end);
1558
+ this.updateView();
1559
+ }
1560
+ }
1561
+
1562
+ },
1563
+
1564
+ elementChanged: function() {
1565
+ if (!this.element.is('input')) return;
1566
+ if (!this.element.val().length) return;
1567
+ if (this.element.val().length < this.locale.format.length) return;
1568
+
1569
+ var dateString = this.element.val().split(this.locale.separator),
1570
+ start = null,
1571
+ end = null;
1572
+
1573
+ if (dateString.length === 2) {
1574
+ start = moment(dateString[0], this.locale.format);
1575
+ end = moment(dateString[1], this.locale.format);
1576
+ }
1577
+
1578
+ if (this.singleDatePicker || start === null || end === null) {
1579
+ start = moment(this.element.val(), this.locale.format);
1580
+ end = start;
1581
+ }
1582
+
1583
+ if (!start.isValid() || !end.isValid()) return;
1584
+
1585
+ this.setStartDate(start);
1586
+ this.setEndDate(end);
1587
+ this.updateView();
1588
+ },
1589
+
1590
+ keydown: function(e) {
1591
+ //hide on tab or enter
1592
+ if ((e.keyCode === 9) || (e.keyCode === 13)) {
1593
+ this.hide();
1594
+ }
1595
+ },
1596
+
1597
+ updateElement: function() {
1598
+ if (this.element.is('input') && !this.singleDatePicker && this.autoUpdateInput) {
1599
+ this.element.val(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));
1600
+ this.element.trigger('change');
1601
+ } else if (this.element.is('input') && this.autoUpdateInput) {
1602
+ this.element.val(this.startDate.format(this.locale.format));
1603
+ this.element.trigger('change');
1604
+ }
1605
+ },
1606
+
1607
+ remove: function() {
1608
+ this.container.remove();
1609
+ this.element.off('.daterangepicker');
1610
+ this.element.removeData();
1611
+ }
1612
+
1613
+ };
1614
+
1615
+ $.fn.daterangepicker = function(options, callback) {
1616
+ this.each(function() {
1617
+ var el = $(this);
1618
+ if (el.data('daterangepicker'))
1619
+ el.data('daterangepicker').remove();
1620
+ el.data('daterangepicker', new DateRangePicker(el, options, callback));
1621
+ });
1622
+ return this;
1623
+ };
1624
+
1625
+ return DateRangePicker;
1626
+
1627
+ }));