houston/houston-core

View on GitHub
app/views/teams/_form.html.erb

Summary

Maintainability
Test Coverage
<%= form_for @team, :html => { :class => "form-horizontal" } do |f| %>
  <fieldset>
    <div class="control-group">
      <%= f.label :name, :class => "control-label" %>
      <div class="controls">
        <%= f.text_field :name, :class => "text_field" %>
      </div>
    </div>

    <hr />

    <div class="control-group">
      <%= f.label :roles, "Teammates", :class => "control-label" %>
      <div id="team_roles" class="controls changes-nested-editor nested editor"></div>
    </div>

    <div class="form-actions">
      <%= f.submit nil, :class => "btn btn-primary" %>
      <%= link_to "Cancel", teams_path, :class => "btn" %>

      <% if @team.persisted? && can?(:destroy, @team) %>
        <button class="btn btn-delete btn-danger" id="delete_team_button">Delete</button>
      <% end %>
    </div>
  </fieldset>
<% end %>

<% content_for :javascripts do %>
<script type="text/javascript">
  $(function() {
    new Houston.TeamRolesView({
      el: $('#team_roles')[0],
      roles: <%=raw Houston.config.roles.to_json %>,
      users: <%=raw User.unretired.pluck("CONCAT(first_name, ' ', last_name)", :id).map { |name, id| { name: name, id: id } }.to_json %>,
      values: <%=raw @team.roles.map { |role| { id: role.id, userId: role.user_id, roles: role.roles } }.to_json %>
    }).render();

    <% if @team.persisted? && can?(:destroy, @team) %>
    $('#delete_team_button').click(function(e) {
      e.preventDefault();
      $.destroy('<%= team_path(@team) %>')
        .success(function() { window.location = '/teams'; })
        .error(function(response) { Errors.fromResponse(response).renderToAlert(); });
    });
    <% end %>
  });
</script>
<% end %>