mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 20:45:58 +01:00
widgets.render
This commit is contained in:
@@ -1,24 +1,51 @@
|
||||
var async = require('async'),
|
||||
winston = require('winston'),
|
||||
plugins = require('./plugins'),
|
||||
db = require('./database');
|
||||
|
||||
|
||||
(function(Widgets) {
|
||||
|
||||
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, html){
|
||||
rendered.push({
|
||||
html: html
|
||||
});
|
||||
});
|
||||
}, function(err) {
|
||||
callback(err, rendered);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Widgets.getArea = function(template, location, callback) {
|
||||
db.getObjectField('widgets:' + template, location, function(err, widgets) {
|
||||
callback(err, JSON.parse(widgets));
|
||||
})
|
||||
};
|
||||
|
||||
Widgets.setArea = function(data, callback) {
|
||||
if (!data.location || !data.template) {
|
||||
Widgets.setArea = function(area, callback) {
|
||||
if (!area.location || !data.template) {
|
||||
callback({
|
||||
error: 'Missing location and template data'
|
||||
});
|
||||
}
|
||||
|
||||
db.setObjectField('widgets:' + data.template, data.location, JSON.stringify(data.widgets), function(err) {
|
||||
db.setObjectField('widgets:' + area.template, area.location, JSON.stringify(area.widgets), function(err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user