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

v1.18.x
psychobunny 12 years ago
parent 4b5bae4f9b
commit 32990794ce

@ -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');

@ -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];
}
}

@ -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>

@ -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({

Loading…
Cancel
Save