Upravy v programu a rozpoctu
This commit is contained in:
+74
-5
@@ -86,6 +86,7 @@ var templateData = {
|
||||
budget: [
|
||||
{
|
||||
name: "Rozlucka se svobodou",
|
||||
limit: 20000,
|
||||
items: [
|
||||
{
|
||||
name: "Polozka 1",
|
||||
@@ -123,6 +124,21 @@ function renderTemplate(req, res) {
|
||||
var urlSegment = url.replace (/[^a-z0-9_]/, '');
|
||||
var viewsRoot = app.get ('views');
|
||||
|
||||
for (var budget in templateData.budget) {
|
||||
console.log(typeof templateData.budget[budget]);
|
||||
|
||||
if (typeof templateData.budget[budget] == 'undefined') {
|
||||
templateData.budget.splice (budget, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (var item in templateData.budget[budget].items) {
|
||||
if (typeof templateData.budget[budget].items[item] == 'undefined') {
|
||||
templateData.budget[budget].items.splice (item, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
templateData.queryString = req.query;
|
||||
templateData.page = urlSegment;
|
||||
|
||||
@@ -188,15 +204,18 @@ app.post ('/editor/album', function (req, res) {
|
||||
app.post ('/budget/groups', function (req, res) {
|
||||
|
||||
var groups = req.body.group;
|
||||
var limits = req.body.limit;
|
||||
|
||||
for (var i in groups) {
|
||||
if (typeof templateData.budget[i] == 'undefined') {
|
||||
templateData.budget[i] = {
|
||||
name: groups[i],
|
||||
limit: limits[i],
|
||||
items: []
|
||||
}
|
||||
} else {
|
||||
templateData.budget[i].name = groups[i];
|
||||
templateData.budget[i].limit = limits[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +230,7 @@ app.post ('/budget/groups', function (req, res) {
|
||||
});
|
||||
|
||||
app.post ('/budget/add_item', function (req, res) {
|
||||
|
||||
console.log (req.body);
|
||||
var items = req.body.name.length;
|
||||
|
||||
var newGroupsMap = {};
|
||||
@@ -225,7 +244,7 @@ app.post ('/budget/add_item', function (req, res) {
|
||||
var newGroupName = req.body.group_name[i];
|
||||
|
||||
if (typeof newGroupsMap[newGroupName] == 'undefined') {
|
||||
templateData.budget.push ({name: newGroupName, items: []});
|
||||
templateData.budget.push ({name: newGroupName, limit: 10000, items: []});
|
||||
|
||||
newGroupsMap[newGroupName] = templateData.budget.length;
|
||||
|
||||
@@ -253,19 +272,49 @@ app.post ('/budget/add_item', function (req, res) {
|
||||
|
||||
});
|
||||
|
||||
app.post ('/budget/add_item_in_group', function (req, res) {
|
||||
console.log (req.body);
|
||||
var items = req.body.name.length;
|
||||
|
||||
app.get('/budget/detail/:id', function (req, res) {
|
||||
var group = req.body.group;
|
||||
|
||||
templateData.budget[group].limit = req.body.limit;
|
||||
|
||||
templateData.budget[group].items = [];
|
||||
for (var i = 0; i < items; i++) {
|
||||
var itemName = req.body.name[i];
|
||||
var price = req.body.price[i];
|
||||
var bought = typeof req.body["bought_" + i] == 'undefined' ? false : true;
|
||||
|
||||
templateData.budget[group].items.push ({
|
||||
name: itemName,
|
||||
price: price,
|
||||
bought: bought
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
var redirectUrl = '/budget';
|
||||
|
||||
if (typeof req.body.redirectParams !== 'undefined') {
|
||||
redirectUrl += '?' + req.body.redirectParams;
|
||||
}
|
||||
|
||||
res.redirect (redirectUrl)
|
||||
|
||||
});
|
||||
|
||||
app.get ('/budget/detail/:id', function (req, res) {
|
||||
|
||||
var detail = templateData.budget[req.params.id];
|
||||
detail.id = req.params.id;
|
||||
|
||||
app.set ('layout', false);
|
||||
|
||||
app.set ('views', viewsRootBase);
|
||||
|
||||
|
||||
res.render ('partials/backend/budgetDetail.ejs', detail);
|
||||
|
||||
|
||||
});
|
||||
|
||||
app.post ('/budget/bought/:group/:item', function (req, res) {
|
||||
@@ -281,6 +330,26 @@ app.post ('/budget/bought/:group/:item', function (req, res) {
|
||||
|
||||
});
|
||||
|
||||
app.get ('/budget/group/:group/delete', function (req, res) {
|
||||
|
||||
var group = req.params.group;
|
||||
|
||||
delete templateData.budget[group];
|
||||
|
||||
res.end ();
|
||||
|
||||
});
|
||||
|
||||
app.get ('/budget/group/:group/:item/delete', function (req, res) {
|
||||
|
||||
var group = req.params.group;
|
||||
var item = req.params.item;
|
||||
|
||||
delete templateData.budget[group].items[item];
|
||||
res.end ();
|
||||
|
||||
});
|
||||
|
||||
app.post ('/editor/:page?', function (req, res) {
|
||||
savePost (req, res);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user