mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-06-19 20:21:22 +02:00
allow plugins/widgets to define widgets; moved sample widgets out of core and into nodebb-widget-essentials
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -57,32 +57,17 @@
|
||||
<div class="col-xs-6 available-widgets">
|
||||
<h4>Available Widgets</h4>
|
||||
<div class="well">
|
||||
<div data-widget="html" class="panel panel-default pointer">
|
||||
<div class="panel-heading">
|
||||
<strong>HTML</strong> <small>Any text, html, or embedded script.</small>
|
||||
</div>
|
||||
<div class="panel-body hidden">
|
||||
<form>
|
||||
<textarea class="form-control" rows="6" name="html" placeholder="Enter HTML"></textarea>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div data-widget="text" class="panel panel-default pointer">
|
||||
<div class="panel-heading">
|
||||
<strong>Text</strong> <small>Markdown formatted text</small>
|
||||
</div>
|
||||
<div class="panel-body hidden">
|
||||
<form>
|
||||
<textarea class="form-control" rows="6" name="text" placeholder="Enter Text / Markdown"></textarea>
|
||||
<hr />
|
||||
<div class="checkbox">
|
||||
<label><input type="checkbox" name="markdown" checked /> Parse as Markdown?</label>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<!-- BEGIN widgets -->
|
||||
|
||||
<div data-widget="{widgets.widget}" class="panel panel-default pointer">
|
||||
<div class="panel-heading">
|
||||
<strong>{widgets.name}</strong> <small>{widgets.description}</small>
|
||||
</div>
|
||||
<div class="panel-body hidden">
|
||||
<form>
|
||||
{widgets.content}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<!-- END widgets -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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));
|
||||
Reference in New Issue
Block a user