nodebb-plugin-equipment-calendar 10.0.0 → 10.0.2
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/package.json +1 -1
- package/public/js/admin.js +60 -78
package/package.json
CHANGED
package/public/js/admin.js
CHANGED
|
@@ -1,97 +1,79 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
/* globals ajaxify, socket,
|
|
2
|
+
/* globals ajaxify, app, socket, require, $ */
|
|
3
3
|
|
|
4
|
+
// Official NodeBB ACP pattern uses the Settings module (AMD) + jQuery events.
|
|
4
5
|
(function () {
|
|
5
6
|
const HASH = 'equipmentCalendar';
|
|
6
7
|
|
|
7
|
-
function
|
|
8
|
+
function onPage() {
|
|
8
9
|
try {
|
|
9
|
-
const url = (ajaxify && ajaxify.data && ajaxify.data.url) ? ajaxify.data.url : '';
|
|
10
|
-
return url
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return document.querySelector('.equipment-calendar-settings');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function fields() {
|
|
19
|
-
return Array.from(document.querySelectorAll('.equipment-calendar-settings [data-field]'));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function setValues(values) {
|
|
23
|
-
const map = values || {};
|
|
24
|
-
fields().forEach((el) => {
|
|
25
|
-
const key = el.getAttribute('data-field');
|
|
26
|
-
let val = map[key];
|
|
27
|
-
if (val === undefined || val === null) val = '';
|
|
28
|
-
el.value = String(val);
|
|
29
|
-
});
|
|
10
|
+
const url = (ajaxify && ajaxify.data && typeof ajaxify.data.url === 'string') ? ajaxify.data.url : '';
|
|
11
|
+
return url === 'admin/plugins/equipment-calendar' || url === '/admin/plugins/equipment-calendar' ||
|
|
12
|
+
url.startsWith('admin/plugins/equipment-calendar?') || url.startsWith('/admin/plugins/equipment-calendar?');
|
|
13
|
+
} catch (e) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
30
16
|
}
|
|
31
17
|
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
out[key] = el.value;
|
|
37
|
-
});
|
|
38
|
-
return out;
|
|
39
|
-
}
|
|
18
|
+
function init() {
|
|
19
|
+
if (!onPage()) return;
|
|
20
|
+
const $container = $('.equipment-calendar-settings');
|
|
21
|
+
if (!$container.length) return;
|
|
40
22
|
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
function alertError(msg) {
|
|
46
|
-
if (window.app && typeof app.alertError === 'function') return app.alertError(msg);
|
|
47
|
-
console.error('[error]', msg);
|
|
48
|
-
}
|
|
23
|
+
// Prefer Settings module when available (official behaviour)
|
|
24
|
+
if (typeof require === 'function') {
|
|
25
|
+
require(['settings'], function (Settings) {
|
|
26
|
+
Settings.load(HASH, $container);
|
|
49
27
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
28
|
+
$('#ec-save').off('click.ec').on('click.ec', function () {
|
|
29
|
+
Settings.save(HASH, $container, function () {
|
|
30
|
+
if (app && app.alertSuccess) {
|
|
31
|
+
app.alertSuccess('[[admin/settings:settings-saved]]');
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
56
35
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
async function load() {
|
|
61
|
-
const data = await socketEmit('admin.settings.get', { hash: HASH });
|
|
62
|
-
const values = (data && (data.values || data)) || {};
|
|
63
|
-
setValues(values);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function save() {
|
|
67
|
-
const values = getValues();
|
|
68
|
-
await socketEmit('admin.settings.save', { hash: HASH, values });
|
|
69
|
-
}
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
70
38
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
39
|
+
// Fallback: raw socket calls (in case require is unavailable)
|
|
40
|
+
const fields = $container.find('[data-field]');
|
|
41
|
+
function getValues() {
|
|
42
|
+
const values = {};
|
|
43
|
+
fields.each(function () {
|
|
44
|
+
const $el = $(this);
|
|
45
|
+
values[$el.attr('data-field')] = $el.val();
|
|
46
|
+
});
|
|
47
|
+
return values;
|
|
48
|
+
}
|
|
49
|
+
function setValues(values) {
|
|
50
|
+
values = values || {};
|
|
51
|
+
fields.each(function () {
|
|
52
|
+
const $el = $(this);
|
|
53
|
+
const key = $el.attr('data-field');
|
|
54
|
+
$el.val(values[key] || '');
|
|
55
|
+
});
|
|
56
|
+
}
|
|
74
57
|
|
|
75
|
-
|
|
58
|
+
socket.emit('admin.settings.get', { hash: HASH }, function (err, data) {
|
|
59
|
+
if (err) return;
|
|
60
|
+
setValues((data && (data.values || data)) || {});
|
|
61
|
+
});
|
|
76
62
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
await save();
|
|
84
|
-
alertSuccess('[[admin/settings:settings-saved]]');
|
|
85
|
-
} catch (err) {
|
|
86
|
-
alertError(err && err.message ? err.message : String(err));
|
|
63
|
+
$('#ec-save').off('click.ec').on('click.ec', function () {
|
|
64
|
+
socket.emit('admin.settings.save', { hash: HASH, values: getValues() }, function (err) {
|
|
65
|
+
if (err) {
|
|
66
|
+
app && app.alertError && app.alertError(err.message || String(err));
|
|
67
|
+
return;
|
|
87
68
|
}
|
|
69
|
+
app && app.alertSuccess && app.alertSuccess('[[admin/settings:settings-saved]]');
|
|
88
70
|
});
|
|
89
|
-
}
|
|
71
|
+
});
|
|
90
72
|
}
|
|
91
73
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
74
|
+
// Official NodeBB event binding (see NodeBB hooks docs)
|
|
75
|
+
$(window).off('action:ajaxify.end.ec').on('action:ajaxify.end.ec', init);
|
|
76
|
+
|
|
77
|
+
// Run once in case the page is already loaded
|
|
78
|
+
$(init);
|
|
97
79
|
})();
|