-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.js
More file actions
51 lines (43 loc) · 1.2 KB
/
library.js
File metadata and controls
51 lines (43 loc) · 1.2 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
'use strict';
var async = module.parent.require('async');
const plugin = {};
var app;
plugin.init = function (params, callback) {
app = params.app;
callback();
};
plugin.defineWidgets = function (widgets, callback) {
var widget = {
widget: 'lastupdated',
name: 'Topic Last Updated',
description: 'Displays the date when the topic was last updated',
content: 'admin/lastupdated.tpl',
};
app.render(widget.content, {}, function (err, html) {
widget.content = html;
widgets.push(widget);
callback(err, widgets);
});
};
plugin.renderWidget = function (widgetRenderParams, callback) {
if (widgetRenderParams.area.template !== 'topic.tpl') {
return callback(null, widgetRenderParams);
}
async.waterfall([
function (next) {
const lastpost_time = new Date(widgetRenderParams.area.templateData.lastposttime);
const english = new Intl.DateTimeFormat('en-GB', { month: 'long', day: 'numeric', year: 'numeric' });
const last_post = english.format(lastpost_time);
app.render('widgets/lastupdated', {
topic: {
last_post,
},
}, next);
},
function (html, next) {
widgetRenderParams.html = html;
next(null, widgetRenderParams);
},
], callback);
};
module.exports = plugin;