Merge pull request #3594 from yariplus/homepages

Add Custom and Category homepages.
v1.18.x
Barış Soner Uşaklı 9 years ago
commit bcb3b55ab0

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

@ -348,6 +348,28 @@ adminController.navigation.get = function(req, res, next) {
};
adminController.homepage.get = function(req, res, next) {
async.waterfall([
function(next) {
db.getSortedSetRange('cid:0:children', 0, -1, next);
},
function(cids, next) {
privileges.categories.filterCids('find', cids, 0, next);
},
function(cids, next) {
categories.getMultipleCategoryFields(cids, ['name', 'slug'], next);
},
function(categoryData, next) {
categoryData = categoryData.map(function(category) {
return {
route: 'category/' + category.slug,
name: 'Category: ' + category.name
};
});
next(null, categoryData);
}
], function(err, categoryData) {
if (err || !categoryData) categoryData = [];
plugins.fireHook('filter:homepage.get', {routes: [
{
route: 'categories',
@ -361,9 +383,15 @@ adminController.homepage.get = function(req, res, next) {
route: 'popular',
name: 'Popular'
}
]}, function(err, data) {
].concat(categoryData)}, function(err, data) {
data.routes.push({
route: '',
name: 'Custom'
});
res.render('admin/general/homepage', data);
});
});
};
adminController.settings.get = function(req, res, next) {

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

@ -12,6 +12,11 @@
<option value="{routes.route}">{routes.name}</option>
<!-- END routes -->
</select>
<br>
<div id="homePageCustom" style="display: none;">
<label>Custom Route</label>
<input type="text" class="form-control" data-field="homePageCustom"/>
</div>
</div>
</form>
</div>

Loading…
Cancel
Save