added carts in /admin

This commit is contained in:
Yaman 2015-01-11 20:41:35 -05:00
parent fb9d041e0f
commit e143ce15e2
8 changed files with 107 additions and 10 deletions

View File

@ -21,7 +21,7 @@
margin-bottom: 4%; margin-bottom: 4%;
} }
.yield:hover { .yield:hover, .yieldc:hover{
color: #E14C2B; color: #E14C2B;
} }

View File

@ -27,9 +27,21 @@
</div> </div>
<!-- Carts --> <!-- Carts -->
<div> <div>
<h6>Add a Cart</h6>
<form class="new-task">
<input type="text" name="acnumber" placeholder="Cart Number (ex. B)"/>
<input type="submit" value="Submit" class="addc" />
</form>
<h6> Edit Carts</h6>
{{#each carts}}
<div class="row">
{{>cart}}
<i class="icons yieldc fa fa-exclamation-triangle fa-lg"></i>
<i class="icons crossc fa fa-times fa-lg"></i>
</div>
{{/each}}
</div> </div>
{{/teacherTabs}} {{/teacherTabs}}
</div> </div>
</div> </div>
</template> </template>

View File

@ -1,6 +1,9 @@
Template.admin.helpers({ Template.admin.helpers({
chromebooks: function() { chromebooks: function() {
return Chromebooks.find(); return Chromebooks.find();
},
carts: function() {
return carts.find();
} }
}); });
@ -44,11 +47,55 @@ Template.admin.events({
// Prevent default form // Prevent default form
return false; return false;
}, },
"submit .addc, click .addc": function (event) {
event.preventDefault();
var cart_number = $("input[name='acnumber']")[0].value;
if (!((cart_number === "")))
carts.insert({
"status": 0,
"userid": null,
"last_checkout": null,
"number": cart_number
});
// Clear form
$("input[name='acnumber']")[0].value = "";
// Prevent default form
return false;
},
'click .cross' : function() { 'click .cross' : function() {
if (Roles.userIsInRole(Meteor.userId(), ['admin'])) { if (Roles.userIsInRole(Meteor.userId(), ['admin'])) {
Chromebooks.remove(this._id); Chromebooks.remove(this._id);
} }
}, },
'click .crossc' : function() {
if (Roles.userIsInRole(Meteor.userId(), ['admin'])) {
carts.remove(this._id);
}
},
'click .yieldc' : function() {
if (Roles.userIsInRole(Meteor.userId(), ['admin'])) {
if (this.status === 0) {
carts.update(this._id, {$set: {status: 2}});
}
else if (this.status === 1) {
carts.update(this._id, {$set: {status: 2}});
}
else {
carts.update(this._id, {$set: {status: 0}});
carts.update(this._id, {$set: {last_checkout: null}});
carts.update(this._id, {$set: {userid: null}});
carts.update(this._id, {$set: {user: null}});
}
}
else {
alert("Access Denied");
}
},
'click .yield' : function() { 'click .yield' : function() {
if (Roles.userIsInRole(Meteor.userId(), ['admin'])) { if (Roles.userIsInRole(Meteor.userId(), ['admin'])) {
if (this.status === 0) { if (this.status === 0) {

View File

@ -0,0 +1,14 @@
<template name="cart">
<div class="cart chromebook {{status_class}}">
<p class="pure-u-3-5">Cart #{{number}}</p>
{{#if status }}
<div class="timestamp pure-u-2-5">
<p class="user"> <b>{{user}}</b></p>
<p class="time">{{time_ago}}</p>
</div>
<!-- <div class="cross pure-u-2-5">
<i class="fa fa-times"></i>
</div> -->
{{/if}}
</div>
</template>

View File

@ -0,0 +1,20 @@
var statusmap = {
0: "available",
1: "checkedout",
2: "unavailable"
}
Meteor.subscribe('carts');
Template.chromebook.helpers({
status_class: function() {
return statusmap[this.status];
},
time_ago: function() {
if (this.last_checkout === null) {
return "";
} else {
return moment(this.last_checkout).fromNow();
}
}
});

View File

@ -47,7 +47,7 @@ body {
color: #25abd9; color: #25abd9;
} }
.cross:hover { .cross:hover, .crossc:hover{
color: #E14C2B; color: #E14C2B;
} }

View File

@ -5,11 +5,11 @@
{{#teacherTabs tabs=tabs}} {{#teacherTabs tabs=tabs}}
<!-- Single --> <!-- Single -->
<div> <div>
{{#each chromebooks}} {{#each chromebooks}}
<div class="row"> <div class="row">
{{> chromebook}} {{> chromebook}}
</div> </div>
{{/each}} {{/each}}
</div> </div>
<!-- Carts --> <!-- Carts -->
<div> <div>

View File

@ -11,6 +11,10 @@ Meteor.publish('chromebook', function() {
} }
}); });
Meteor.publish('carts', function() {
return carts.find();
});
var adminusers = [ var adminusers = [
"ybq987@gmail.com", "ybq987@gmail.com",
"mminer@bloomfield.org", "mminer@bloomfield.org",