aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--controllers/system.js49
-rw-r--r--models/Project.js22
-rw-r--r--models/pPost.js2
-rw-r--r--routes.js2
-rw-r--r--views/projectPost.ejs26
5 files changed, 75 insertions, 26 deletions
diff --git a/controllers/system.js b/controllers/system.js
index 40e13e8..a61f7b6 100644
--- a/controllers/system.js
+++ b/controllers/system.js
@@ -5,8 +5,8 @@
var mongoose = require('mongoose')
, Project = mongoose.model('Project')
, Access = mongoose.model('Access')
- , User = mongoose.model('User');
-
+ , User = mongoose.model('User')
+ , pPost = mongoose.model('pPost');
/**
* Before the user log in
@@ -43,6 +43,12 @@ exports.faq = function(req, res) {
}
+exports.contact = function(req, res) {
+ res.render('contact', {
+ title: 'contact',
+ loggedin: false
+ });
+}
/**
@@ -57,11 +63,11 @@ exports.dashboard = function(req, res) {
/*
Access.find({ user: req.user._id }, function(err, accesses) {
- if (err) return res.render('500');
+ if (err) return res.status(500).render('error', { title: '500', text: 'En serverfeil oppstod', error: err.stack });
console.log('accesses ' + accesses);
accesses.forEach(function(access) {
Project.load(access.project, function(err, project) {
- if (err) return res.render('500');
+ if (err) return res.status(500).render('error', { title: '500', text: 'En serverfeil oppstod', error: err.stack });
projectList.push(project);
console.log(project.user.username);
});
@@ -69,7 +75,7 @@ exports.dashboard = function(req, res) {
});
*/
Access.loadUser(req.user._id, function(err, projects) {
- if (err) return res.render('500');
+ if (err) return res.status(500).render('error', { title: '500', text: 'En serverfeil oppstod', error: err.stack });
Project.populate(projects, { path: 'project.user', model: User }, function(err, projects) {
console.log('accesses: ' + projects);
@@ -82,11 +88,11 @@ exports.dashboard = function(req, res) {
});
- })
+ });
/*
Project.find(function(err, projects) {
- if (err) return res.render('500');
+ if (err) return res.status(500).render('error', { title: '500', text: 'En serverfeil oppstod', error: err.stack });
res.render('dashboard', {
title: 'Dashboad',
loggedin: true,
@@ -98,7 +104,12 @@ exports.dashboard = function(req, res) {
exports.project = function(req, res) {
- res.render('project', { title: 'Harepus', loggedin: true, req: req });
+ Project.loadShort(req.params.short, function(err, project) {
+ if (err) return res.status(500).render('error', { title: '500', text: 'En serverfeil oppstod', error: err.stack });
+
+ res.render('project', { title: 'Harepus', loggedin: true, req: req, project: project });
+
+ });
}
exports.projectParticipants = function(req, res) {
@@ -112,13 +123,31 @@ exports.postProjectParticipants = function(req, res) {
}
exports.projectPost = function(req, res) {
- res.render('projectPost', { title: 'Legg til utgift', loggedin: true, req: req });
+
+ /** ###################################
+ * Need to check if user has access to this project!!
+ */
+ console.log(req.loggedin);
+ Project.loadShort(req.params.short, function(err, project) {
+ if (err) return res.status(500).render('error', { title: '500', text: 'En serverfeil oppstod', error: err.stack });
+ res.render('projectPost', { title: 'Legg til utgift', loggedin: true, req: req, project: project });
+ });
+
}
exports.postProjectPost = function(req, res) {
-
+/*// var ppost = new pPost(req.body);
+ ppost.user = req.user._id;
+ ppost.project = ;
+/*/
+ var ppost = new pPost(req.body);
+ console.log('ppost.user = ' + req.user._id);
+ console.log('ppost.project = ' + ppost.project);
+ console.log('ppost.what = ' + ppost.what);
+
+//*//
}
exports.newProject = function(req, res) {
diff --git a/models/Project.js b/models/Project.js
index f29c7f8..ba0e8e7 100644
--- a/models/Project.js
+++ b/models/Project.js
@@ -41,12 +41,6 @@ ProjectSchema.pre('save', function(next) {
ProjectSchema.statics = {
- log: function() {
- console.log('wat. wat logged this');
- },
-
-
-
/**
* Find project by id
*
@@ -59,8 +53,22 @@ ProjectSchema.statics = {
this.findOne({ _id: id })
.populate('user')
.exec(callback);
- }
+ },
+
+
+ /**
+ * Find project my shortURL
+ *
+ * @param {shortURL} shortURL
+ * @param {Function} callback
+ * @api private
+ */
+ loadShort : function(shortURL, callback) {
+ this.findOne({ shortURL: shortURL })
+ .populate('user')
+ .exec(callback);
+ }
}
diff --git a/models/pPost.js b/models/pPost.js
index 5ec28b1..c02f863 100644
--- a/models/pPost.js
+++ b/models/pPost.js
@@ -11,7 +11,7 @@ var pPostSchema = new Schema({
for: { type: Schema.ObjectId, ref: 'User' },
project: { type: Schema.ObjectId, ref: 'Project' },
what: { type: String, default: '', trim: true },
- comment: {type: String, default: '', trim: true },
+ comment: { type: String, default: '', trim: true },
participants: [],
value: { type: Number, defailt: 0 },
file: { type: String, default: '', trim: true },
diff --git a/routes.js b/routes.js
index 50d4cba..12d2894 100644
--- a/routes.js
+++ b/routes.js
@@ -22,6 +22,8 @@ module.exports = function(app, passport, auth) {
app.get('/faq', system.faq);
+ app.get('/contact', system.contact);
+
app.get('/login', users.login);
app.get('/signup', users.signup);
diff --git a/views/projectPost.ejs b/views/projectPost.ejs
index 5e7af87..80ed6d8 100644
--- a/views/projectPost.ejs
+++ b/views/projectPost.ejs
@@ -11,6 +11,7 @@
<form class="form-horizontal" method="post">
+ <input type="hidden" name="project" value="<%= project._id %>">
<fieldset>
<h1><legend><%= title %></legend></h1>
@@ -35,10 +36,10 @@
</div>
</div>
<%
- var d = new Date();
- var n = d.getFullYear() + '-' + ('0' + (d.getMonth()+1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2);
- var t = d.toLocaleTimeString().slice(0, 5);
-
+ // we need to populate the date- and timefield with the current time and date
+ var d = new Date();
+ var n = d.getFullYear() + '-' + ('0' + (d.getMonth()+1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2);
+ var t = d.toLocaleTimeString().slice(0, 5);
%>
<!-- <%= d %> -->
<div class="control-group">
@@ -51,15 +52,17 @@
<div class="control-group">
<label for="cost" class="control-label">Hvor mye <strong class="text-error">*</strong></label>
<div class="controls">
- <input type="number" name="cost" id="cost" class="input-small" placeholder="0" required>
+ <input type="number" name="value" id="value" class="input-small" placeholder="0" required>
</div>
</div>
<div class="control-group">
<label for="split_between" class="control-label">Delt på</label>
<div class="controls">
- <select multiple="multiple">
- <option value="">Dennis</option>
- <option value="">Kurt</option>
+
+ <span class="selectAll">Select all</span>
+ <select name="participants[]" id="participants" multiple="multiple">
+ <option value="5180e11b0074a8b029000001" selected="selected">Dennis</option>
+ <option value="51814b792c94cc5346000001" selected="selected">Kurt</option>
</select>
</div>
</div>
@@ -97,5 +100,12 @@
<% include footer %>
+ <script>
+ $(".selectAll").click(function() {
+ $('#participants').children().attr('selected','selected');
+ //$(this).parent().find('option').attr('selected','selected');
+ });
+ </script>
+
</body>
</html>