Skip to content

Node.js based forum software built for the modern web

draft zone for widgets, closes #1238

psychobunny7926514c9501
diff --git a/src/controllers/admin.js b/src/controllers/admin.js
index d940e06534..a326029f97 100644
--- a/src/controllers/admin.js
+++ b/src/controllers/admin.js
@@ -120,6 +120,8 @@ adminController.themes.get = function(req, res, next) {
plugins.fireHook('filter:widgets.getWidgets', [], next);
}
}, function(err, widgetData) {
+ widgetData.areas.push({ name: 'Drafts', template: 'global', location: 'drafts' });
+
async.each(widgetData.areas, function(area, next) {
widgets.getArea(area.template, area.location, function(err, areaData) {
area.data = areaData;
diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js
index 72ed56d833..54537fd273 100644
--- a/src/socket.io/admin.js
+++ b/src/socket.io/admin.js
@@ -284,9 +284,12 @@ SocketAdmin.themes.set = function(socket, data, callback) {
if(!data) {
return callback(new Error('invalid data'));
}
- meta.themes.set(data, function() {
- callback();
- meta.restart()
+
+ widgets.reset(function(err) {
+ meta.themes.set(data, function() {
+ callback();
+ meta.restart();
+ });
});
};
diff --git a/src/widgets.js b/src/widgets.js
index e1ca3b504c..f8b782efff 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -74,4 +74,25 @@ var async = require('async'),
});
};
+ Widgets.reset = function(callback) {
+ plugins.fireHook('filter:widgets.getAreas', [], function(err, areas) {
+ var drafts = [];
+
+ async.each(areas, function(area, next) {
+ Widgets.getArea(area.template, area.location, function(err, areaData) {
+ drafts = drafts.concat(areaData);
+ area.widgets = [];
+ Widgets.setArea(area, next);
+ });
+ }, function(err) {
+ console.log(drafts);
+ Widgets.setArea({
+ template: 'global',
+ location: 'drafts',
+ widgets: drafts
+ }, callback);
+ });
+ });
+ };
+
}(exports));
\ No newline at end of file