-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.js
More file actions
130 lines (113 loc) · 5.69 KB
/
admin.js
File metadata and controls
130 lines (113 loc) · 5.69 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { displayAlertBox } from './alert.js';
/**
* Lie une liste d'inputs à une fonction de mise à jour de preview.
* Exécute la fonction immédiatement, puis sur chaque événement 'input'.
*/
function bindPreviewInputs(inputIds, updateFn) {
updateFn();
inputIds.forEach((id) => {
const el = document.getElementById(id);
if (el) el.addEventListener('input', updateFn);
});
}
function updateDonationGoalPreview() {
const back = document.querySelector('.back');
const front = document.querySelector('.front');
const backTitle = document.getElementById('back-title');
const frontTitle = document.getElementById('front-title');
// L'objectif est maintenant dans le formulaire d'infos (stream_goal ou event_goal)
const goalInput = document.getElementById('stream_goal') || document.getElementById('event_goal');
back.style.backgroundColor = document.getElementById('background_color').value;
front.style.backgroundColor = document.getElementById('bar_color').value;
back.style.color = document.getElementById('text_color_main').value;
front.style.color = document.getElementById('text_color_alt').value;
const textContent = document.getElementById('text_content').value;
backTitle.textContent = textContent;
frontTitle.textContent = textContent;
const goalValue = goalInput ? (parseFloat(goalInput.value) || 0) : 0;
const currentDonation = goalValue / 2;
document.getElementById('back-goal-total').textContent = `${goalValue} €`;
document.getElementById('front-goal-total').textContent = `${goalValue} €`;
document.getElementById('back-goal-current').textContent = `${currentDonation} €`;
document.getElementById('front-goal-current').textContent = `${currentDonation} €`;
front.style.width = goalValue > 0 ? `${(currentDonation / goalValue) * 100}%` : '0%';
}
const donationBarForm = document.getElementById('donationBarForm');
if (donationBarForm) {
bindPreviewInputs(
['text_color_main', 'text_color_alt', 'text_content', 'bar_color', 'background_color', 'stream_goal', 'event_goal'],
updateDonationGoalPreview
);
}
const alertBoxForm = document.getElementById('alertBoxForm');
if (alertBoxForm) {
document.getElementById('previewBtn').addEventListener('click', () => {
displayAlertBox('test de pseudo', 'test de message', '1000');
});
}
// ── Card widget live preview ──────────────────────────────────
const cardWidgetForm = document.getElementById('cardWidgetForm');
if (cardWidgetForm) {
function updateCardPreview() {
const preview = document.getElementById('cardPreview');
const tag = document.getElementById('cardPreviewTag');
const title = document.getElementById('cardPreviewTitle');
const desc = document.getElementById('cardPreviewDesc');
const amount = document.getElementById('cardPreviewAmount');
const barFill = document.getElementById('cardPreviewBarFill');
const goalEl = document.getElementById('cardPreviewGoal');
const pct = document.getElementById('cardPreviewPct');
const bgColor = document.getElementById('card_background_color').value;
const textColor = document.getElementById('card_text_color').value;
const barColor = document.getElementById('card_bar_color').value;
const barBgColor = document.getElementById('card_bar_background_color').value;
const tagColor = document.getElementById('card_tag_color').value;
const tagBgColor = document.getElementById('card_tag_background_color').value;
// L'objectif est maintenant dans le formulaire d'infos (stream_goal ou event_goal)
const goalInput = document.getElementById('stream_goal') || document.getElementById('event_goal');
const goalValue = goalInput ? (parseFloat(goalInput.value) || 1) : 1;
if (preview) {
preview.style.backgroundColor = bgColor;
preview.style.color = textColor;
}
if (tag) {
tag.style.color = tagColor;
tag.style.backgroundColor = tagBgColor;
tag.textContent = `✏️ ${document.getElementById('card_tag').value || ''}`;
}
if (title) title.textContent = document.getElementById('card_title').value || '';
if (desc) desc.textContent = document.getElementById('card_description').value || '';
const halfGoal = goalValue / 2;
if (amount) amount.textContent = `${halfGoal} €`;
if (barFill) {
barFill.style.backgroundColor = barColor;
barFill.style.width = '50%';
barFill.parentElement.style.backgroundColor = barBgColor;
}
if (goalEl) goalEl.innerHTML = `Objectif : <strong>${goalValue} €</strong>`;
if (pct) pct.textContent = '50%';
}
bindPreviewInputs(
[
'card_tag', 'card_title', 'card_description',
'card_background_color', 'card_text_color', 'card_bar_color',
'card_bar_background_color', 'card_tag_color', 'card_tag_background_color',
'stream_goal', 'event_goal',
],
updateCardPreview
);
// Live image preview
const cardImageInput = document.getElementById('card_image');
if (cardImageInput) {
cardImageInput.addEventListener('change', function () {
const file = this.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = (e) => {
const imgEl = document.getElementById('cardPreviewImage');
if (imgEl) imgEl.style.backgroundImage = `url(${e.target.result})`;
};
reader.readAsDataURL(file);
});
}
}