1
0

Add GoalController: #index, #new, #create

This commit is contained in:
cryptogopher
2021-02-21 18:10:15 +01:00
parent ea308a1e4a
commit 7f87b3bc84
20 changed files with 182 additions and 76 deletions

View File

@@ -1,13 +1,10 @@
<div class="tabular">
<%= fields_for 'measurement[routine_attributes]', routine do |ff| %>
<%= ff.hidden_field :id %>
<p>
<label><%= l(:field_name) %><span class="required"> *</span></label>
<%= ff.text_field :name, required: true, style: "width: 95%;" %>
</p>
<p>
<label><%= l(:field_description) %></label>
<%= ff.text_area :description, cols: 40, rows: 3, style: "width: 95%;" %>
</p>
<% end %>
<%= error_messages_for @goal %>
<div class="box tabular">
<p><%= goal_f.text_field :name, required: true, style: "width: 95%;" %></p>
<p><%= goal_f.text_area :description, rows: 3, style: "width: 95%;" %></p>
<hr style="width: 95%;">
<%= render partial: 'targets/form', locals: {goal_f: goal_f} %>
</div>

View File

@@ -0,0 +1,32 @@
<% if @goals.any? %>
<table id="goals" class="list odd-even">
<thead>
<tr>
<th><%= l(:field_name) %></th>
<th><%= l(:field_description) %></th>
<th style="width:5%"><%= l(:field_action) %></th>
</tr>
</thead>
<tbody>
<% @goals.each do |g| %>
<tr id="goal-<%= g.id %>" class="primary goal">
<td class="name unwrappable">
<div style="float:left;">
<%= checked_image g.is_binding %><%= link_to g.name, g %>
</div>
<div style="float:right;">
<%# TODO: display # of active targets/targeted quantities %>
<small><%#= " (#{pluralize(m.readouts.size, 'readout')})" %></small>
</div>
</td>
<td class="description ellipsible"><%= g.description %></td>
<td class="action unwrappable">
<%= delete_link(g, {remote: true, data: {}}) unless g.is_binding %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>

View File

@@ -0,0 +1,16 @@
<h2><%= t ".heading_new_goal" %></h2>
<%= labelled_form_for [@project, @goal], remote: true,
html: {id: 'new-goal-form', name: 'new-goal-form'} do |goal_f| %>
<%= render partial: 'goals/form', locals: {goal_f: goal_f} %>
<div class="tabular">
<p>
<%= submit_tag l(:button_create) %>
<%= link_to l(:button_cancel), "#",
onclick: "$('#new-goal').empty(); return false;" %>
</p>
</div>
<% end %>
<hr>

View File

@@ -0,0 +1,2 @@
$('#new-goal').empty();
$('#goals').html('<%= j render partial: 'goals/index' %>');

View File

@@ -0,0 +1,13 @@
<div class="contextual">
<%= link_to_if User.current.allowed_to?(:manage_body_trackers, @project),
t(".link_new_goal"), new_project_goal_path(@project),
{remote: true, class: 'icon icon-add'} %>
</div>
<div id="new-goal">
</div>
<%= title t(:body_trackers_title), t(".heading") %>
<div id='goals'>
<%= render partial: 'goals/index' %>
</div>

View File

@@ -0,0 +1 @@
$('#new-goal').html('<%= j render partial: 'goals/new_form' %>');