Skip to content

Instantly share code, notes, and snippets.

@kingluddite
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kingluddite/11859d3e62c10ce336e6 to your computer and use it in GitHub Desktop.
Save kingluddite/11859d3e62c10ce336e6 to your computer and use it in GitHub Desktop.
/* /client/main.js */
Session.setDefault('showProjectDialog', false);
<template name="ProjectForm">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>
<label for="name">Name:</label>
<input type="text" name="name" class="input form-control name" value="{{project.name}}">
</p>
<label for="client">Client:</label>
<input type="text" name="client" class="input form-control client" value="{{project.client}}">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default cancel" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary save">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</template>
<template name="Projects">
{{#if showProjectDialog}}
{{> ProjectForm}}
{{/if}}
<div class="page-header">
<h1>Projects<small> list</small></h1>
</div>
<p>
<button type="button" class="btn btn-success addProject">Add Project</button>
</p>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Name</th>
<th>Client</th>
<th>Due Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{{#each projectList}}
{{> ProjectRow}}
{{/each}}
</tbody>
</table>
</template>
Template.Projects.projectList = function() {
return Projects.find();
};
Template.Projects.showProjectDialog = function() {
return Session.get('showProjectDialog');
};
Template.Projects.events({
'click .addProject':function(evt, tmpl) {
return Session.set('showProjectDialog', true)
},
'click .cancel':function(evt, tmpl) {
return Session.set('showProjectDialog', false);
},
'click .close':function(evt, tmpl) {
return Session.set('showProjectDialog', false);
}
});
@kingluddite
Copy link
Author

we have our projects.html that shows the dialog form if the setProjectDialog is true
Why is it camelCase? I camelCase session variables so I can easily see them

we initially set the setProjectDialog to false so it hides when our app loads

in projects.js we build the events that show or hide it based on the setProjectDialog true or false
if they click the add project button (we just add this button) the class name on that button .addProject gives us the ability to set the setProjectDialog session to true
when we click the cancel or close (both targeted by their class names (.close and .cancel))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment