Skip to content

Commit

Permalink
Merge pull request #54 from CSE112-GoldTeam/checkin-process
Browse files Browse the repository at this point in the history
Checkin process
  • Loading branch information
j-delaney committed Feb 25, 2015
2 parents 8cac278 + ec7df94 commit c289d0f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 99 deletions.
75 changes: 63 additions & 12 deletions routes/checkin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,45 @@ router.get('/office/:id/checkin', function (req, res, next) {

//Sig Page
router.get('/office/:id/sign', function(req, res, next) {
res.render('checkin/sign', {title: 'Express'});
var db = req.db;
var businesses = db.get('businesses');

businesses.find({_id: ObjectID(req.params.id)}, function (err, results) {
//TODO: Verify that there are results and no errors
var business = results[0];
res.render('checkin/sign', {
title: 'Express',
disclosure: business.disclosure
});
});
});

router.post('/office/:id/sign', function (req, res, next) {
var sig = req.body.sig.trim();
if (sig === '') {
var db = req.db;
var businesses = db.get('businesses');

businesses.find({_id: ObjectID(req.params.id)}, function (err, results) {
//TODO: Verify that there are results and no errors
var business = results[0];
res.render('checkin/sign', {
title: 'Express',
disclosure: business.disclosure,
error: 'You must provide a signature'
});
});
} else {
//Update the state of the appointment
var appointmentId = req.session.appointmentId;
req.db.get('appointments').update({_id: ObjectID(appointmentId)}, {
$set: {
state: 'checkedIn'
}
}, function (err) {
res.redirect('done');
});
}
});

//Custom Form
Expand Down Expand Up @@ -153,8 +191,17 @@ router.post('/office/:id/customform', function (req, res, next) {

formResponses.insert(formResponse, function (err, result) {
//TODO: Error checking
res.redirect('done');
})

//Update the state of the appointment
var appointmentId = req.session.appointmentId;
db.get('appointments').update({_id: ObjectID(appointmentId)}, {
$set: {
state: 'formDone'
}
}, function (err) {
res.redirect('sign');
});
});
}
});
});
Expand Down Expand Up @@ -189,19 +236,19 @@ router.post('/office/:id/nocode', function (req, res, next) {
var inputDOB = req.body.inputDOB;
var dobSubStr = req.body.inputDOB;
var numSlash = inputDOB.match(/\//g).length;

var busName;
var aptID;

if (numSlash != 2) {
res.render('checkin/nocode', {
error: dobFormatErr,
error: dobFormatErr,
inputFirst: inputFirst,
inputLast: inputLast,
inputDOB: inputDOB
});
}

var firstSep = dobSubStr.indexOf("/");
var inputMonth = dobSubStr.substring(0, firstSep);

Expand All @@ -228,7 +275,7 @@ router.post('/office/:id/nocode', function (req, res, next) {
}

var inputYear = dobSubStr.substring(secondSep+1);

if (inputYear.length != 4)
{
res.render('checkin/nocode', {
Expand Down Expand Up @@ -272,8 +319,8 @@ router.post('/office/:id/nocode', function (req, res, next) {
}

inputDOB = inputMonth + "/" + inputDay + "/" + inputYear;
appointments.find({business: req.params.id, fname: inputFirst, lname: inputLast, dob: inputDOB}, function(err, result) {

appointments.find({business: ObjectID(req.params.id), fname: inputFirst, lname: inputLast, dob: inputDOB}, function(err, result) {
if (result.length == 0) {
res.render('checkin/nocode', {
error: 'No appointment found',
Expand All @@ -285,11 +332,15 @@ router.post('/office/:id/nocode', function (req, res, next) {
else {
var appt = result[0];
var apptID = appt._id;
req.session.apointmentId = apptID;
res.redirect('apptinfo');
req.session.appointmentId = apptID;
req.session.save(function (err) {
if (err) {
console.error("Session save error:", err);
}
res.redirect('apptinfo');
});
}
});

});

module.exports = router;
2 changes: 1 addition & 1 deletion views/checkin/apptinfo.hjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<a class="btn btn-lg btn-danger btn-block" type="submit" href="entercode">Not you?</a>
</div>
<div class="col-md-2">
<a class="btn btn-lg btn-success btn-block" type="submit" href="done">Next</a>
<a class="btn btn-lg btn-success btn-block" type="submit" href="customform">Next</a>
</div>
</body>
</html>
Expand Down
3 changes: 1 addition & 2 deletions views/checkin/checkin.hjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
<div class="container">
<h1 class ="header">Welcome to Company!</h1>
<img class="checkinphoto" src="http://placehold.it/500x200" alt="...">
<a type="button" class="btn btn-success custom-button checkinbutton" href="entercode"
<a type="button" class="btn btn-success custom-button checkinbutton" href="nocode"
style="display:block;margin-left:auto;margin-right:auto">Check In
</a>
</div>
<div style="text-align:center;margin-top: 1em"><a href="nocode">I don't have an appointment.</a></div>
</body>
</html>

70 changes: 0 additions & 70 deletions views/checkin/entercode.hjs

This file was deleted.

59 changes: 45 additions & 14 deletions views/checkin/sign.hjs
Original file line number Diff line number Diff line change
@@ -1,26 +1,57 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<script>
$(document).ready(function() {
$('#sig').on('input', function(){
var sig = $('#sig').val();
sig = '/api/signature/' + sig;
$('#sigImg').attr('src', sig);
})
});
</script>
<title>{{ title }}</title>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<link rel='stylesheet' href='/stylesheets/style.css'/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>

<script>
$(document).ready(function () {
$('#sig').on('input', function () {
var sig = $('#sig').val();
sig = '/api/signature/' + sig;
$('#sigImg').attr('src', sig);
})
});
</script>

</head>

<body>

<!-- this nav bar is consistent with PK's navbar -->
<header role="banner" class="navbar navbar-fixed-top navbar-custom">
<div class="container">
<div class="navbar-inverse side-collapse in">
<ul class="nav navbar-nav">
<li><a class="navbar-brand" href="#">Company Logo</a></li>
</ul>
</div>
</div>
</header>

{{#error}}
<div class="alert alert-danger" role="alert">
{{ error }}
</div>
{{/error}}

<h3>Disclosure Agreement</h3>

{{{ disclosure }}}

<h3>SIGN HERE</h3>

<img id="sigImg" src="/api/signature/" style="width:auto" />
<br />
<input type="text" id="sig" />
<form action="sign" method="post">
<img id="sigImg" src="/api/signature/" style="width:auto"/>
<br/>
<input type="text" id="sig" name="sig"/>
<button class="btn btn-default" type="submit">Sign</button>
</form>


</body>
</html>

0 comments on commit c289d0f

Please sign in to comment.