Skip to content

Commit

Permalink
update team
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekkumarweb committed Jan 19, 2017
1 parent 5e16d67 commit ce43c27
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 28 deletions.
34 changes: 19 additions & 15 deletions models/accommodations.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,27 @@ Accommodation.add({
});

Accommodation.schema.pre('save', function(next){
if (!this.mailStatus && this.confirmed) {
User.model.findById(this.user).then((user)=>{
this.mailStatus = true;
require('../routes/mail.js').sendAAMail(user.email, user.name.first+' '+user.name.last);
User.model.findById(this.user).then((user)=>{
this.email = user.email;
this.phone = user.phone;
if (!this.mailStatus && this.confirmed) {
User.model.findById(this.user).then((user)=>{
this.mailStatus = true;
require('../routes/mail.js').sendAAMail(user.email, user.name.first+' '+user.name.last);
next();
}, (err)=>{
console.log(err);
next();
});
}
else if (!this.confirmed) {
this.mailStatus = false;
next();
}, (err)=>{
console.log(err);
}
else {
next();
});
}
else if (!this.confirmed) {
this.mailStatus = false;
next();
}
else {
next();
}
}
})
});

Accommodation.defaultColumns = 'id|1%, user|15%, email|20%%, phone|15%, noOfMale|5%, noOfFemale|5%, on19|5%, on20|5%, on21|5%, on22|5%, confirmed, notes';
Expand Down
17 changes: 16 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,22 @@ exports = module.exports = function (app) {
if (!req.user || !req.user.canAccessKeystone) {
return res.notfound();
}
res.render('adminteam');
Event.model.find({}).then(evts=>{
res.render('adminteam', {events: evts});
}, err=>res.notfound())
})

app.post('/admin/team', (req, res)=>{
if (!req.user || !req.user.canAccessKeystone) {
return res.json({status: false});
}
new Team.model({
name: req.body.name,
event: req.body.event,
members: req.body.members
}).save().then(team=>{
res.json({status: true, team: team})
}, err=>{res.json({status: false})});
})

app.get('/admin/:event', function(req, res){
Expand Down
160 changes: 148 additions & 12 deletions templates/views/adminteam.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta charset="UTF-8">
<title>Dashboard</title>


<link rel='stylesheet prefetch' href='https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css'>
<link rel='stylesheet prefetch' href='https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css'>

Expand All @@ -22,11 +21,47 @@

<div class="container">
<div class="row">
<h2>Team</h2>
<textarea id="team-in" rows="5", cols="50"></textarea><br>
<button id="createteam">Create Team</button>
<p id="result"></p>

<div class="col-md-3">
<div class="input-group">
<input class="form-control" id="qsearch" placeholder="Search for" required>
<span class="input-group-btn">
<button id="search" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
</span>
</div>
<div class="input-group">
<input class="form-control" id="name" placeholder="Team name" required>
</div>
<div class="form-group">
<label for="selev">Event:</label>
<select class="form-control" id="selev">
{{#each events}}
<option value="{{this._id}}">{{this.name}}</option>
{{/each}}
</select>
</div>
<button id="createteam">Create team</button>
<button id="clear">Clear</button>
<p class="result"></p>
</div>
<div class="col-md-9"></div>
<div class="col-md-12">
<table class="table table-list-search">
<thead>
<tr>
<th></th>
<th>IITH ID</th>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>College</th>
<th style="display: none">Select</th>
</tr>
</thead>
<tbody>

</tbody>
</table>
</div>
</div>
</div>

Expand All @@ -36,14 +71,115 @@ <h2>Team</h2>
<script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore.js'></script>

<script>
$(document).ready(function(){
$("#createteam").click(function(){
var teams = $("#team-in").val();
teams = teams.replace(/\s/g, '')
teams = teams.split(',');
console.log(teams);

function checkin(i) {
var $this = $("button[data-index='"+i+"']");
var data = {
check: true
}
$this.html("saving")
$.post("/checkin/"+i, data, function(data, sts){
if (!data || !data.status) {
$this.html("Error, click again");
}
else {
$this.parent().html("Checked in");
}
});
}

function removetd(el) {
$(el).parent().parent().remove();
}
$(document).ready(function() {
$("#qsearch").on("keypress", function(e){
if (e.charCode == 13) {
$("#search").click();
}
})
$("#clear").click(function(){
$(".result").html("");
$("tbody").html("");
$("#name").val("");
})
function pad(num, size) {
var s = num+"";
while (s.length < size) s = "0" + s;
return s;
}
$("#createteam").click(function(){
var data = {
name: $("#name").val(),
event: $("#selev").val(),
members: $(".selmem:checked").map(function(){return $(this).attr('data-id')}).get()
};
$.post('/admin/team', data, function(dt, st){
console.log(dt);
if (dt.status) {
$(".result").html("Team created. Team ID : "+dt.team.teamID)
}
else {
$(".result").html("Error creating team");
}
})
})
$("#search").click(function(){
var q = $("#qsearch").val();
if (q.toUpperCase().substring(0, 6) == "IITH17") {
q = q.toUpperCase();
$.post('/checkin/user', {q: q}, function(data, sts){
$("tbody").append(`
<tr>
<td><span onclick="removetd(this)">&times</span></th>
<td>${q}</td>
<td>${data.name.first} ${data.name.last}</td>
<td>${data.email}</td>
<td>${data.phone}</td>
<td>${data.college}</td>
<td style="display: none"><input type="checkbox" class="selmem" data-id="${data._id}" checked disabled></td>
</tr>
`);
});
}
else {$(".msg").html("Enter correct iith id")}
// else {
// $.get('/keystone/api/users?search='+encodeURIComponent(q)+'&fields=name%2Cuserid%2Cemail%2Ccollege%2Cphone%2CcheckedIn&limit=100&sort=name&expandRelationshipFields=false',
// function(dat, sts){
// $("tbody").html("");
// for (x in dat.results) {
// var data = dat.results[x];
// $("tbody").append(`
// <tr>
// <td>${"IITH17"+pad(data.fields.userid, 4)}</td>
// <td>${data.name}</td>
// <td>${data.fields.email}</td>
// <td>${data.fields.phone}</td>
// <td>${data.fields.college}</td>
// <td>${data.fields.checkedIn ? "Checked in " : '<button class="save" onclick="checkin(\''+data.id+'\')" data-index="'+data.id+'">Check in</button>'}</td>
// </tr>
// `);
// }
// })
// }
});
// $(".save").click(function(){
// console.log('save');
// var $this = $(this);
// var i = $this.attr("data-index");
// var data = {
// check: true
// }
// $this.html("saving")
// $.post("/checkin/"+i, data, function(data, sts){
// if (!data || !data.status) {
// $this.html("Error, click again");
// }
// else {
// $this.parent().html("Checked in");
// }
// });
// });
});
</script>

</body>
Expand Down

0 comments on commit ce43c27

Please sign in to comment.