You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/src/widgets.js

56 lines
1.2 KiB
JavaScript

var async = require('async'),
winston = require('winston'),
11 years ago
plugins = require('./plugins'),
db = require('./database');
(function(Widgets) {
11 years ago
Widgets.render = function(uid, area, callback) {
if (!area.location || !area.template) {
callback({
error: 'Missing location and template data'
});
}
var rendered = [];
Widgets.getArea(area.template, area.location, function(err, widgets) {
async.each(widgets, function(widget, next) {
plugins.fireHook('filter:widget.render:' + widget.widget, {
uid: uid,
area: area,
data: widget.data
}, function(err, data){
11 years ago
rendered.push({
html: data.html,
title: data.title
11 years ago
});
next(err);
11 years ago
});
}, function(err) {
callback(err, rendered);
});
});
};
Widgets.getArea = function(template, location, callback) {
db.getObjectField('widgets:' + template, location, function(err, widgets) {
callback(err, JSON.parse(widgets));
})
};
11 years ago
Widgets.setArea = function(area, callback) {
if (!area.location || !area.template) {
callback({
error: 'Missing location and template data'
});
}
11 years ago
db.setObjectField('widgets:' + area.template, area.location, JSON.stringify(area.widgets), function(err) {
callback(err);
});
};
}(exports));