+
- Markdown Markdown formatted text
+ Text Markdown formatted text
diff --git a/src/routes/admin.js b/src/routes/admin.js
index ceb2074d06..fa60980dcf 100644
--- a/src/routes/admin.js
+++ b/src/routes/admin.js
@@ -2,6 +2,7 @@ var nconf = require('nconf'),
fs = require('fs'),
path = require('path'),
winston = require('winston'),
+ async = require('async'),
db = require('./../database'),
user = require('./../user'),
@@ -11,6 +12,7 @@ var nconf = require('nconf'),
categories = require('./../categories'),
meta = require('../meta'),
plugins = require('../plugins'),
+ widgets = require('../widgets'),
image = require('./../image'),
file = require('./../file'),
Languages = require('../languages'),
@@ -411,9 +413,17 @@ var nconf = require('nconf'),
app.get('/themes', function (req, res) {
plugins.fireHook('filter:widgets.getAreas', [], function(err, areas) {
- res.json(200, {
- areas: areas
+ async.each(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,
+ });
});
+
});
});
diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js
index da1de17596..21f3d8bf11 100644
--- a/src/socket.io/admin.js
+++ b/src/socket.io/admin.js
@@ -3,6 +3,7 @@
var groups = require('../groups'),
meta = require('../meta'),
plugins = require('../plugins'),
+ widgets = require('../widgets'),
user = require('../user'),
topics = require('../topics'),
categories = require('../categories'),
@@ -255,10 +256,11 @@ SocketAdmin.categories.groupsList = function(socket, cid, callback) {
});
};
-/* Themes & Plugins */
+/* Themes, Widgets, and Plugins */
SocketAdmin.themes = {};
SocketAdmin.plugins = {};
+SocketAdmin.widgets = {};
SocketAdmin.themes.getInstalled = function(socket, data, callback) {
meta.themes.get(callback);
@@ -269,7 +271,7 @@ SocketAdmin.themes.set = function(socket, data, callback) {
return callback(new Error('invalid data'));
}
meta.themes.set(data, callback);
-}
+};
SocketAdmin.plugins.toggle = function(socket, plugin_id) {
plugins.toggleActive(plugin_id, function(status) {
@@ -277,6 +279,14 @@ SocketAdmin.plugins.toggle = function(socket, plugin_id) {
});
};
+SocketAdmin.widgets.set = function(socket, data, callback) {
+ if(!data) {
+ return callback(new Error('invalid data'));
+ }
+
+ widgets.setArea(data, callback);
+};
+
/* Configs */
SocketAdmin.config = {};
diff --git a/src/widgets.js b/src/widgets.js
new file mode 100644
index 0000000000..5c506619af
--- /dev/null
+++ b/src/widgets.js
@@ -0,0 +1,26 @@
+var async = require('async'),
+ winston = require('winston'),
+ db = require('./database');
+
+
+(function(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) {
+ callback(err);
+ });
+ };
+
+ 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