From e143ce15e24f836e446c0dc457ff547fac8f313a Mon Sep 17 00:00:00 2001 From: Yaman Date: Sun, 11 Jan 2015 20:41:35 -0500 Subject: [PATCH] added carts in /admin --- chromebook-checkout-meteor/client/admin.css | 2 +- chromebook-checkout-meteor/client/admin.html | 18 +++++-- chromebook-checkout-meteor/client/admin.js | 49 ++++++++++++++++++- chromebook-checkout-meteor/client/cart.html | 14 ++++++ chromebook-checkout-meteor/client/cart.js | 20 ++++++++ .../client/chromebook.css | 2 +- .../client/teacher.html | 8 +-- chromebook-checkout-meteor/server/users.js | 4 ++ 8 files changed, 107 insertions(+), 10 deletions(-) create mode 100644 chromebook-checkout-meteor/client/cart.html create mode 100644 chromebook-checkout-meteor/client/cart.js diff --git a/chromebook-checkout-meteor/client/admin.css b/chromebook-checkout-meteor/client/admin.css index 4c870a3..5aa96f1 100644 --- a/chromebook-checkout-meteor/client/admin.css +++ b/chromebook-checkout-meteor/client/admin.css @@ -21,7 +21,7 @@ margin-bottom: 4%; } -.yield:hover { +.yield:hover, .yieldc:hover{ color: #E14C2B; } diff --git a/chromebook-checkout-meteor/client/admin.html b/chromebook-checkout-meteor/client/admin.html index 332c31e..3f0ab72 100644 --- a/chromebook-checkout-meteor/client/admin.html +++ b/chromebook-checkout-meteor/client/admin.html @@ -27,9 +27,21 @@
- +
Add a Cart
+
+ + +
+
Edit Carts
+ {{#each carts}} +
+ {{>cart}} + + +
+ {{/each}}
- {{/teacherTabs}} - + {{/teacherTabs}} + \ No newline at end of file diff --git a/chromebook-checkout-meteor/client/admin.js b/chromebook-checkout-meteor/client/admin.js index 7a6ba32..e21f100 100644 --- a/chromebook-checkout-meteor/client/admin.js +++ b/chromebook-checkout-meteor/client/admin.js @@ -1,6 +1,9 @@ Template.admin.helpers({ chromebooks: function() { return Chromebooks.find(); + }, + carts: function() { + return carts.find(); } }); @@ -36,7 +39,7 @@ Template.admin.events({ "serial": chromebook_serial, "number": chromebook_number }); - + // Clear form $("input[name='anumber']")[0].value = ""; $("input[name='aserial']")[0].value = ""; @@ -44,11 +47,55 @@ Template.admin.events({ // Prevent default form 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() { if (Roles.userIsInRole(Meteor.userId(), ['admin'])) { 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() { if (Roles.userIsInRole(Meteor.userId(), ['admin'])) { if (this.status === 0) { diff --git a/chromebook-checkout-meteor/client/cart.html b/chromebook-checkout-meteor/client/cart.html new file mode 100644 index 0000000..c4f4239 --- /dev/null +++ b/chromebook-checkout-meteor/client/cart.html @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/chromebook-checkout-meteor/client/cart.js b/chromebook-checkout-meteor/client/cart.js new file mode 100644 index 0000000..cfd0578 --- /dev/null +++ b/chromebook-checkout-meteor/client/cart.js @@ -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(); + } + } +}); \ No newline at end of file diff --git a/chromebook-checkout-meteor/client/chromebook.css b/chromebook-checkout-meteor/client/chromebook.css index 182e7b8..9dc07d4 100644 --- a/chromebook-checkout-meteor/client/chromebook.css +++ b/chromebook-checkout-meteor/client/chromebook.css @@ -47,7 +47,7 @@ body { color: #25abd9; } -.cross:hover { +.cross:hover, .crossc:hover{ color: #E14C2B; } diff --git a/chromebook-checkout-meteor/client/teacher.html b/chromebook-checkout-meteor/client/teacher.html index 22b5571..266c886 100644 --- a/chromebook-checkout-meteor/client/teacher.html +++ b/chromebook-checkout-meteor/client/teacher.html @@ -5,11 +5,11 @@ {{#teacherTabs tabs=tabs}}
- {{#each chromebooks}} -
+ {{#each chromebooks}} +
{{> chromebook}} -
- {{/each}} +
+ {{/each}}
diff --git a/chromebook-checkout-meteor/server/users.js b/chromebook-checkout-meteor/server/users.js index 919e56e..e8001cb 100644 --- a/chromebook-checkout-meteor/server/users.js +++ b/chromebook-checkout-meteor/server/users.js @@ -11,6 +11,10 @@ Meteor.publish('chromebook', function() { } }); +Meteor.publish('carts', function() { + return carts.find(); +}); + var adminusers = [ "ybq987@gmail.com", "mminer@bloomfield.org",