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
|
|
|
const msg = $target.data('confirmation') || ''; |
67
|
|
|
if (msg.length && !window.confirm(msg)) { |
68
|
|
|
return false; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
let dataAction; |
72
|
|
|
if ($target.is('a[data-action]')) { |
73
|
|
|
dataAction = $target.data('action'); |
74
|
|
|
} else { |
75
|
|
|
dataAction = $target.closest('a[data-action]').data('action'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$('#batch_action').val(dataAction); |
79
|
|
|
$('#collection').submit(); |
80
|
|
|
|
81
|
|
|
return false; |
82
|
|
|
}); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
static handleFancybox() { |
86
|
|
|
$('.fancybox').fancybox({ |
87
|
|
|
afterLoad: function () { |
88
|
|
|
let width, height; |
89
|
|
|
if (width = $(this.element).data('width')) { |
90
|
|
|
this.width = width; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
if (height = $(this.element).data('height')) { |
94
|
|
|
this.height = height; |
95
|
|
|
} |
96
|
|
|
}, |
97
|
|
|
}); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$(() => new AdminArchitect); |
102
|
|
|
|