forked from NodeBB-Community/nodebb-plugin-shoutbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.js
125 lines (97 loc) · 3.08 KB
/
library.js
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
"use strict";
var NodeBB = require('./lib/nodebb'),
Config = require('./lib/config'),
Sockets = require('./lib/sockets'),
app,
Shoutbox = {};
Shoutbox.init = {};
Shoutbox.widget = {};
Shoutbox.settings = {};
Shoutbox.init.load = function(params, callback) {
function renderGlobal(req, res, next) {
Config.getTemplateData(function(data) {
res.render(Config.plugin.id, data);
});
}
function renderAdmin(req, res, next) {
Config.getTemplateData(function(data) {
res.render('admin/plugins/' + Config.plugin.id, data);
});
}
var router = params.router;
router.get('/' + Config.plugin.id, params.middleware.buildHeader, renderGlobal);
router.get('/api/' + Config.plugin.id, renderGlobal);
router.get('/admin/plugins/' + Config.plugin.id, params.middleware.admin.buildHeader, renderAdmin);
router.get('/api/admin/plugins/' + Config.plugin.id, renderAdmin);
NodeBB.SocketPlugins[Config.plugin.id] = Sockets.events;
NodeBB.SocketAdmin[Config.plugin.id] = Config.adminSockets;
app = params.app;
Config.init(callback);
};
Shoutbox.init.addGlobalNavigation = function(menu, callback) {
menu = menu.concat([
{
route: '/' + Config.plugin.id,
title: Config.plugin.name,
iconClass: 'fa fa-fw ' + Config.plugin.icon,
textClass: "visible-xs-inline",
text: Config.plugin.name
}
]);
callback(null, menu);
};
Shoutbox.init.addAdminNavigation = function(header, callback) {
header.plugins.push({
route: '/plugins/' + Config.plugin.id,
icon: Config.plugin.icon,
name: Config.plugin.name
});
callback(null, header);
};
Shoutbox.widget.define = function(widgets, callback) {
widgets.push({
name: Config.plugin.name,
widget: Config.plugin.id,
description: Config.plugin.description,
content: ''
});
callback(null, widgets);
};
Shoutbox.widget.render = function(widget, callback) {
widget.data.container = '';
Config.user.get({ uid: widget.uid, settings: {} }, function(err, result) {
Config.getTemplateData(function(data) {
data.hiddenStyle = '';
if (!err && result && result.settings && parseInt(result.settings['shoutbox:toggles:hide'], 10) == 1) {
data.hiddenStyle = 'display: none;';
}
app.render('shoutbox/panel', data, function(err, html) {
widget.html = html;
callback(err, widget);
});
});
});
};
Shoutbox.settings.addUserSettings = function(settings, callback) {
app.render('shoutbox/user/settings', { settings: settings.settings }, function(err, html) {
settings.customSettings.push({
title: Config.plugin.name,
content: html
});
callback(null, settings);
});
};
Shoutbox.settings.addUserFieldWhitelist = function (data, callback) {
data.whitelist.push('shoutbox:toggles:sound');
data.whitelist.push('shoutbox:toggles:notification');
data.whitelist.push('shoutbox:toggles:hide');
data.whitelist.push('shoutbox:muted');
callback(null, data);
};
Shoutbox.settings.getUserSettings = function(data, callback) {
Config.user.get(data, callback);
};
Shoutbox.settings.saveUserSettings = function(data) {
Config.user.save(data);
};
module.exports = Shoutbox;