forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalpineInit.js
More file actions
49 lines (44 loc) · 1.19 KB
/
alpineInit.js
File metadata and controls
49 lines (44 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import notificationMethods from './notifications.js';
import initUnlimitedInput from './unlimitedInput.js';
import initShortcuts from './shortcuts.js';
// Set up various Alpine things, loads after Alpine is initialized
export default function alpineInit() {
// Bulk edit forms
Alpine.bind('BulkEdit', () => ({
/** @param {SubmitEvent} evt */
'@submit'(evt) {
evt.preventDefault();
document.querySelectorAll('.ch-toggle').forEach((el) => {
if (el.checked) {
const input = document.createElement('input');
input.type = 'hidden';
input.name = el.name;
input.value = el.value;
evt.target.appendChild(input);
}
});
evt.target.submit();
},
}));
// Form state
Alpine.store('form', {
dirty: false,
makeDirty() {
this.dirty = true;
},
});
document
.querySelectorAll('#vstobjects input, #vstobjects select, #vstobjects textarea')
.forEach((el) => {
el.addEventListener('change', () => {
Alpine.store('form').makeDirty();
});
});
// Register Alpine notifications methods
Alpine.data('notifications', notificationMethods);
initAlpineDependentModules();
}
function initAlpineDependentModules() {
initUnlimitedInput();
initShortcuts();
}