moved widget code out of controller; cleaned up code into a folder

This commit is contained in:
psychobunny
2015-05-11 14:20:10 -04:00
parent 394d55de99
commit 0f199af84d
4 changed files with 237 additions and 218 deletions

View File

@@ -15,7 +15,6 @@ var async = require('async'),
events = require('../events'),
languages = require('../languages'),
plugins = require('../plugins'),
widgets = require('../widgets'),
groups = require('../groups'),
validator = require('validator');
@@ -364,70 +363,12 @@ adminController.appearance.get = function(req, res, next) {
};
adminController.extend.widgets = function(req, res, next) {
async.parallel({
areas: function(next) {
var defaultAreas = [
{ name: 'Global Sidebar', template: 'global', location: 'sidebar' },
{ name: 'Global Header', template: 'global', location: 'header' },
{ name: 'Global Footer', template: 'global', location: 'footer' },
{ name: 'Group Page (Left)', template: 'groups/details.tpl', location: 'left'},
{ name: 'Group Page (Right)', template: 'groups/details.tpl', location: 'right'}
];
plugins.fireHook('filter:widgets.getAreas', defaultAreas, next);
},
widgets: function(next) {
plugins.fireHook('filter:widgets.getWidgets', [], next);
}
}, function(err, widgetData) {
require('../widgets/admin').get(function(err, data) {
if (err) {
return next(err);
}
widgetData.areas.push({ name: 'Draft Zone', template: 'global', location: 'drafts' });
async.each(widgetData.areas, function(area, next) {
widgets.getArea(area.template, area.location, function(err, areaData) {
area.data = areaData;
next(err);
});
}, function(err) {
if (err) {
return next(err);
}
for (var w in widgetData.widgets) {
if (widgetData.widgets.hasOwnProperty(w)) {
// if this gets anymore complicated, it needs to be a template
widgetData.widgets[w].content += "<br /><label>Title:</label><input type=\"text\" class=\"form-control\" name=\"title\" placeholder=\"Title (only shown on some containers)\" /><br /><label>Container:</label><textarea rows=\"4\" class=\"form-control container-html\" name=\"container\" placeholder=\"Drag and drop a container or enter HTML here.\"></textarea><div class=\"checkbox\"><label><input name=\"hide-guests\" type=\"checkbox\"> Hide from anonymous users?</label></div><div class=\"checkbox\"><label><input name=\"hide-registered\" type=\"checkbox\"> Hide from registered users?</input></label></div>";
}
}
var templates = [],
list = {}, index = 0;
widgetData.areas.forEach(function(area) {
if (typeof list[area.template] === 'undefined') {
list[area.template] = index;
templates.push({
template: area.template,
areas: []
});
index++;
}
templates[list[area.template]].areas.push({
name: area.name,
location: area.location
});
});
res.render('admin/extend/widgets', {
templates: templates,
areas: widgetData.areas,
widgets: widgetData.widgets
});
});
res.render('admin/extend/widgets', data);
});
};