diff --git a/public/src/admin/general/homepage.js b/public/src/admin/general/homepage.js
new file mode 100644
index 0000000000..96a6aac0eb
--- /dev/null
+++ b/public/src/admin/general/homepage.js
@@ -0,0 +1,23 @@
+"use strict";
+/*global define*/
+
+define('admin/general/homepage', ['admin/settings'], function(Settings) {
+
+ function toggleCustomRoute() {
+ if ($('[data-field="homePageRoute"]').val()) {
+ $('#homePageCustom').hide();
+ }else{
+ $('#homePageCustom').show();
+ }
+ }
+
+ var Homepage = {};
+
+ Homepage.init = function() {
+ $('[data-field="homePageRoute"]').on('change', toggleCustomRoute);
+
+ toggleCustomRoute();
+ };
+
+ return Homepage;
+});
diff --git a/src/controllers/admin.js b/src/controllers/admin.js
index 776b6e9362..07c7f9f1da 100644
--- a/src/controllers/admin.js
+++ b/src/controllers/admin.js
@@ -348,21 +348,49 @@ adminController.navigation.get = function(req, res, next) {
};
adminController.homepage.get = function(req, res, next) {
- plugins.fireHook('filter:homepage.get', {routes: [
- {
- route: 'categories',
- name: 'Categories'
+ async.waterfall([
+ function(next) {
+ db.getSortedSetRange('cid:0:children', 0, -1, next);
+ },
+ function(cids, next) {
+ privileges.categories.filterCids('find', cids, 0, next);
},
- {
- route: 'recent',
- name: 'Recent'
+ function(cids, next) {
+ categories.getMultipleCategoryFields(cids, ['name', 'slug'], next);
},
- {
- route: 'popular',
- name: 'Popular'
+ function(categoryData, next) {
+ categoryData = categoryData.map(function(category) {
+ return {
+ route: 'category/' + category.slug,
+ name: 'Category: ' + category.name
+ };
+ });
+ next(null, categoryData);
}
- ]}, function(err, data) {
- res.render('admin/general/homepage', data);
+ ], function(err, categoryData) {
+ if (err || !categoryData) categoryData = [];
+
+ plugins.fireHook('filter:homepage.get', {routes: [
+ {
+ route: 'categories',
+ name: 'Categories'
+ },
+ {
+ route: 'recent',
+ name: 'Recent'
+ },
+ {
+ route: 'popular',
+ name: 'Popular'
+ }
+ ].concat(categoryData)}, function(err, data) {
+ data.routes.push({
+ route: '',
+ name: 'Custom'
+ });
+
+ res.render('admin/general/homepage', data);
+ });
});
};
diff --git a/src/controllers/index.js b/src/controllers/index.js
index 53ae658937..d4d321657b 100644
--- a/src/controllers/index.js
+++ b/src/controllers/index.js
@@ -33,20 +33,20 @@ var Controllers = {
Controllers.home = function(req, res, next) {
- var route = meta.config.homePageRoute || 'categories',
+ var route = meta.config.homePageRoute || meta.config.homePageCustom || 'categories',
hook = 'action:homepage.get:' + route;
if (plugins.hasListeners(hook)) {
plugins.fireHook(hook, {req: req, res: res, next: next});
} else {
- if (route === 'categories') {
+ if (route === 'categories' || route === '/') {
Controllers.categories.list(req, res, next);
} else if (route === 'recent') {
Controllers.recent.get(req, res, next);
} else if (route === 'popular') {
Controllers.popular.get(req, res, next);
} else {
- next();
+ res.redirect(route);
}
}
};
diff --git a/src/views/admin/general/homepage.tpl b/src/views/admin/general/homepage.tpl
index 812b31b077..5148d79da9 100644
--- a/src/views/admin/general/homepage.tpl
+++ b/src/views/admin/general/homepage.tpl
@@ -12,6 +12,11 @@
+
+