-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlibrary.js
More file actions
55 lines (41 loc) · 1.41 KB
/
Copy pathlibrary.js
File metadata and controls
55 lines (41 loc) · 1.41 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
"use strict";
var db = module.parent.require('./database'),
colorifyTopics = {},
defaultGroup = ['Bucket'];
colorifyTopics.init = function (params, callback) {
params.router.get('/admin/plugins/topic-color', params.middleware.admin.buildHeader, renderAdmin);
params.router.get('/api/admin/plugins/topic-color', renderAdmin);
params.router.get('/api/plugins/topic-color', renderFront);
params.router.post('/api/admin/plugins/topic-color/save', save);
callback();
};
colorifyTopics.addAdminNavigation = function(header, callback) {
header.plugins.push({
route: '/plugins/topic-color',
icon: 'fa-tint',
name: 'Topic Color'
});
callback(null, header);
};
function render (res, next, path) {
db.getObject('plugins:topic-color', function(err, data) {
if (err) {
return next(err);
}
if (data) {
data = { allowedGroups : JSON.parse(data.allowedGroups) };
} else {
data = { allowedGroups : defaultGroup };
}
res.render(path, data);
});
}
function renderAdmin (req, res, next) { render( res, next, 'admin/plugins/topic-color' ) }
function renderFront (req, res, next) { render( res, next, 'plugins/topic-color' ) }
function save (req, res, next) {
var data = { allowedGroups : req.body.allowedGroups };
db.setObject('plugins:topic-color', data, function(err) {
err ? res.json(500, 'Error while saving settings') : res.json('Settings successfully saved');
});
}
module.exports = colorifyTopics;