var config = require('./config.js').config; var uuid = require('node-uuid'); // Post management routing module.exports = function(app) { // GET /admin/post/list app.get('/admin/post/list/:start?', function(req, res, next) { var count = 25; if (req.params.start) { var start = req.params.start; } else { var start = 0; } Post.getPosts(count, start, function(err, posts){ res.render('admin-post-list', { successNotice: req.flash('successNotice'), failureNotice: req.flash('failureNotice'), posts: posts, user: req.user }); }); } ); // GET /admin/post/view app.get('/admin/post/view/:uuid?', function (req, res, next) { if (req.params.uuid) { Post.getByUUID(req.params.uuid, function(err, post) { res.render('admin-post-view', { successNotice: req.flash('successNotice'), failureNotice: req.flash('failureNotice'), post: post, user: req.user }); }); } else { res.redirect('/admin/post/list'); } } ); // GET /admin/post/new app.get('/admin/post/new', function(req, res, next) { Category.getCategories(null, null, function (err, categories) { res.render('admin-post-new', { categories: categories, user: req.user }); }); } ); // POST /admin/post/new app.post('/admin/post/new', function(req, res, next) { var post = new Post({'uuid': uuid.v1()}); post.set("title", req.body.title); if (req.body.slug != "") { post.set("slug", req.body.slug); } else { post.set("slug", post.makeSlug()); } if (req.body.postDate != "") { post.set("postDate", new Date(req.body.postDate)); post.set("updatedDate", new Date(req.body.postDate)); } post.tagPost(req.body.tags); post.set("markdown", req.body.markdown); if (req.body.published) { post.set("published", true); } else { post.set("published", false); } Category.getByName(req.body.category, function (err, category) { post.set("category", category.get("uuid")); post.save(null, function (err) { if (!err) { req.flash('successNotice', 'Post created.'); res.redirect('/admin/post/edit/'+post.get("uuid")); } else { req.flash('failureNotice', 'Post creation failed'); res.redirect('/admin/post/new/'); } }); }); } ); // GET /admin/post/edit app.get('/admin/post/edit/:uuid', function(req, res, next) { Post.getByUUID(req.params.uuid, function(err, post) { Category.getByUUID(post.get("category"), function(err, category) { Category.getCategories(null, null, function(err, categories) { var tags = "" for (i=0; i