Add child Quantity action added
This commit is contained in:
parent
b7b7401833
commit
c774f7745d
@ -3,7 +3,8 @@ class QuantitiesController < ApplicationController
|
|||||||
|
|
||||||
before_action :init_session_filters
|
before_action :init_session_filters
|
||||||
before_action :find_project_by_project_id, only: [:index, :new, :create, :filter, :parents]
|
before_action :find_project_by_project_id, only: [:index, :new, :create, :filter, :parents]
|
||||||
before_action :find_quantity, only: [:edit, :update, :destroy, :move]
|
before_action :find_quantity, only: [:edit, :update, :destroy, :move,
|
||||||
|
:new_child, :create_child]
|
||||||
before_action :authorize
|
before_action :authorize
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@ -75,6 +76,24 @@ class QuantitiesController < ApplicationController
|
|||||||
render :index
|
render :index
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def new_child
|
||||||
|
@parent_quantity = @quantity
|
||||||
|
@quantity = @project.quantities.new
|
||||||
|
@quantity.domain = @parent_quantity.domain
|
||||||
|
@quantity.parent = @parent_quantity
|
||||||
|
@quantity.build_formula
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_child
|
||||||
|
@quantity = @project.quantities.new(quantity_params)
|
||||||
|
if @quantity.save
|
||||||
|
flash[:notice] = 'Created new quantity'
|
||||||
|
prepare_quantities
|
||||||
|
else
|
||||||
|
render :new_child
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def init_session_filters
|
def init_session_filters
|
||||||
|
@ -46,6 +46,10 @@
|
|||||||
<td class="description"><%= q.description %></td>
|
<td class="description"><%= q.description %></td>
|
||||||
<td class="formula"><%= checked_image q.formula %></td>
|
<td class="formula"><%= checked_image q.formula %></td>
|
||||||
<td class="action unwrappable">
|
<td class="action unwrappable">
|
||||||
|
<%= link_to l(:button_child), new_child_quantity_path(q), {
|
||||||
|
remote: true,
|
||||||
|
class: "icon icon-add"
|
||||||
|
} %>
|
||||||
<%= link_to l(:button_edit), edit_quantity_path(q), {
|
<%= link_to l(:button_edit), edit_quantity_path(q), {
|
||||||
remote: true,
|
remote: true,
|
||||||
class: "icon icon-edit"
|
class: "icon icon-edit"
|
||||||
|
15
app/views/quantities/_new_child_form.html.erb
Normal file
15
app/views/quantities/_new_child_form.html.erb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<%= labelled_form_for @quantity,
|
||||||
|
url: create_child_quantity_path(@parent_quantity),
|
||||||
|
remote: true,
|
||||||
|
html: {id: 'new-child-form', name: 'new-child-form'} do |f| %>
|
||||||
|
|
||||||
|
<%= render partial: 'quantities/form', locals: {f: f} %>
|
||||||
|
|
||||||
|
<div class="tabular">
|
||||||
|
<p>
|
||||||
|
<%= submit_tag l(:button_create) %>
|
||||||
|
<%= link_to l(:button_cancel), "#",
|
||||||
|
onclick: '$(this).closest("tr").remove(); return false;' %>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
2
app/views/quantities/create_child.js.erb
Normal file
2
app/views/quantities/create_child.js.erb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<%= render partial: 'body_trackers/flash' %>
|
||||||
|
$('#quantities').html('<%= j render partial: 'quantities/index' %>');
|
8
app/views/quantities/new_child.js.erb
Normal file
8
app/views/quantities/new_child.js.erb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<%= render partial: 'body_trackers/flash' %>
|
||||||
|
$('tr[id=quantity-<%= @parent_quantity.id %>]').nextUntil('tr.quantity').remove();
|
||||||
|
var columns = $('table > thead > tr > th').length;
|
||||||
|
$('tr[id=quantity-<%= @parent_quantity.id %>]').nextAll('tr.quantity').first().before(
|
||||||
|
'<tr><td class="form" colspan="'+columns+'">' +
|
||||||
|
'<div id="new-child-quantity"><%= j render partial: "quantities/new_child_form" %></div>' +
|
||||||
|
'</td></tr>'
|
||||||
|
);
|
@ -17,6 +17,7 @@ en:
|
|||||||
field_code: 'Formula'
|
field_code: 'Formula'
|
||||||
field_shortname: 'Short name'
|
field_shortname: 'Short name'
|
||||||
button_retake: 'Retake'
|
button_retake: 'Retake'
|
||||||
|
button_child: 'Child'
|
||||||
activerecord:
|
activerecord:
|
||||||
errors:
|
errors:
|
||||||
models:
|
models:
|
||||||
|
@ -27,6 +27,8 @@ resources :projects, shallow: true do
|
|||||||
resources :sources, only: [:index, :create, :destroy]
|
resources :sources, only: [:index, :create, :destroy]
|
||||||
resources :quantities, only: [:index, :new, :create, :edit, :update, :destroy] do
|
resources :quantities, only: [:index, :new, :create, :edit, :update, :destroy] do
|
||||||
member do
|
member do
|
||||||
|
get 'new_child'
|
||||||
|
post 'create_child'
|
||||||
post 'move/:direction', to: 'quantities#move', as: :move
|
post 'move/:direction', to: 'quantities#move', as: :move
|
||||||
end
|
end
|
||||||
collection do
|
collection do
|
||||||
|
2
init.rb
2
init.rb
@ -28,7 +28,7 @@ Redmine::Plugin.register :body_tracking do
|
|||||||
ingredients: [:new, :create, :edit, :update, :destroy, :toggle, :toggle_column,
|
ingredients: [:new, :create, :edit, :update, :destroy, :toggle, :toggle_column,
|
||||||
:import],
|
:import],
|
||||||
sources: [:create, :destroy],
|
sources: [:create, :destroy],
|
||||||
quantities: [:new, :create, :edit, :update, :destroy, :move],
|
quantities: [:new, :create, :edit, :update, :destroy, :move, :new_child, :create_child],
|
||||||
units: [:create, :destroy],
|
units: [:create, :destroy],
|
||||||
}, require: :loggedin
|
}, require: :loggedin
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user