Skip to content

Node.js based forum software built for the modern web

fixed admin bug (on f5 was not populating fields); plugins - filter:admin.create_routes allows you to create path to custom admin page

psychobunny32990794ce7f
diff --git a/public/src/forum/admin/footer.js b/public/src/forum/admin/footer.js
index 22990fcf7b..8a99da7a74 100644
--- a/public/src/forum/admin/footer.js
+++ b/public/src/forum/admin/footer.js
@@ -16,9 +16,7 @@ jQuery('document').ready(function() {
});
socket.once('api:config.get', function(config) {
- require(['forum/admin/settings'], function(Settings) {
- Settings.config = config;
- });
+ app.config = config;
});
socket.emit('api:config.get');
diff --git a/public/src/forum/admin/settings.js b/public/src/forum/admin/settings.js
index 75f1a78c83..b6017af47e 100644
--- a/public/src/forum/admin/settings.js
+++ b/public/src/forum/admin/settings.js
@@ -1,18 +1,16 @@
define(function() {
var Settings = {};
- Settings.config = {};
-
Settings.init = function() {
Settings.prepare();
};
Settings.prepare = function() {
- // Come back in 500ms if the config isn't ready yet
- if (Settings.config === undefined) {
+ // Come back in 125ms if the config isn't ready yet
+ if (!app.config) {
setTimeout(function() {
Settings.prepare();
- }, 500);
+ }, 125);
return;
}
@@ -25,21 +23,21 @@ define(function() {
key = fields[x].getAttribute('data-field');
inputType = fields[x].getAttribute('type');
if (fields[x].nodeName === 'INPUT') {
- if (Settings.config[key]) {
+ if (app.config[key]) {
switch (inputType) {
case 'text':
case 'textarea':
case 'number':
- fields[x].value = Settings.config[key];
+ fields[x].value = app.config[key];
break;
case 'checkbox':
- fields[x].checked = Settings.config[key] === '1' ? true : false;
+ fields[x].checked = app.config[key] === '1' ? true : false;
break;
}
}
} else if (fields[x].nodeName === 'TEXTAREA') {
- if (Settings.config[key]) fields[x].value = Settings.config[key];
+ if (app.config[key]) fields[x].value = app.config[key];
}
}
diff --git a/public/templates/admin/header.tpl b/public/templates/admin/header.tpl
index 0a0a8ba69a..ba2cdf32c7 100644
--- a/public/templates/admin/header.tpl
+++ b/public/templates/admin/header.tpl
@@ -104,7 +104,7 @@
<li class="nav-header">Plugins</li>
<!-- BEGIN plugins -->
<li>
- <a href='{relative_path}/admin/{plugins.route}'><i class="{plugins.icon}"></i> {plugins.name}</a>
+ <a href='{relative_path}/admin{plugins.route}'><i class="{plugins.icon}"></i> {plugins.name}</a>
</li>
<!-- END plugins -->
</ul>
diff --git a/src/routes/admin.js b/src/routes/admin.js
index c0ad93387e..28d0044849 100644
--- a/src/routes/admin.js
+++ b/src/routes/admin.js
@@ -80,6 +80,30 @@ var user = require('./../user.js'),
});
});
+
+ var custom_routes = {
+ 'routes': [],
+ 'api_methods': []
+ };
+
+ plugins.ready(function() {
+ plugins.fireHook('filter:admin.create_routes', custom_routes, function(err, custom_routes) {
+ var routes = custom_routes.routes;
+
+ for (var route in routes) {
+ if (routes.hasOwnProperty(route)) {
+ app[routes[route].method || 'get']('/admin' + routes[route].route, function(req, res) {
+ routes[route].options(req, res, function(options) {
+ Admin.build_header(res, function (err, header) {
+ res.send(header + options.content + templates['admin/footer']);
+ });
+ });
+ });
+ }
+ }
+ });
+ });
+
app.namespace('/api/admin', function () {
app.get('/index', function (req, res) {
res.json({