36 lines
956 B
JavaScript
Raw Normal View History

2014-12-23 21:09:30 -05:00
var statusmap = {
0: "available",
1: "checkedout",
2: "unavailable"
}
2014-12-25 17:42:54 -05:00
Meteor.subscribe('chromebook');
2014-12-23 21:09:30 -05:00
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();
}
2014-12-25 17:42:54 -05:00
},
username: function() {
return Meteor.users.findOne({_id: this.userid}).profile.name;
2014-12-23 21:09:30 -05:00
}
});
Template.chromebook.events({
'click .available': function() {
Chromebooks.update(this._id, {$set: {status: 1}});
Chromebooks.update(this._id, {$set: {last_checkout: new Date()}});
2014-12-25 17:42:54 -05:00
Chromebooks.update(this._id, {$set: {userid: Meteor.userId()}});
2014-12-23 21:09:30 -05:00
},
'click .checkedout': function() {
Chromebooks.update(this._id, {$set: {status: 0}});
Chromebooks.update(this._id, {$set: {last_checkout: null}});
2014-12-25 17:42:54 -05:00
Chromebooks.update(this._id, {$set: {userid: null}});
2014-12-23 21:09:30 -05:00
}
});