Skip to content

Instantly share code, notes, and snippets.

@jmkelly
Created February 15, 2015 23:00
Show Gist options
  • Save jmkelly/995cfc8429c8e62a8233 to your computer and use it in GitHub Desktop.
Save jmkelly/995cfc8429c8e62a8233 to your computer and use it in GitHub Desktop.
js and templating
//small piece of functionality, in this case show a leave form search and it's data
Kernel.module.define('LeaveSearchShow', {
renderTo: "#leave-search-show",
init: function () {
var self = this;
self.hub.listen('leave-search-fetch-complete', function (data) {
self.render(data);
});
},
clear: function () {
$(renderTo).empty();
},
render: function (data) {
var self = this;
var wrappedData = {};
if (typeof (data) !== 'undefined') {
var template = self.hub.template(self);
wrappedData.data = data;
$(self.renderTo).html(template(wrappedData));
}
}
});
//seperate file
<div class="row-fluid">
<table class="table">
<thead>
<tr>
<td>Name</td>
<td>Leave Type</td>
<td>Start Date/ Time</td>
<td>End Date/ Time</td>
<td>Status</td>
</tr>
</thead>
<tbody>
{{#each data}}
<tr class="{{{formatLeaveStatus LeaveStatus}}}">
<td>{{Name}}</td>
<td>{{LeaveType}}</td>
<td>{{StartDateTime}}</td>
<td>{{EndDateTime}}</td>
<td>{{LeaveStatus}}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment