v1.18.x
Barış Soner Uşaklı 10 years ago
parent fe1f4f84ec
commit bd553eb05d

@ -2,35 +2,34 @@
/* globals define, socket, app, templates, translator, ajaxify*/ /* globals define, socket, app, templates, translator, ajaxify*/
define('forum/home', function() { define('forum/categories', function() {
var home = {}; var categories = {};
$(window).on('action:ajaxify.start', function(ev, data) { $(window).on('action:ajaxify.start', function(ev, data) {
if (data.tpl_url !== 'home') { if (data.tpl_url !== 'categories') {
socket.removeListener('event:new_post', home.onNewPost); socket.removeListener('event:new_post', categories.onNewPost);
} }
}); });
categories.init = function() {
app.enterRoom('categories');
home.init = function() { socket.removeListener('event:new_post', categories.onNewPost);
app.enterRoom('home'); socket.on('event:new_post', categories.onNewPost);
socket.removeListener('event:new_post', home.onNewPost); $('.category-header').tooltip({
socket.on('event:new_post', home.onNewPost);
$('.home .category-header').tooltip({
placement: 'bottom' placement: 'bottom'
}); });
}; };
home.onNewPost = function(data) { categories.onNewPost = function(data) {
if (data && data.posts && data.posts.length && data.posts[0].topic) { if (data && data.posts && data.posts.length && data.posts[0].topic) {
renderNewPost(data.posts[0].topic.cid, data.posts[0]); renderNewPost(data.posts[0].topic.cid, data.posts[0]);
} }
}; };
function renderNewPost(cid, post) { function renderNewPost(cid, post) {
var category = $('.home .category-item[data-cid="' + cid + '"]'); var category = $('.category-item[data-cid="' + cid + '"]');
if (!category.length) { if (!category.length) {
return; return;
} }
@ -64,7 +63,7 @@ define('forum/home', function() {
} }
function parseAndTranslate(posts, callback) { function parseAndTranslate(posts, callback) {
templates.parse('home', 'posts', {categories: {posts: posts}}, function(html) { templates.parse('categories', 'posts', {categories: {posts: posts}}, function(html) {
translator.translate(html, function(translatedHTML) { translator.translate(html, function(translatedHTML) {
translatedHTML = $(translatedHTML); translatedHTML = $(translatedHTML);
translatedHTML.find('img').addClass('img-responsive'); translatedHTML.find('img').addClass('img-responsive');
@ -74,5 +73,5 @@ define('forum/home', function() {
}); });
} }
return home; return categories;
}); });

@ -154,8 +154,8 @@ categoriesController.list = function(req, res, next) {
if (err) { if (err) {
return next(err); return next(err);
} }
// TODO: template should be called categories.tpl
res.render('home', data); res.render('categories', data);
}); });
}; };

@ -30,13 +30,15 @@ var Controllers = {
Controllers.home = function(req, res, next) { Controllers.home = function(req, res, next) {
var route = meta.config.homePageRoute || 'home'; var route = meta.config.homePageRoute || 'categories';
if (route === 'home') { if (route === 'categories') {
return Controllers.categories.list(req, res, next); return Controllers.categories.list(req, res, next);
} else if (route === 'recent') { } else if (route === 'recent') {
Controllers.categories.recent(req, res, next); Controllers.categories.recent(req, res, next);
} else if (route === 'popular') { } else if (route === 'popular') {
Controllers.categories.popular(req, res, next); Controllers.categories.popular(req, res, next);
} else {
next();
} }
}; };

@ -24,7 +24,8 @@ templatesController.getTemplatesListing = function(req, res, next) {
readConfigFile(next); readConfigFile(next);
}, },
function(config, next) { function(config, next) {
config.custom_mapping['^/?$'] = meta.config.homePageRoute || 'home'; console.log(meta.config.homePageRoute);
config.custom_mapping['^/?$'] = meta.config.homePageRoute || 'categories';
plugins.fireHook('filter:templates.get_config', config, next); plugins.fireHook('filter:templates.get_config', config, next);
} }

@ -34,7 +34,7 @@
<form> <form>
<label>Home Page Route</label> <label>Home Page Route</label>
<select class="form-control" data-field="homePageRoute"> <select class="form-control" data-field="homePageRoute">
<option value="home">Categories</option> <option value="categories">Categories</option>
<option value="recent">Recent</option> <option value="recent">Recent</option>
<option value="popular">Popular</option> <option value="popular">Popular</option>
</select> </select>

@ -1,6 +1,6 @@
{ {
"custom_mapping": { "custom_mapping": {
"^\/?$": "home", "^\/?$": "categories",
"^admin?$": "admin/general/dashboard", "^admin?$": "admin/general/dashboard",
"^users/sort-posts": "users", "^users/sort-posts": "users",
"^users/latest": "users", "^users/latest": "users",

Loading…
Cancel
Save