bunch of functionlity

This commit is contained in:
Edin Dazdarevic
2015-05-28 13:44:14 +02:00
parent 02a556408c
commit e35f78a45b
25 changed files with 583 additions and 64 deletions

View File

@@ -0,0 +1,21 @@
<template name='home'>
<div class='container'>
<div class='row'>
<h1>confighub.io</h1>
<div class='col-lg-12'>
<h2>
Your machines
</h2>
</div>
</div>
{{> machineList machines=machines}}
{{#unless newMachineRequested}}
<div class="row">
<div class='col-lg-12'>
<button type='button' class='add-new-machine-btn'>Add new machine</button>
</div>
</div>
{{/unless}} {{#if newMachineRequested}} {{> newMachine }} {{/if}}
</div>
</template>

View File

@@ -0,0 +1,85 @@
// 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;
}
});