nodebb-plugin-calendar-onekite 11.1.12 → 11.1.13

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/library.js CHANGED
@@ -1,5 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ // We use NodeBB's route helpers for page routes so the rendered page includes
4
+ // the normal client bundle (ajaxify/requirejs). The helper signatures differ
5
+ // across NodeBB versions, but for NodeBB v4.x the order is:
6
+ // setupPageRoute(router, path, middlewaresArray, handler)
7
+ // setupAdminPageRoute(router, path, middlewaresArray, handler)
3
8
  const routeHelpers = require.main.require('./src/routes/helpers');
4
9
 
5
10
  const controllers = require('./lib/controllers');
@@ -15,18 +20,11 @@ const mw = (...fns) => fns.filter(isFn);
15
20
  Plugin.init = async function (params) {
16
21
  const { router, middleware } = params;
17
22
 
18
- // Public page
19
- const publicMws = mw(middleware.exposeUid, middleware.buildHeader);
20
- router.get('/calendar', ...publicMws, controllers.renderCalendar);
21
-
22
- // ACP page
23
- const adminPageMws = mw(
24
- middleware.exposeUid,
25
- middleware.ensureLoggedIn,
26
- middleware.admin && middleware.admin.checkPrivileges,
27
- middleware.admin && middleware.admin.buildHeader
28
- );
29
- router.get('/admin/plugins/calendar-onekite', ...adminPageMws, admin.renderAdmin);
23
+ // Page routes (HTML)
24
+ // IMPORTANT: pass an ARRAY for middlewares (even if empty), otherwise
25
+ // setupPageRoute will throw "middlewares is not iterable".
26
+ routeHelpers.setupPageRoute(router, '/calendar', mw(), controllers.renderCalendar);
27
+ routeHelpers.setupAdminPageRoute(router, '/admin/plugins/calendar-onekite', mw(), admin.renderAdmin);
30
28
 
31
29
  // Public API (JSON)
32
30
  router.get('/api/v3/plugins/calendar-onekite/events', mw(middleware.exposeUid), api.getEvents);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-calendar-onekite",
3
- "version": "11.1.12",
3
+ "version": "11.1.13",
4
4
  "description": "FullCalendar-based equipment reservation workflow with admin approval & HelloAsso payment for NodeBB",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
package/public/client.js CHANGED
@@ -1,6 +1,6 @@
1
- /* global FullCalendar */
1
+ /* global FullCalendar, ajaxify */
2
2
 
3
- define('forum/calendar-onekite', ['alerts', 'bootbox'], function (alerts, bootbox) {
3
+ define('forum/calendar-onekite', ['alerts', 'bootbox', 'hooks'], function (alerts, bootbox, hooks) {
4
4
  'use strict';
5
5
 
6
6
  function showAlert(type, msg) {
@@ -137,6 +137,24 @@ define('forum/calendar-onekite', ['alerts', 'bootbox'], function (alerts, bootbo
137
137
  calendar.render();
138
138
  }
139
139
 
140
+ // Auto-init on /calendar when ajaxify finishes rendering.
141
+ function autoInit(data) {
142
+ try {
143
+ const tpl = data && data.template ? data.template.name : (ajaxify && ajaxify.data && ajaxify.data.template ? ajaxify.data.template.name : '');
144
+ if (tpl === 'calendar-onekite') {
145
+ init('#onekite-calendar');
146
+ }
147
+ } catch (e) {}
148
+ }
149
+
150
+ if (hooks && typeof hooks.on === 'function') {
151
+ hooks.on('action:ajaxify.end', autoInit);
152
+ }
153
+
154
+ // In case the page is served as the initial load (no ajaxify navigation)
155
+ // call once after current tick.
156
+ setTimeout(() => autoInit({ template: (ajaxify && ajaxify.data && ajaxify.data.template) || { name: '' } }), 0);
157
+
140
158
  return {
141
159
  init,
142
160
  };
@@ -1,3 +1,5 @@
1
+ <!-- IMPORT admin/partials/settings/header.tpl -->
2
+
1
3
  <div class="acp-page-container">
2
4
  <div class="row">
3
5
  <div class="col-lg-8">
@@ -74,6 +76,8 @@
74
76
  </div>
75
77
  </div>
76
78
 
79
+ <!-- IMPORT admin/partials/settings/footer.tpl -->
80
+
77
81
  <script>
78
82
  require(['admin/plugins/calendar-onekite'], function (m) {
79
83
  m.init();
@@ -11,8 +11,7 @@
11
11
  <script src="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.11/index.global.min.js"></script>
12
12
  <script src="https://cdn.jsdelivr.net/npm/@fullcalendar/core@6.1.11/locales-all.global.min.js"></script>
13
13
 
14
- <script>
15
- require(['forum/calendar-onekite'], function (m) {
16
- m.init('#onekite-calendar');
17
- });
18
- </script>
14
+ <!--
15
+ No inline require() here.
16
+ The plugin's forum script auto-initialises on the calendar page via ajaxify.
17
+ -->