Upravy v editoru webu
This commit is contained in:
+103
-2
@@ -1,4 +1,3 @@
|
||||
|
||||
var express = require ('express');
|
||||
var app = express ();
|
||||
|
||||
@@ -10,6 +9,78 @@ app.set ('view engine', 'ejs');
|
||||
app.use ('/dist', express.static ('dist'));
|
||||
app.use (expressLayouts);
|
||||
|
||||
var bodyParser = require ('body-parser');
|
||||
app.use (bodyParser.json ());
|
||||
app.use (bodyParser.urlencoded ({extended: true}));
|
||||
|
||||
var templateData = {
|
||||
invitations: [
|
||||
{
|
||||
name: "Frantisek Novak",
|
||||
person_count: 2,
|
||||
will_come: true,
|
||||
date: new Date ('2018-11-20')
|
||||
},
|
||||
{
|
||||
name: "Frantisek Dvorak",
|
||||
person_count: 4,
|
||||
will_come: false,
|
||||
date: new Date ('2018-11-19')
|
||||
},
|
||||
{
|
||||
name: "Frantisek Dvorak",
|
||||
person_count: 4,
|
||||
will_come: null
|
||||
},
|
||||
{
|
||||
name: "Frantisek Dvorak",
|
||||
person_count: 4,
|
||||
will_come: null
|
||||
},
|
||||
],
|
||||
tasks: [
|
||||
{name: "Ukol 1", done: false},
|
||||
{name: "Ukol 2", done: true},
|
||||
{name: "Ukol 3", done: true},
|
||||
{name: "Ukol 4", done: false},
|
||||
],
|
||||
aboutUs: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
|
||||
notes: "",
|
||||
wedding: {
|
||||
when: '1. 9. 2019',
|
||||
where: 'Zámek Litomyšl',
|
||||
at: '11:00'
|
||||
},
|
||||
ourStory: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
|
||||
program: [
|
||||
{
|
||||
icon: "automobile",
|
||||
time: "10:00",
|
||||
title: "Příjezd nevěsty"
|
||||
},
|
||||
{
|
||||
icon: "heart",
|
||||
time: "11:00",
|
||||
title: "Obřad"
|
||||
},
|
||||
{
|
||||
icon: "cutlery",
|
||||
time: "12:00",
|
||||
title: "Hostina"
|
||||
},
|
||||
{
|
||||
icon: "glass",
|
||||
time: "13:00",
|
||||
title: "Přípitek"
|
||||
},
|
||||
{
|
||||
icon: "birthday-cake",
|
||||
time: "12:00",
|
||||
title: "Krájení dortu"
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* Render template - check if exists
|
||||
*
|
||||
@@ -21,8 +92,10 @@ function renderTemplate(req, res) {
|
||||
var urlSegment = url.replace (/[^a-z0-9_]/, '');
|
||||
var viewsRoot = app.get ('views');
|
||||
|
||||
templateData.queryString = req.query;
|
||||
|
||||
if (fs.existsSync (viewsRoot + '/' + urlSegment + ".ejs")) {
|
||||
res.render (urlSegment);
|
||||
res.render (urlSegment, templateData);
|
||||
} else {
|
||||
res.status (404);
|
||||
res.send ('View ' + viewsRoot + '/' + urlSegment + '.ejs not found');
|
||||
@@ -49,4 +122,32 @@ app.get ('/:page?', function (req, res) {
|
||||
renderTemplate (req, res);
|
||||
});
|
||||
|
||||
function savePost(req, res) {
|
||||
console.log (req.body);
|
||||
|
||||
for (var i in req.body) {
|
||||
templateData[i] = req.body[i];
|
||||
}
|
||||
}
|
||||
|
||||
app.post ('/:page?', function (req, res) {
|
||||
savePost (req, res);
|
||||
|
||||
var redirectUrl = '/' + (typeof req.params.page === 'undefined' ? 'index' : req.params.page);
|
||||
|
||||
res.redirect (redirectUrl)
|
||||
});
|
||||
|
||||
app.post ('/editor/:page?', function (req, res) {
|
||||
savePost (req, res);
|
||||
|
||||
var redirectUrl = '/editor/' + (typeof req.params.page === 'undefined' ? 'index' : req.params.page);
|
||||
|
||||
if (typeof req.body.redirectParams !== 'undefined') {
|
||||
redirectUrl += '?'+req.body.redirectParams;
|
||||
}
|
||||
|
||||
res.redirect (redirectUrl)
|
||||
});
|
||||
|
||||
app.listen (8080);
|
||||
Reference in New Issue
Block a user