Files
old-confighub/web/client/views/home/home.js
2015-05-28 13:44:14 +02:00

86 lines
2.1 KiB
JavaScript

// var Machines = new Mongo.Collection("machines");
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
// counter starts at 0
// Session.setDefault('counter', 0);
Template.home.helpers({
machines: function() {
return Machines.find({});
},
newMachineRequested: function() {
return Session.get('newMachineRequested');
}
});
Template.home.events({
"click .add-new-machine-btn": function() {
Session.set('newMachineRequested', true);
}
});
// Template.hello.helpers({
// counter: function() {
// return Session.get('counter');
// }
// });
// Template.hello.events({
// 'click button': function() {
// // increment the counter when button is clicked
// Session.set('counter', Session.get('counter') + 1);
// }
// });
Template.newMachine.helpers({
// because the Session variable will most probably
// be undefined the first time
// return true;
newMachineAdded: function() {
return Session.get("newMachineJustAdded");
}
});
Template.newMachine.events({
"click .close-new-machine-btn": function() {
Session.set('newMachineJustAdded', false);
Session.set('newMachineRequested', false);
},
"submit .new-machine": function(event) {
event.preventDefault();
return false;
},
"click .new-machine-save-btn": function(event, template) {
// This function is called when the new task form is submitted
// console.log('saving!!!!!!');
// event.preventDefault();
// return false;
//
var text = template.find('.machine-name').value; //vent.target.machineName.value;
var machineId = guid();
Machines.insert({
name: text,
status: 'init pending',
configurations: [],
machineId: machineId,
createdAt: new Date() // current time
});
// Clear form
template.find('.machine-name').value = "";
Session.set('newMachineJustAdded', machineId);
// Prevent default form submit
return false;
}
});