nodebb-plugin-calendar-onekite 1.3.4 → 1.3.6
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.
package/helloasso.js
CHANGED
|
@@ -33,7 +33,7 @@ async function getHelloAssoAccessToken() {
|
|
|
33
33
|
|
|
34
34
|
async function createHelloAssoCheckoutIntent({ eid, rid, uid, itemId, quantity, amount }) {
|
|
35
35
|
if (!HELLOASSO_ORG_SLUG || !HELLOASSO_FORM_SLUG) {
|
|
36
|
-
console.warn('[calendar-
|
|
36
|
+
console.warn('[calendar-onekite] HelloAsso non configuré, retournera une URL générique.');
|
|
37
37
|
return 'https://www.helloasso.com/';
|
|
38
38
|
}
|
|
39
39
|
|
package/library.js
CHANGED
|
@@ -99,7 +99,8 @@ async function updateEvent(eid, data) {
|
|
|
99
99
|
allDay: data.allDay !== undefined ? (data.allDay ? 1 : 0) : existing.allDay,
|
|
100
100
|
location: data.location !== undefined ? String(data.location) : existing.location,
|
|
101
101
|
visibility: data.visibility !== undefined ? String(data.visibility) : existing.visibility,
|
|
102
|
-
bookingEnabled:
|
|
102
|
+
bookingEnabled:
|
|
103
|
+
data.bookingEnabled !== undefined ? (data.bookingEnabled ? 1 : 0) : (existing.bookingEnabled || 0),
|
|
103
104
|
bookingItems: JSON.stringify(bookingItems),
|
|
104
105
|
updatedAt: String(Date.now()),
|
|
105
106
|
};
|
|
@@ -140,7 +141,7 @@ async function getUpcomingEvents(limit = 5) {
|
|
|
140
141
|
|
|
141
142
|
async function userCanCreate(uid) {
|
|
142
143
|
if (!uid || uid === 0) return false;
|
|
143
|
-
const settings = await Settings.get('calendar-
|
|
144
|
+
const settings = await Settings.get('calendar-onekite');
|
|
144
145
|
if (!settings || !settings.allowedGroups) return false;
|
|
145
146
|
|
|
146
147
|
const allowedSet = new Set(
|
|
@@ -159,7 +160,7 @@ async function userCanCreate(uid) {
|
|
|
159
160
|
async function userCanBook(uid) {
|
|
160
161
|
if (!uid || uid === 0) return false;
|
|
161
162
|
|
|
162
|
-
const settings = await Settings.get('calendar-
|
|
163
|
+
const settings = await Settings.get('calendar-onekite');
|
|
163
164
|
// Si pas configuré, on permet à tout le monde connecté
|
|
164
165
|
if (!settings || !settings.allowedBookingGroups) return true;
|
|
165
166
|
|
|
@@ -224,6 +225,23 @@ function computePrice(event, reservation) {
|
|
|
224
225
|
return unit * reservation.quantity * days;
|
|
225
226
|
}
|
|
226
227
|
|
|
228
|
+
/* ********* ADMIN PAGE (AJOUTÉ) ********* */
|
|
229
|
+
|
|
230
|
+
async function renderAdminPage(req, res) {
|
|
231
|
+
try {
|
|
232
|
+
const settings = (await Settings.get('calendar-onekite')) || {};
|
|
233
|
+
res.render('admin/plugins/calendar-onekite', {
|
|
234
|
+
title: 'Calendar OneKite',
|
|
235
|
+
settings,
|
|
236
|
+
});
|
|
237
|
+
} catch (err) {
|
|
238
|
+
if (req.path && req.path.startsWith('/api/')) {
|
|
239
|
+
return res.status(500).json({ error: err.message });
|
|
240
|
+
}
|
|
241
|
+
res.status(500).send(err.message);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
227
245
|
/* ********* INIT ********* */
|
|
228
246
|
|
|
229
247
|
Plugin.init = async function (params) {
|
|
@@ -390,7 +408,7 @@ Plugin.init = async function (params) {
|
|
|
390
408
|
status: 'pending_admin',
|
|
391
409
|
helloAssoOrderId: null,
|
|
392
410
|
createdAt: now,
|
|
393
|
-
pickupLocation: item.pickupLocation || ''
|
|
411
|
+
pickupLocation: item.pickupLocation || '',
|
|
394
412
|
};
|
|
395
413
|
|
|
396
414
|
allRes.push(reservation);
|
|
@@ -412,7 +430,7 @@ Plugin.init = async function (params) {
|
|
|
412
430
|
pickupLocation: reservation.pickupLocation || 'Non précisé',
|
|
413
431
|
});
|
|
414
432
|
} catch (e) {
|
|
415
|
-
console.warn('[calendar-
|
|
433
|
+
console.warn('[calendar-onekite] email reservation-created error:', e.message);
|
|
416
434
|
}
|
|
417
435
|
|
|
418
436
|
res.json({
|
|
@@ -499,7 +517,7 @@ Plugin.init = async function (params) {
|
|
|
499
517
|
days: reservation.days || 1,
|
|
500
518
|
});
|
|
501
519
|
} catch (e) {
|
|
502
|
-
console.warn('[calendar-
|
|
520
|
+
console.warn('[calendar-onekite] email reservation-approved error:', e.message);
|
|
503
521
|
}
|
|
504
522
|
|
|
505
523
|
res.json({ success: true, checkoutUrl });
|
|
@@ -566,7 +584,6 @@ Plugin.init = async function (params) {
|
|
|
566
584
|
const itemIndex = items.findIndex(i => i.id === reservation.itemId);
|
|
567
585
|
if (itemIndex !== -1) {
|
|
568
586
|
const item = items[itemIndex];
|
|
569
|
-
// plus de reservedTemp, la logique se base sur les réservations
|
|
570
587
|
item.reserved = (item.reserved || 0) + reservation.quantity;
|
|
571
588
|
items[itemIndex] = item;
|
|
572
589
|
}
|
|
@@ -592,24 +609,24 @@ Plugin.init = async function (params) {
|
|
|
592
609
|
days: reservation.days || 1,
|
|
593
610
|
});
|
|
594
611
|
} catch (e) {
|
|
595
|
-
console.warn('[calendar-
|
|
612
|
+
console.warn('[calendar-onekite] email payment-confirmed error:', e.message);
|
|
596
613
|
}
|
|
597
614
|
|
|
598
615
|
res.json({ ok: true });
|
|
599
616
|
} catch (err) {
|
|
600
|
-
console.error('[calendar-
|
|
617
|
+
console.error('[calendar-onekite] HelloAsso webhook error:', err);
|
|
601
618
|
res.status(500).json({ error: err.message });
|
|
602
619
|
}
|
|
603
620
|
});
|
|
604
621
|
|
|
605
|
-
/* PAGE ADMIN PLUGIN */
|
|
622
|
+
/* PAGE ADMIN PLUGIN (CORRIGÉ) */
|
|
606
623
|
|
|
607
|
-
router.get('/admin/plugins/
|
|
608
|
-
router.get('/api/admin/plugins/
|
|
624
|
+
router.get('/admin/plugins/calendar-onekite', middleware.admin.buildHeader, renderAdminPage);
|
|
625
|
+
router.get('/api/admin/plugins/calendar-onekite', renderAdminPage);
|
|
609
626
|
|
|
610
|
-
router.put('/api/admin/plugins/
|
|
627
|
+
router.put('/api/admin/plugins/calendar-onekite', middleware.admin.checkPrivileges, async (req, res) => {
|
|
611
628
|
try {
|
|
612
|
-
await Settings.set('calendar-
|
|
629
|
+
await Settings.set('calendar-onekite', req.body);
|
|
613
630
|
res.json({ status: 'ok' });
|
|
614
631
|
} catch (err) {
|
|
615
632
|
res.status(500).json({ error: err.message });
|
|
@@ -708,9 +725,9 @@ function renderPlanningPage(req, res) {
|
|
|
708
725
|
|
|
709
726
|
Plugin.addAdminNavigation = function (header) {
|
|
710
727
|
header.plugins.push({
|
|
711
|
-
route: '/plugins/calendar-
|
|
728
|
+
route: '/plugins/calendar-onekite',
|
|
712
729
|
icon: 'fa fa-calendar',
|
|
713
|
-
name: 'Calendar
|
|
730
|
+
name: 'Calendar OneKite',
|
|
714
731
|
});
|
|
715
732
|
return header;
|
|
716
733
|
};
|
|
@@ -727,7 +744,7 @@ Plugin.defineWidgets = async function (widgets) {
|
|
|
727
744
|
|
|
728
745
|
Plugin.renderUpcomingWidget = async function (widget, callback) {
|
|
729
746
|
try {
|
|
730
|
-
const settings = await Settings.get('calendar-
|
|
747
|
+
const settings = (await Settings.get('calendar-onekite')) || {};
|
|
731
748
|
const limit = Number(widget.data.limit || settings.limit || 5);
|
|
732
749
|
const events = await getUpcomingEvents(limit);
|
|
733
750
|
const html = await appRef.renderAsync('widgets/calendar-upcoming', { events });
|
package/package.json
CHANGED
package/plugin.json
CHANGED
package/static/js/admin.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
$(document).ready(function () {
|
|
4
|
-
if (!$('#calendar-
|
|
4
|
+
if (!$('#calendar-onekite-admin').length && !$('#calendar-planning').length) return;
|
|
5
5
|
|
|
6
6
|
const AdminCalendar = {
|
|
7
7
|
|
|
8
8
|
initSettings: function () {
|
|
9
|
-
if (!$('#calendar-
|
|
9
|
+
if (!$('#calendar-onekite-admin').length) return;
|
|
10
10
|
AdminCalendar.bindSettingsSave();
|
|
11
11
|
AdminCalendar.loadPending();
|
|
12
12
|
},
|
|
@@ -17,11 +17,11 @@ $(document).ready(function () {
|
|
|
17
17
|
},
|
|
18
18
|
|
|
19
19
|
bindSettingsSave: function () {
|
|
20
|
-
$('#calendar-
|
|
20
|
+
$('#calendar-onekite-save').on('click', () => {
|
|
21
21
|
const settings = {
|
|
22
|
-
allowedGroups: $('#calendar-
|
|
23
|
-
allowedBookingGroups: $('#calendar-
|
|
24
|
-
limit: $('#calendar-
|
|
22
|
+
allowedGroups: $('#calendar-onekite-groups').val(),
|
|
23
|
+
allowedBookingGroups: $('#calendar-onekite-book-groups').val(),
|
|
24
|
+
limit: $('#calendar-onekite-widget-limit').val()
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
$.ajax({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<div id="calendar-
|
|
1
|
+
<div id="calendar-onekite-admin">
|
|
2
2
|
<h2>Calendar Lite – Administration</h2>
|
|
3
3
|
|
|
4
4
|
<h3>Réservations en attente</h3>
|
|
@@ -10,19 +10,20 @@
|
|
|
10
10
|
|
|
11
11
|
<div class="form-group">
|
|
12
12
|
<label>Groupes autorisés à créer / modifier des événements</label>
|
|
13
|
-
<input id="calendar-
|
|
13
|
+
<input id="calendar-onekite-groups" class="form-control" value="{settings.allowedGroups}">
|
|
14
14
|
<small>Ex : administrators, moderators</small>
|
|
15
15
|
</div>
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
<div class="form-group">
|
|
18
19
|
<label>Nombre d’événements dans le widget</label>
|
|
19
|
-
<input id="calendar-
|
|
20
|
+
<input id="calendar-onekite-widget-limit" type="number" class="form-control" value="{settings.limit}">
|
|
20
21
|
<label>Groupes autorisés à réserver</label>
|
|
21
|
-
<input id="calendar-
|
|
22
|
+
<input id="calendar-onekite-book-groups" class="form-control" value="{settings.allowedBookingGroups}">
|
|
22
23
|
<small>Ex : registered-users, membres, vip</small>
|
|
23
24
|
</div>
|
|
24
25
|
|
|
25
|
-
<button id="calendar-
|
|
26
|
+
<button id="calendar-onekite-save" class="btn btn-primary">Enregistrer</button>
|
|
26
27
|
</div>
|
|
27
28
|
|
|
28
|
-
<script src="/plugins/nodebb-plugin-calendar-
|
|
29
|
+
<script src="/plugins/nodebb-plugin-calendar-onekite/static/js/admin.js"></script>
|