date_n_time_picker_activeadmin 0.1.3 → 0.1.4.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0c499d2c6bb5a56524c736bbab99d960870720ea632a4e11d70383ff7d9d2f0b
|
|
4
|
+
data.tar.gz: d452a4563e4295b4ea75a0149b2f3614710fd3aaf765c7cbfc8aa9c67278819b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cb38de6521d5c35ab529265831567f961371e3d9fd6ebc4fb80e263856f9d4cf4eeddf908fe1e73a2e7da290f05553f436ec4da783149777b2cbb0b8f871f1fb
|
|
7
|
+
data.tar.gz: 928b7948e5a9a2ac74f0f53a7eae5ad1bff3519aaec400d6b7cb6a36018e01a1995b0294927bba3bdc6b927b6afe3b8b9fa053dda7e7492592fef57027abc948
|
data/README.md
CHANGED
|
@@ -30,6 +30,33 @@ Or install it yourself as:
|
|
|
30
30
|
|
|
31
31
|
<br/><br/>
|
|
32
32
|
|
|
33
|
+
## ActiveAdmin 4 Beta Support
|
|
34
|
+
|
|
35
|
+
This branch/version targets [ActiveAdmin 4's beta releases](https://github.com/activeadmin/activeadmin) (`>= 4.0.0.beta1, < 5`), which are not yet stable on RubyGems. Install with:
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
gem 'activeadmin', '>= 4.0.0.beta1', '< 5'
|
|
39
|
+
gem 'date_n_time_picker_activeadmin', '>= 0.1.4.beta1'
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
ActiveAdmin 4 replaced its Sprockets/Sass stylesheet and jQuery-based JS with a Tailwind CSS + importmap-rails setup, and no longer ships an `active_admin.scss`/`active_admin.js` you can `@import`/`//= require` into. As of this release, this gem's own assets are jQuery-free vanilla JS, but are still delivered via Sprockets (not Tailwind's CLI build, which doesn't compile Sass). To wire them into an ActiveAdmin 4 app:
|
|
43
|
+
|
|
44
|
+
1. Keep (or add) a Sprockets Sass compiler in your host app, e.g. `gem 'dartsass-sprockets'`, since ActiveAdmin 4 apps typically no longer include one.
|
|
45
|
+
2. Add explicit `link` entries to `app/assets/config/manifest.js` so Sprockets precompiles the gem's assets, since they live outside `app/assets`:
|
|
46
|
+
```
|
|
47
|
+
//= link date_n_time_picker_activeadmin.css
|
|
48
|
+
//= link date_n_time_picker_activeadmin.js
|
|
49
|
+
```
|
|
50
|
+
3. Override `app/views/active_admin/_html_head.html.erb` (copy it from the `activeadmin` gem, or run `rails g active_admin:views html_head`) and add:
|
|
51
|
+
```erb
|
|
52
|
+
<%= stylesheet_link_tag "date_n_time_picker_activeadmin" %>
|
|
53
|
+
<%= javascript_include_tag "date_n_time_picker_activeadmin" %>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
See `test_app/blog` on this branch for a complete working example.
|
|
57
|
+
|
|
58
|
+
<br/><br/>
|
|
59
|
+
|
|
33
60
|
## Usage
|
|
34
61
|
|
|
35
62
|
Code Sample
|
|
@@ -38,19 +65,21 @@ Code Sample
|
|
|
38
65
|
f.input :column_name, as: :datetimepicker
|
|
39
66
|
```
|
|
40
67
|
|
|
41
|
-
CSS
|
|
68
|
+
CSS (ActiveAdmin 3, or any Sprockets/Sass stylesheet)
|
|
42
69
|
In active_admin.scss, add the line,
|
|
43
70
|
|
|
44
71
|
```css
|
|
45
72
|
@import date_n_time_picker_activeadmin
|
|
46
73
|
```
|
|
47
|
-
JS
|
|
74
|
+
JS (ActiveAdmin 3, or any Sprockets JS manifest)
|
|
48
75
|
In active_admin.js, add the line,
|
|
49
76
|
|
|
50
77
|
```js
|
|
51
78
|
//= require date_n_time_picker_activeadmin
|
|
52
79
|
```
|
|
53
80
|
|
|
81
|
+
For ActiveAdmin 4, see [ActiveAdmin 4 Beta Support](#activeadmin-4-beta-support) above.
|
|
82
|
+
|
|
54
83
|
<br/><br/>
|
|
55
84
|
|
|
56
85
|
## Customisations
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
var toggleTimeIcon = toggleTimeIcon || '<i class="far fa-clock"></i>'
|
|
3
3
|
var toggleCalendarIcon = toggleCalendarIcon || '<i class="far fa-calendar-alt"></i>'
|
|
4
4
|
|
|
5
|
+
function delegate(root, eventType, selector, handler) {
|
|
6
|
+
root.addEventListener(eventType, function (e) {
|
|
7
|
+
let target = e.target.closest(selector)
|
|
8
|
+
if (target && root.contains(target)) {
|
|
9
|
+
handler(e, target)
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
|
|
5
14
|
function myDate() {
|
|
6
15
|
this.date = null;
|
|
7
16
|
this.month = null;
|
|
@@ -36,8 +45,8 @@ function Datetimepicker(element) {
|
|
|
36
45
|
</div>
|
|
37
46
|
</div>`
|
|
38
47
|
}
|
|
39
|
-
|
|
40
|
-
this.widget =
|
|
48
|
+
this.dateInputElement.insertAdjacentHTML('afterend', html)
|
|
49
|
+
this.widget = this.dateInputElement.nextElementSibling
|
|
41
50
|
|
|
42
51
|
bindWidgetEvents.bind(this)()
|
|
43
52
|
this.displayCalendar(this.viewingDate.month, this.viewingDate.year)
|
|
@@ -109,8 +118,9 @@ function Datetimepicker(element) {
|
|
|
109
118
|
</span>
|
|
110
119
|
</span>
|
|
111
120
|
</div>`
|
|
112
|
-
|
|
113
|
-
|
|
121
|
+
let header = this.widget.querySelector('.header')
|
|
122
|
+
header.className = 'header datepicker'
|
|
123
|
+
header.innerHTML = html
|
|
114
124
|
}
|
|
115
125
|
|
|
116
126
|
this.fillBodyCalendar = function (month, year, day, total_days, min_date, max_date) {
|
|
@@ -118,7 +128,7 @@ function Datetimepicker(element) {
|
|
|
118
128
|
let html = `<table>
|
|
119
129
|
<thead>
|
|
120
130
|
<tr>`
|
|
121
|
-
|
|
131
|
+
DAYS.forEach(function (value) {
|
|
122
132
|
html += `<th> ${value} </th>`
|
|
123
133
|
})
|
|
124
134
|
html += ` </tr>
|
|
@@ -170,8 +180,9 @@ function Datetimepicker(element) {
|
|
|
170
180
|
i++
|
|
171
181
|
}
|
|
172
182
|
html += `</tr></tbody></table>`
|
|
173
|
-
|
|
174
|
-
|
|
183
|
+
let body = this.widget.querySelector('.body')
|
|
184
|
+
body.className = 'body datepicker'
|
|
185
|
+
body.innerHTML = html
|
|
175
186
|
}
|
|
176
187
|
|
|
177
188
|
this.displayMonthPicker = function () {
|
|
@@ -180,18 +191,18 @@ function Datetimepicker(element) {
|
|
|
180
191
|
}
|
|
181
192
|
|
|
182
193
|
this.fillHeaderMonthPicker = function () {
|
|
183
|
-
|
|
184
|
-
|
|
194
|
+
this.widget.querySelector('.header').className = 'header monthpicker'
|
|
195
|
+
this.widget.querySelector('.header.monthpicker').innerHTML = `<span> Select Month</span>`
|
|
185
196
|
}
|
|
186
197
|
|
|
187
198
|
this.fillBodyMonthPicker = function () {
|
|
188
|
-
|
|
199
|
+
this.widget.querySelector('.body').className = 'body monthpicker'
|
|
189
200
|
let html = `<div class="month-container">`
|
|
190
|
-
|
|
201
|
+
MONTHS.forEach(function (value, index) {
|
|
191
202
|
html += `<div class="${index}">${value}</div>`
|
|
192
203
|
})
|
|
193
204
|
html += `</div> `
|
|
194
|
-
|
|
205
|
+
this.widget.querySelector('.body.monthpicker').innerHTML = html
|
|
195
206
|
}
|
|
196
207
|
|
|
197
208
|
this.displayYearPicker = function () {
|
|
@@ -202,7 +213,7 @@ function Datetimepicker(element) {
|
|
|
202
213
|
}
|
|
203
214
|
|
|
204
215
|
this.displayNextDozenYears = function () {
|
|
205
|
-
let current_end_year =
|
|
216
|
+
let current_end_year = this.widget.querySelector('.header.yearpicker .current-dozen .end-year').textContent
|
|
206
217
|
let next_start_year = parseInt(current_end_year) + 1
|
|
207
218
|
let next_end_year = parseInt(current_end_year) + 12
|
|
208
219
|
this.fillHeaderYearPicker(next_start_year, next_end_year)
|
|
@@ -210,7 +221,7 @@ function Datetimepicker(element) {
|
|
|
210
221
|
}
|
|
211
222
|
|
|
212
223
|
this.displayPreviousDozenYears = function () {
|
|
213
|
-
let current_start_year =
|
|
224
|
+
let current_start_year = this.widget.querySelector('.header.yearpicker .current-dozen .start-year').textContent
|
|
214
225
|
let previous_start_year = parseInt(current_start_year) - 12
|
|
215
226
|
let previous_end_year = parseInt(current_start_year) - 1
|
|
216
227
|
this.fillHeaderYearPicker(previous_start_year, previous_end_year)
|
|
@@ -218,7 +229,7 @@ function Datetimepicker(element) {
|
|
|
218
229
|
}
|
|
219
230
|
|
|
220
231
|
this.fillHeaderYearPicker = function (start_year, end_year) {
|
|
221
|
-
|
|
232
|
+
this.widget.querySelector('.header').className = 'header yearpicker'
|
|
222
233
|
let html = `<span class="previous-dozen-years">
|
|
223
234
|
<i class="fa fa-chevron-left"></i>
|
|
224
235
|
</span >
|
|
@@ -228,11 +239,11 @@ function Datetimepicker(element) {
|
|
|
228
239
|
<span class="next-dozen-years">
|
|
229
240
|
<i class="fa fa-chevron-right"></i>
|
|
230
241
|
</span>`
|
|
231
|
-
|
|
242
|
+
this.widget.querySelector('.header.yearpicker').innerHTML = html
|
|
232
243
|
}
|
|
233
244
|
|
|
234
245
|
this.fillBodyYearPicker = function (start_year, end_year) {
|
|
235
|
-
|
|
246
|
+
this.widget.querySelector('.body').className = 'body yearpicker'
|
|
236
247
|
let html = `<div class="year-container"> `
|
|
237
248
|
|
|
238
249
|
for (i = start_year; i <= end_year; i++) {
|
|
@@ -244,11 +255,11 @@ function Datetimepicker(element) {
|
|
|
244
255
|
}
|
|
245
256
|
}
|
|
246
257
|
html += `</div>`
|
|
247
|
-
|
|
258
|
+
this.widget.querySelector('.body.yearpicker').innerHTML = html
|
|
248
259
|
}
|
|
249
260
|
|
|
250
261
|
this.toggleDateTimePickers = function () {
|
|
251
|
-
if (
|
|
262
|
+
if (this.widget.querySelector('.footer .toggle').classList.contains('time')) {
|
|
252
263
|
//display timepicker
|
|
253
264
|
this.displayTimePicker()
|
|
254
265
|
|
|
@@ -265,12 +276,14 @@ function Datetimepicker(element) {
|
|
|
265
276
|
}
|
|
266
277
|
|
|
267
278
|
this.toggleFooterIcon = function () {
|
|
268
|
-
|
|
269
|
-
|
|
279
|
+
let toggle = this.widget.querySelector('.footer .toggle')
|
|
280
|
+
if (toggle.classList.contains('time')) {
|
|
281
|
+
toggle.firstElementChild.outerHTML = toggleCalendarIcon
|
|
270
282
|
} else {
|
|
271
|
-
|
|
283
|
+
toggle.firstElementChild.outerHTML = toggleTimeIcon
|
|
272
284
|
}
|
|
273
|
-
|
|
285
|
+
toggle.classList.toggle('time')
|
|
286
|
+
toggle.classList.toggle('date')
|
|
274
287
|
}
|
|
275
288
|
|
|
276
289
|
this.displayTimePicker = function () {
|
|
@@ -279,8 +292,8 @@ function Datetimepicker(element) {
|
|
|
279
292
|
}
|
|
280
293
|
|
|
281
294
|
this.fillHeaderTimePicker = function () {
|
|
282
|
-
|
|
283
|
-
|
|
295
|
+
this.widget.querySelector('.header').className = 'header timepicker'
|
|
296
|
+
this.widget.querySelector('.header.timepicker').innerHTML = `<span> Select Time</span> `
|
|
284
297
|
}
|
|
285
298
|
|
|
286
299
|
this.fillBodyTimePicker = function () {
|
|
@@ -302,8 +315,8 @@ function Datetimepicker(element) {
|
|
|
302
315
|
${this.finalTime.period}
|
|
303
316
|
</div
|
|
304
317
|
</div> `
|
|
305
|
-
|
|
306
|
-
|
|
318
|
+
this.widget.querySelector('.body').className = 'body timepicker'
|
|
319
|
+
this.widget.querySelector('.body.timepicker').innerHTML = html
|
|
307
320
|
}
|
|
308
321
|
|
|
309
322
|
this.displayHourPicker = function () {
|
|
@@ -312,18 +325,18 @@ function Datetimepicker(element) {
|
|
|
312
325
|
}
|
|
313
326
|
|
|
314
327
|
this.fillHeaderHourPicker = function () {
|
|
315
|
-
|
|
316
|
-
|
|
328
|
+
this.widget.querySelector('.header').className = 'header hourpicker'
|
|
329
|
+
this.widget.querySelector('.header.hourpicker').innerHTML = `<span> Select Hour</span>`
|
|
317
330
|
}
|
|
318
331
|
|
|
319
332
|
this.fillBodyHourPicker = function () {
|
|
320
|
-
|
|
333
|
+
this.widget.querySelector('.body').className = 'body hourpicker'
|
|
321
334
|
let html = `<div class="hour-container">`
|
|
322
335
|
for (i = 1; i <= 12; i++) {
|
|
323
336
|
html += `<div>${i}</div>`
|
|
324
337
|
}
|
|
325
338
|
html += `</div>`
|
|
326
|
-
|
|
339
|
+
this.widget.querySelector('.body.hourpicker').innerHTML = html
|
|
327
340
|
}
|
|
328
341
|
|
|
329
342
|
this.displayMinutePicker = function () {
|
|
@@ -332,18 +345,18 @@ function Datetimepicker(element) {
|
|
|
332
345
|
}
|
|
333
346
|
|
|
334
347
|
this.fillHeaderMinutePicker = function () {
|
|
335
|
-
|
|
336
|
-
|
|
348
|
+
this.widget.querySelector('.header').className = 'header minutepicker'
|
|
349
|
+
this.widget.querySelector('.header.minutepicker').innerHTML = `<span> Select Minute</span> `
|
|
337
350
|
}
|
|
338
351
|
|
|
339
352
|
this.fillBodyMinutePicker = function () {
|
|
340
|
-
|
|
353
|
+
this.widget.querySelector('.body').className = 'body minutepicker'
|
|
341
354
|
let html = `<div class="minute-container"> `
|
|
342
355
|
for (i = 0; i <= 59; i += 5) {
|
|
343
356
|
html += `<div>${i}</div> `
|
|
344
357
|
}
|
|
345
358
|
html += `</div>`
|
|
346
|
-
|
|
359
|
+
this.widget.querySelector('.body.minutepicker').innerHTML = html
|
|
347
360
|
}
|
|
348
361
|
}
|
|
349
362
|
|
|
@@ -421,24 +434,24 @@ function formatDateTime(jsDateObject, dateObject, timeObject, format) {
|
|
|
421
434
|
}
|
|
422
435
|
|
|
423
436
|
function bindWidgetEvents() {
|
|
424
|
-
this.widget
|
|
437
|
+
delegate(this.widget, 'click', '.header.datepicker .select-month', function (e, target) {
|
|
425
438
|
//display month picker
|
|
426
439
|
this.displayMonthPicker();
|
|
427
|
-
|
|
440
|
+
this.widget.querySelector('.footer').style.display = 'none'
|
|
428
441
|
}.bind(this))
|
|
429
|
-
this.widget
|
|
430
|
-
this.viewingDate.month = parseInt(
|
|
442
|
+
delegate(this.widget, 'click', '.body.monthpicker .month-container div', function (e, target) {
|
|
443
|
+
this.viewingDate.month = parseInt(target.className)
|
|
431
444
|
// display calendar
|
|
432
445
|
this.displayCalendar(this.viewingDate.month, this.viewingDate.year)
|
|
433
446
|
//show footer
|
|
434
|
-
|
|
447
|
+
this.widget.querySelector('.footer').style.display = ''
|
|
435
448
|
}.bind(this))
|
|
436
|
-
this.widget
|
|
437
|
-
let current_month =
|
|
449
|
+
delegate(this.widget, 'click', '.header.datepicker .previous-month', function (e, target) {
|
|
450
|
+
let current_month = this.widget.querySelector('.header.datepicker .select-month span').className
|
|
438
451
|
// get the previous value of current month
|
|
439
452
|
if (current_month == 0) {
|
|
440
453
|
this.viewingDate.month = 11
|
|
441
|
-
this.viewingDate.year = parseInt(
|
|
454
|
+
this.viewingDate.year = parseInt(this.widget.querySelector('.select-year').textContent) - 1
|
|
442
455
|
}
|
|
443
456
|
else {
|
|
444
457
|
this.viewingDate.month = current_month - 1
|
|
@@ -446,12 +459,12 @@ function bindWidgetEvents() {
|
|
|
446
459
|
// display calendar
|
|
447
460
|
this.displayCalendar(this.viewingDate.month, this.viewingDate.year)
|
|
448
461
|
}.bind(this))
|
|
449
|
-
this.widget
|
|
450
|
-
let current_month =
|
|
462
|
+
delegate(this.widget, 'click', '.header.datepicker .next-month', function (e, target) {
|
|
463
|
+
let current_month = this.widget.querySelector('.header.datepicker .select-month span').className
|
|
451
464
|
// get the next value of current month
|
|
452
465
|
if (current_month == 11) {
|
|
453
466
|
this.viewingDate.month = 0
|
|
454
|
-
this.viewingDate.year = parseInt(
|
|
467
|
+
this.viewingDate.year = parseInt(this.widget.querySelector('.select-year').textContent) + 1
|
|
455
468
|
} else {
|
|
456
469
|
this.viewingDate.month = parseInt(current_month) + 1
|
|
457
470
|
}
|
|
@@ -459,142 +472,144 @@ function bindWidgetEvents() {
|
|
|
459
472
|
// display calendar
|
|
460
473
|
this.displayCalendar(this.viewingDate.month, this.viewingDate.year)
|
|
461
474
|
}.bind(this))
|
|
462
|
-
this.widget
|
|
463
|
-
let year =
|
|
475
|
+
delegate(this.widget, 'click', '.header.datepicker .next-year', function (e, target) {
|
|
476
|
+
let year = this.widget.querySelector('.header.datepicker .select-year').textContent
|
|
464
477
|
this.viewingDate.year = parseInt(year) + 1
|
|
465
478
|
|
|
466
479
|
// display calendar
|
|
467
480
|
this.displayCalendar(this.viewingDate.month, this.viewingDate.year)
|
|
468
481
|
}.bind(this))
|
|
469
|
-
this.widget
|
|
470
|
-
let year =
|
|
482
|
+
delegate(this.widget, 'click', '.header.datepicker .previous-year', function (e, target) {
|
|
483
|
+
let year = this.widget.querySelector('.header.datepicker .select-year').textContent
|
|
471
484
|
this.viewingDate.year = parseInt(year) - 1
|
|
472
485
|
|
|
473
486
|
// display calendar
|
|
474
487
|
this.displayCalendar(this.viewingDate.month, this.viewingDate.year)
|
|
475
488
|
}.bind(this))
|
|
476
|
-
this.widget
|
|
489
|
+
delegate(this.widget, 'click', '.header.datepicker .select-year', function (e, target) {
|
|
477
490
|
|
|
478
491
|
// display year picker
|
|
479
492
|
this.displayYearPicker()
|
|
480
493
|
|
|
481
494
|
//hide footer
|
|
482
|
-
|
|
495
|
+
this.widget.querySelector('.footer').style.display = 'none'
|
|
483
496
|
}.bind(this))
|
|
484
|
-
this.widget
|
|
497
|
+
delegate(this.widget, 'click', '.body.yearpicker .year-container div', function (e, target) {
|
|
485
498
|
//selected year
|
|
486
|
-
this.viewingDate.year =
|
|
499
|
+
this.viewingDate.year = target.textContent
|
|
487
500
|
|
|
488
501
|
//display calendar
|
|
489
502
|
this.displayCalendar(this.viewingDate.month, this.viewingDate.year)
|
|
490
503
|
|
|
491
504
|
//show footer
|
|
492
|
-
|
|
505
|
+
this.widget.querySelector('.footer').style.display = ''
|
|
493
506
|
}.bind(this))
|
|
494
|
-
this.widget
|
|
507
|
+
delegate(this.widget, 'click', '.header.yearpicker .previous-dozen-years', function (e, target) {
|
|
495
508
|
this.displayPreviousDozenYears()
|
|
496
509
|
}.bind(this))
|
|
497
|
-
this.widget
|
|
510
|
+
delegate(this.widget, 'click', '.header.yearpicker .next-dozen-years', function (e, target) {
|
|
498
511
|
this.displayNextDozenYears()
|
|
499
512
|
}.bind(this))
|
|
500
|
-
this.widget
|
|
513
|
+
delegate(this.widget, 'click', '.footer .toggle', function (e, target) {
|
|
501
514
|
this.toggleDateTimePickers()
|
|
502
515
|
}.bind(this))
|
|
503
|
-
this.widget
|
|
504
|
-
this.finalTime.hour =
|
|
516
|
+
delegate(this.widget, 'click', '.body.timepicker .time-container .hour', function (e, target) {
|
|
517
|
+
this.finalTime.hour = target.value
|
|
505
518
|
}.bind(this))
|
|
506
|
-
this.widget
|
|
507
|
-
this.finalTime.minute =
|
|
519
|
+
delegate(this.widget, 'click', '.body.timepicker .time-container .minute', function (e, target) {
|
|
520
|
+
this.finalTime.minute = target.value
|
|
508
521
|
}.bind(this))
|
|
509
|
-
this.widget
|
|
522
|
+
delegate(this.widget, 'click', '.body.timepicker .time-container .hour-container .previous-hour', function (e, target) {
|
|
510
523
|
if (this.finalTime.hour == 0) {
|
|
511
524
|
this.finalTime.hour = 12
|
|
512
525
|
} else {
|
|
513
526
|
this.finalTime.hour = this.finalTime.hour - 1
|
|
514
527
|
}
|
|
515
|
-
|
|
528
|
+
this.widget.querySelector('.body.timepicker .time-container .hour').textContent = this.finalTime.hour
|
|
516
529
|
}.bind(this))
|
|
517
|
-
this.widget
|
|
530
|
+
delegate(this.widget, 'click', '.body.timepicker .time-container .hour-container .next-hour', function (e, target) {
|
|
518
531
|
if (this.finalTime.hour == 12) {
|
|
519
532
|
this.finalTime.hour = 0
|
|
520
533
|
} else {
|
|
521
534
|
this.finalTime.hour = parseInt(this.finalTime.hour) + 1
|
|
522
535
|
}
|
|
523
|
-
|
|
536
|
+
this.widget.querySelector('.body.timepicker .time-container .hour').textContent = this.finalTime.hour
|
|
524
537
|
}.bind(this))
|
|
525
|
-
this.widget
|
|
538
|
+
delegate(this.widget, 'click', '.body.timepicker .time-container .minute-container .previous-minute', function (e, target) {
|
|
526
539
|
if (this.finalTime.minute == 0) {
|
|
527
540
|
this.finalTime.minute = 60
|
|
528
541
|
} else {
|
|
529
542
|
this.finalTime.minute = this.finalTime.minute - 1
|
|
530
543
|
}
|
|
531
|
-
|
|
544
|
+
this.widget.querySelector('.body.timepicker .time-container .minute').textContent = this.finalTime.minute
|
|
532
545
|
}.bind(this))
|
|
533
|
-
this.widget
|
|
546
|
+
delegate(this.widget, 'click', '.body.timepicker .time-container .minute-container .next-minute', function (e, target) {
|
|
534
547
|
if (this.finalTime.minute == 60) {
|
|
535
548
|
this.finalTime.minute = 0
|
|
536
549
|
} else {
|
|
537
550
|
this.finalTime.minute = parseInt(this.finalTime.minute) + 1
|
|
538
551
|
}
|
|
539
|
-
|
|
552
|
+
this.widget.querySelector('.body.timepicker .time-container .minute').textContent = this.finalTime.minute
|
|
540
553
|
}.bind(this))
|
|
541
|
-
this.widget
|
|
554
|
+
delegate(this.widget, 'click', '.body.timepicker .time-container .hour', function (e, target) {
|
|
542
555
|
this.displayHourPicker()
|
|
543
|
-
|
|
556
|
+
this.widget.querySelector('.footer').style.display = 'none'
|
|
544
557
|
}.bind(this))
|
|
545
|
-
this.widget
|
|
558
|
+
delegate(this.widget, 'click', '.body.timepicker .time-container .minute', function (e, target) {
|
|
546
559
|
this.displayMinutePicker()
|
|
547
|
-
|
|
560
|
+
this.widget.querySelector('.footer').style.display = 'none'
|
|
548
561
|
}.bind(this))
|
|
549
|
-
this.widget
|
|
562
|
+
delegate(this.widget, 'click', '.body.hourpicker .hour-container div', function (e, target) {
|
|
550
563
|
//save the selected month value
|
|
551
|
-
this.finalTime.hour =
|
|
564
|
+
this.finalTime.hour = target.textContent
|
|
552
565
|
this.updateDateObject()
|
|
553
566
|
|
|
554
567
|
// display calendar
|
|
555
568
|
this.displayTimePicker()
|
|
556
569
|
|
|
557
570
|
//show footer
|
|
558
|
-
|
|
571
|
+
this.widget.querySelector('.footer').style.display = ''
|
|
559
572
|
}.bind(this))
|
|
560
|
-
this.widget
|
|
573
|
+
delegate(this.widget, 'click', '.body.minutepicker .minute-container div', function (e, target) {
|
|
561
574
|
//save the selected month value
|
|
562
|
-
this.finalTime.minute =
|
|
575
|
+
this.finalTime.minute = target.textContent
|
|
563
576
|
this.updateDateObject()
|
|
564
577
|
|
|
565
578
|
// display calendar
|
|
566
579
|
this.displayTimePicker()
|
|
567
580
|
|
|
568
581
|
//show footer
|
|
569
|
-
|
|
582
|
+
this.widget.querySelector('.footer').style.display = ''
|
|
570
583
|
}.bind(this))
|
|
571
|
-
this.widget
|
|
584
|
+
delegate(this.widget, 'click', '.body.timepicker .toggle-am-pm', function (e, target) {
|
|
572
585
|
//save the selected month value
|
|
573
586
|
if (this.finalTime.period == "AM") {
|
|
574
587
|
this.finalTime.period = "PM"
|
|
575
|
-
|
|
588
|
+
this.widget.querySelector('.body.timepicker .toggle-am-pm').textContent = "PM"
|
|
576
589
|
} else {
|
|
577
590
|
this.finalTime.period = "AM"
|
|
578
|
-
|
|
591
|
+
this.widget.querySelector('.body.timepicker .toggle-am-pm').textContent = "AM"
|
|
579
592
|
}
|
|
580
593
|
this.updateDateObject()
|
|
581
594
|
// display calendar
|
|
582
595
|
// this.displayTimePicker()
|
|
583
596
|
|
|
584
597
|
//show footer
|
|
585
|
-
//
|
|
598
|
+
// this.widget.querySelector('.footer').style.display = ''
|
|
586
599
|
}.bind(this))
|
|
587
|
-
this.widget
|
|
600
|
+
delegate(this.widget, 'click', '.body.datepicker table td:not(.disabled)', function (e, target) {
|
|
588
601
|
|
|
589
602
|
// add and remove class (for the design)
|
|
590
|
-
|
|
591
|
-
|
|
603
|
+
this.widget.querySelectorAll('.body.datepicker table td').forEach(function (td) {
|
|
604
|
+
td.classList.remove('selected')
|
|
605
|
+
})
|
|
606
|
+
target.classList.add('selected')
|
|
592
607
|
|
|
593
608
|
// let min_date = new Date(datetimepicker_options['min_date'])
|
|
594
609
|
// let max_date = new Date(datetimepicker_options['max_date'])
|
|
595
610
|
|
|
596
611
|
// save selected date
|
|
597
|
-
this.finalDate.date =
|
|
612
|
+
this.finalDate.date = target.textContent
|
|
598
613
|
this.finalDate.year = this.viewingDate.year
|
|
599
614
|
this.finalDate.month = this.viewingDate.month
|
|
600
615
|
|
|
@@ -607,7 +622,7 @@ function bindWidgetEvents() {
|
|
|
607
622
|
hr24 = this.finalTime.hour
|
|
608
623
|
else
|
|
609
624
|
hr24 = parseInt(this.finalTime.hour) + 12
|
|
610
|
-
|
|
625
|
+
|
|
611
626
|
this.dateObject = new Date(this.finalDate.year, this.finalDate.month, this.finalDate.date, hr24, this.finalTime.minute )
|
|
612
627
|
}.bind(this)
|
|
613
628
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//= require datetimepicker-object
|
|
1
|
+
//= require datetimepicker-object
|
|
2
2
|
|
|
3
3
|
let default_options = {
|
|
4
4
|
'min_date': -1,
|
|
@@ -8,12 +8,12 @@ let default_options = {
|
|
|
8
8
|
};
|
|
9
9
|
let datetimepicker_active_objects = [];
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
function initDatetimepickers() {
|
|
12
12
|
// Initialising datetimepicker objects
|
|
13
13
|
// Saving them to an array
|
|
14
|
-
|
|
15
|
-
let obj = new Datetimepicker(
|
|
16
|
-
if (
|
|
14
|
+
document.querySelectorAll('.ui-datetime-picker-wrapper > .ui-datetime-picker-input').forEach(function (d) {
|
|
15
|
+
let obj = new Datetimepicker(d);
|
|
16
|
+
if (d.value == "") {
|
|
17
17
|
obj.dateObject = new Date()
|
|
18
18
|
obj.viewingDate.date = -1;
|
|
19
19
|
obj.viewingDate.month = obj.dateObject.getMonth()
|
|
@@ -24,17 +24,16 @@ $(function () {
|
|
|
24
24
|
obj.finalTime.minute = obj.dateObject.getMinutes()
|
|
25
25
|
obj.finalTime.period = time[1]
|
|
26
26
|
|
|
27
|
-
|
|
28
27
|
// display date according to format specified
|
|
29
|
-
if (
|
|
30
|
-
let options =
|
|
31
|
-
obj.datetimepicker_options = { ...default_options, ...(
|
|
28
|
+
if (d.hasAttribute('datetimepicker_options')) {
|
|
29
|
+
let options = d.getAttribute('datetimepicker_options')
|
|
30
|
+
obj.datetimepicker_options = { ...default_options, ...JSON.parse(options) }
|
|
32
31
|
} else {
|
|
33
32
|
obj.datetimepicker_options = default_options
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
} else {
|
|
37
|
-
let val =
|
|
36
|
+
let val = d.value
|
|
38
37
|
|
|
39
38
|
// for firefox browser
|
|
40
39
|
val = val.replace(' UTC', '')
|
|
@@ -50,33 +49,41 @@ $(function () {
|
|
|
50
49
|
obj.finalTime.minute = obj.dateObject.getMinutes()
|
|
51
50
|
obj.finalTime.period = time[1]
|
|
52
51
|
|
|
53
|
-
|
|
54
52
|
// display date according to format specified
|
|
55
|
-
let options =
|
|
53
|
+
let options = d.getAttribute('datetimepicker_options')
|
|
56
54
|
|
|
57
|
-
obj.datetimepicker_options = { ...default_options, ...(
|
|
55
|
+
obj.datetimepicker_options = { ...default_options, ...JSON.parse(options) }
|
|
58
56
|
|
|
59
57
|
let formatted_date = formatDateTime(obj.dateObject, obj.viewingDate, obj.finalTime, obj.datetimepicker_options["format"])
|
|
60
|
-
|
|
58
|
+
d.value = formatted_date
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
d.addEventListener('click', function(){
|
|
61
|
+
d.addEventListener('click', function () {
|
|
64
62
|
obj.initDateTimePicker.bind(obj)()
|
|
65
63
|
datetimepicker_active_objects.push(obj)
|
|
66
64
|
})
|
|
67
65
|
})
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (document.readyState === 'loading') {
|
|
69
|
+
document.addEventListener('DOMContentLoaded', initDatetimepickers)
|
|
70
|
+
} else {
|
|
71
|
+
initDatetimepickers()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
document.addEventListener('click', function (e) {
|
|
75
|
+
if (datetimepicker_active_objects.length > 0) {
|
|
76
|
+
let clicked_inside_wrapper = e.target.closest('.ui-datetime-picker-wrapper') != null
|
|
77
|
+
if ((!clicked_inside_wrapper) || (e.target.classList.contains('ui-datetime-picker-input'))) {
|
|
73
78
|
let obj_to_remove = datetimepicker_active_objects.shift()
|
|
74
79
|
// set value of input field with selected date
|
|
75
80
|
if ((!(obj_to_remove.finalDate.date == null))) {
|
|
76
|
-
formatted_date = formatDateTime(obj_to_remove.dateObject, obj_to_remove.finalDate, obj_to_remove.finalTime, obj_to_remove.datetimepicker_options["format"])
|
|
77
|
-
|
|
81
|
+
let formatted_date = formatDateTime(obj_to_remove.dateObject, obj_to_remove.finalDate, obj_to_remove.finalTime, obj_to_remove.datetimepicker_options["format"])
|
|
82
|
+
obj_to_remove.dateInputElement.value = formatted_date
|
|
83
|
+
}
|
|
84
|
+
if (obj_to_remove.widget) {
|
|
85
|
+
obj_to_remove.widget.remove()
|
|
78
86
|
}
|
|
79
|
-
$(obj_to_remove.dateInputElement).next().remove()
|
|
80
87
|
}
|
|
81
88
|
}
|
|
82
|
-
}, true)
|
|
89
|
+
}, true)
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
width: 277px;
|
|
5
5
|
z-index: 2000;
|
|
6
6
|
position: absolute;
|
|
7
|
-
margin-left:
|
|
7
|
+
margin-left: 1%;
|
|
8
8
|
margin-top: 5px;
|
|
9
9
|
border: 1px solid grey;
|
|
10
10
|
justify-content: center;
|
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
.body.datepicker{
|
|
36
|
+
table{
|
|
37
|
+
width: 100%;
|
|
38
|
+
}
|
|
36
39
|
table thead{
|
|
37
40
|
th{
|
|
38
41
|
background: $date-n-time-picker-container-color;
|
|
@@ -43,7 +46,7 @@
|
|
|
43
46
|
text-align: center;
|
|
44
47
|
&:hover{
|
|
45
48
|
cursor: pointer;
|
|
46
|
-
&:not(.selected){
|
|
49
|
+
&:not(.selected):not(.disabled){
|
|
47
50
|
background-color: $date-n-time-picker-primary-color;
|
|
48
51
|
opacity: 0.5;
|
|
49
52
|
color: $date-n-time-picker-primary-text-color;
|
|
@@ -57,6 +60,13 @@
|
|
|
57
60
|
border-radius: 5px;
|
|
58
61
|
font-weight: bold;
|
|
59
62
|
}
|
|
63
|
+
&.disabled{
|
|
64
|
+
color: darkgrey;
|
|
65
|
+
cursor: not-allowed;
|
|
66
|
+
&:hover{
|
|
67
|
+
cursor: not-allowed;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
60
70
|
}
|
|
61
71
|
th, td, caption {
|
|
62
72
|
padding: 4px 2px 4px 2px;
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: date_n_time_picker_activeadmin
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4.beta1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nikhitha Grace Josh
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: font-awesome-sass
|
|
@@ -34,23 +33,22 @@ dependencies:
|
|
|
34
33
|
name: activeadmin
|
|
35
34
|
requirement: !ruby/object:Gem::Requirement
|
|
36
35
|
requirements:
|
|
37
|
-
- - "~>"
|
|
38
|
-
- !ruby/object:Gem::Version
|
|
39
|
-
version: '3.2'
|
|
40
36
|
- - ">="
|
|
41
37
|
- !ruby/object:Gem::Version
|
|
42
|
-
version:
|
|
38
|
+
version: 4.0.0.beta1
|
|
39
|
+
- - "<"
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '5'
|
|
43
42
|
type: :runtime
|
|
44
43
|
prerelease: false
|
|
45
44
|
version_requirements: !ruby/object:Gem::Requirement
|
|
46
45
|
requirements:
|
|
47
|
-
- - "~>"
|
|
48
|
-
- !ruby/object:Gem::Version
|
|
49
|
-
version: '3.2'
|
|
50
46
|
- - ">="
|
|
51
47
|
- !ruby/object:Gem::Version
|
|
52
|
-
version:
|
|
53
|
-
|
|
48
|
+
version: 4.0.0.beta1
|
|
49
|
+
- - "<"
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: '5'
|
|
54
52
|
email:
|
|
55
53
|
- josh.nikhitha@gmail.com
|
|
56
54
|
executables: []
|
|
@@ -77,7 +75,6 @@ metadata:
|
|
|
77
75
|
homepage_uri: https://github.com/NikhithaGraceJosh/date_n_time_picker_activeadmin
|
|
78
76
|
source_code_uri: https://github.com/NikhithaGraceJosh/date_n_time_picker_activeadmin
|
|
79
77
|
bug_tracker_uri: https://github.com/NikhithaGraceJosh/date_n_time_picker_activeadmin/issues
|
|
80
|
-
post_install_message:
|
|
81
78
|
rdoc_options: []
|
|
82
79
|
require_paths:
|
|
83
80
|
- lib
|
|
@@ -92,8 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
92
89
|
- !ruby/object:Gem::Version
|
|
93
90
|
version: '0'
|
|
94
91
|
requirements: []
|
|
95
|
-
rubygems_version:
|
|
96
|
-
signing_key:
|
|
92
|
+
rubygems_version: 4.0.16
|
|
97
93
|
specification_version: 4
|
|
98
94
|
summary: Datetime Picker for Activeadmin
|
|
99
95
|
test_files: []
|