Skip to content

Instantly share code, notes, and snippets.

@jamlfy
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save jamlfy/d30107b96662abab693a to your computer and use it in GitHub Desktop.

Select an option

Save jamlfy/d30107b96662abab693a to your computer and use it in GitHub Desktop.
// Tu modelo... bla... bla..
module.exports = {
attributes: {
// Los Atributos....
},
damePlantas: function (){
try {
var pl = JSON.parse(this.plantas);
return pl;
}catch(e){
// e Es el error generado
return _.isObject(this.plantas) ? this.plantas : {};
}
},
// Uso
user.damePlantas() --> Objeto
<h3>Gestión de usuarios</h3>
<table class='table'>
<tr>
<th></th>
<th>ID</th>
<th>Nombre</th>
<th>Email</th>
<th>Plantas</th>
<th></th>
<th></th>
<th></th>
</tr>
<% _.each(users, function(user) { %>
<tr data-id="<%= user.id %>" data-model="user">
<% if (user.online) { %>
<td><img src="/images/icon-online.png"></td>
<% } else { %>
<td> <img src="/images/icon-offline.png"></td>
<% } %>
<td><%= user.id %></td>
<td><%= user.name %></td>
<td><%= user.email %></td>
<td>
<% if (user.plantas){ %>
<% _.each(JSON.parse(user.plantas), function(planta_name, planta_id) {
<div><%= sails.config.mon.plantas[planta_id.toUpperCase()] %></div>
<% }); %>
<% } %>
</td>
<% if (user.admin) { %>
<td><img src="/images/admin.png"></td>
<% } else { %>
<td> <img src="/images/pawn.png"></td>
<% } %>
<td><a href="/user/show/<%= user.id %>" class="btn btn-sm btn-primary">Ver</a></td>
<td><a href="/user/edit/<%= user.id %>" class="btn btn-sm btn-warning">Editar</a></td>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment