From 4e1b3506e8c4368d1e9936e0662ae146cf8a766e Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 19 Feb 2014 16:11:16 -0500 Subject: [PATCH] allow plugins/widgets to define widgets; moved sample widgets out of core and into nodebb-widget-essentials --- public/src/forum/admin/themes.js | 1 - public/templates/admin/themes.tpl | 35 +++++++++---------------------- src/routes/admin.js | 15 +++++++++---- src/widgets.js | 14 ++++++------- 4 files changed, 28 insertions(+), 37 deletions(-) diff --git a/public/src/forum/admin/themes.js b/public/src/forum/admin/themes.js index 90b74f7ee0..37180be94b 100644 --- a/public/src/forum/admin/themes.js +++ b/public/src/forum/admin/themes.js @@ -235,7 +235,6 @@ define(['forum/admin/settings'], function(Settings) { var data = area.data[i], widgetEl = $('.available-widgets [data-widget="' + data.widget + '"]').clone(); - widgetArea.append(populateWidget(widgetEl, data.data)); appendToggle(widgetEl); } diff --git a/public/templates/admin/themes.tpl b/public/templates/admin/themes.tpl index b33e7796fd..861dbaee37 100644 --- a/public/templates/admin/themes.tpl +++ b/public/templates/admin/themes.tpl @@ -57,32 +57,17 @@

Available Widgets

-
-
- HTML Any text, html, or embedded script. -
- -
-
-
- Text Markdown formatted text -
- -
- +
+
+ {widgets.name} {widgets.description} +
+ +
diff --git a/src/routes/admin.js b/src/routes/admin.js index fa60980dcf..4213cd15a6 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -412,18 +412,25 @@ var nconf = require('nconf'), }); app.get('/themes', function (req, res) { - plugins.fireHook('filter:widgets.getAreas', [], function(err, areas) { - async.each(areas, function(area, next) { + async.parallel({ + areas: function(next) { + plugins.fireHook('filter:widgets.getAreas', [], next); + }, + widgets: function(next) { + plugins.fireHook('filter:widgets.getWidgets', [], next); + } + }, function(err, data) { + async.each(data.areas, function(area, next) { widgets.getArea(area.template, area.location, function(err, areaData) { area.data = areaData; next(err); }); }, function(err) { res.json(200, { - areas: areas, + areas: data.areas, + widgets: data.widgets }); }); - }); }); diff --git a/src/widgets.js b/src/widgets.js index 5c506619af..5e9e754d2d 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -5,11 +5,17 @@ var async = require('async'), (function(Widgets) { + 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) { callback({ error: 'Missing location and template data' - }) + }); } db.setObjectField('widgets:' + data.template, data.location, JSON.stringify(data.widgets), function(err) { @@ -17,10 +23,4 @@ var async = require('async'), }); }; - Widgets.getArea = function(template, location, callback) { - db.getObjectField('widgets:' + template, location, function(err, widgets) { - callback(err, JSON.parse(widgets)); - }) - }; - }(exports)); \ No newline at end of file