|
1
|
|
|
class AdminArchitect { |
|
2
|
|
|
constructor() { |
|
3
|
|
|
[ |
|
4
|
|
|
'Collections', 'BatchActions', |
|
5
|
|
|
'Fancybox', 'Translatable', 'Translations', |
|
6
|
|
|
].map((method) => { |
|
7
|
|
|
AdminArchitect['handle' + method].call(); |
|
8
|
|
|
}); |
|
9
|
|
|
} |
|
10
|
|
|
|
|
11
|
|
|
static handleTranslatable() { |
|
12
|
|
|
// When Mui tab is switched it will switch all sibling Mui tabs. |
|
13
|
|
|
$('a[data-toggle="tab"]', '.nav-translatable').on('shown.bs.tab', function (e) { |
|
14
|
|
|
let fn = $(e.target), |
|
15
|
|
|
lc = fn.data('locale'); |
|
16
|
|
|
|
|
17
|
|
|
fn.closest('form').find('a[data-locale="' + lc + '"]').tab('show'); |
|
18
|
|
|
}); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
static handleTranslations() { |
|
22
|
|
|
const activate = function (fn) { |
|
23
|
|
|
fn.addClass('active').siblings('button').removeClass('active'); |
|
24
|
|
|
}; |
|
25
|
|
|
|
|
26
|
|
|
$('.global button[data-locale]').click(({target}) => { |
|
27
|
|
|
const fn = $(target), locale = fn.data('locale'); |
|
28
|
|
|
$(fn).closest('table').find('tbody button[data-locale="' + locale + '"]').each(function (i, button) { |
|
29
|
|
|
$(button).trigger('click'); |
|
30
|
|
|
}); |
|
31
|
|
|
activate(fn); |
|
32
|
|
|
}); |
|
33
|
|
|
|
|
34
|
|
|
$('tbody button[data-locale]').click(({target}) => { |
|
35
|
|
|
const fn = $(target), locale = fn.data('locale'); |
|
36
|
|
|
fn.closest('tr').find('.translatable').each((i, e) => { |
|
37
|
|
|
const item = $(e); |
|
38
|
|
|
item[item.data('locale') === locale ? 'removeClass' : 'addClass']('hidden'); |
|
39
|
|
|
}); |
|
40
|
|
|
activate(fn); |
|
41
|
|
|
}); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
static handleCollections() { |
|
45
|
|
|
$(document).on('click', '.toggle-collection', ({target}) => { |
|
46
|
|
|
const fn = $(target); |
|
47
|
|
|
|
|
48
|
|
|
$('input[type=checkbox].collection-item').each((i, e) => { |
|
49
|
|
|
$(e).prop('checked', fn.prop('checked')); |
|
50
|
|
|
}); |
|
51
|
|
|
}); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
static handleBatchActions() { |
|
55
|
|
|
const selected = () => { |
|
56
|
|
|
return $('input[type=checkbox]:checked.collection-item'); |
|
57
|
|
|
}; |
|
58
|
|
|
|
|
59
|
|
|
$(document).on('click', '.batch-actions a[data-action]', ({target}) => { |
|
60
|
|
|
if (!selected().length) { |
|
61
|
|
|
return false; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
const $target = $(target); |
|
65
|
|
|
|
|
66
|
|
|
if ((msg = $target.data('confirmation')) && !window.confirm(msg)) { |
|
|
|
|
|
|
67
|
|
|
return false; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$('#batch_action').val($target.data('action')); |
|
71
|
|
|
$('#collection').submit(); |
|
72
|
|
|
|
|
73
|
|
|
return false; |
|
74
|
|
|
}); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
static handleDateControls() { |
|
78
|
|
|
$('[data-filter-type="date"]').datetimepicker({ |
|
79
|
|
|
format: 'YYYY-MM-DD' |
|
80
|
|
|
}); |
|
81
|
|
|
|
|
82
|
|
|
$('[data-filter-type="time"]').datetimepicker({ |
|
83
|
|
|
format: 'hh:mm:ss' |
|
84
|
|
|
}); |
|
85
|
|
|
|
|
86
|
|
|
$('[data-filter-type="datetime"]').datetimepicker({ |
|
87
|
|
|
format: 'YYYY-MM-DD hh:mm:ss' |
|
88
|
|
|
}); |
|
89
|
|
|
|
|
90
|
|
|
$('[data-filter-type="daterange"]').daterangepicker({ |
|
91
|
|
|
locale: { |
|
92
|
|
|
format: 'YYYY-MM-DD', |
|
93
|
|
|
}, |
|
94
|
|
|
autoUpdateInput: false, |
|
95
|
|
|
ranges: { |
|
96
|
|
|
'Today': [moment(), moment()], |
|
97
|
|
|
'Yesterday': [ |
|
98
|
|
|
moment().subtract(1, 'days'), |
|
99
|
|
|
moment().subtract(1, 'days'), |
|
100
|
|
|
], |
|
101
|
|
|
'Last 7 Days': [moment().subtract(6, 'days'), moment()], |
|
102
|
|
|
'Last 30 Days': [moment().subtract(29, 'days'), moment()], |
|
103
|
|
|
'This Month': [ |
|
104
|
|
|
moment().startOf('month'), |
|
105
|
|
|
moment().endOf('month'), |
|
106
|
|
|
], |
|
107
|
|
|
'Last Month': [ |
|
108
|
|
|
moment().subtract(1, 'month').startOf('month'), |
|
109
|
|
|
moment().subtract(1, 'month').endOf('month'), |
|
110
|
|
|
], |
|
111
|
|
|
}, |
|
112
|
|
|
}).on('apply.daterangepicker', function (ev, picker) { |
|
113
|
|
|
$(this).val(picker.startDate.format('YYYY-MM-DD') + ' - ' + picker.endDate.format('YYYY-MM-DD')); |
|
114
|
|
|
}).on('cancel.daterangepicker', function (ev, picker) { |
|
|
|
|
|
|
115
|
|
|
$(this).val(''); |
|
116
|
|
|
}); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
static handleFancybox() { |
|
120
|
|
|
$('.fancybox').fancybox({ |
|
121
|
|
|
afterLoad: function () { |
|
122
|
|
|
let width, height; |
|
123
|
|
|
if (width = $(this.element).data('width')) { |
|
124
|
|
|
this.width = width; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
if (height = $(this.element).data('height')) { |
|
128
|
|
|
this.height = height; |
|
129
|
|
|
} |
|
130
|
|
|
}, |
|
131
|
|
|
}); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
$(() => new AdminArchitect); |
|
136
|
|
|
|