Added quantity edit form
Changed quantity long text field width setting
This commit is contained in:
parent
8c073494e5
commit
fdfedf3bc9
@ -1,7 +1,7 @@
|
||||
class QuantitiesController < ApplicationController
|
||||
before_action :init_session_filters
|
||||
before_action :find_project_by_project_id, only: [:index, :create, :filter]
|
||||
before_action :find_quantity, only: [:destroy, :toggle, :move]
|
||||
before_action :find_quantity, only: [:edit, :update, :destroy, :toggle, :move]
|
||||
before_action :authorize
|
||||
|
||||
def index
|
||||
@ -21,6 +21,17 @@ class QuantitiesController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def filter
|
||||
session[:q_filters] = params[:filters]
|
||||
prepare_quantities
|
||||
render :toggle
|
||||
end
|
||||
|
||||
def edit
|
||||
prepare_quantities
|
||||
render :toggle
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @quantity.destroy
|
||||
flash[:notice] = 'Deleted quantity'
|
||||
@ -34,12 +45,6 @@ class QuantitiesController < ApplicationController
|
||||
prepare_quantities
|
||||
end
|
||||
|
||||
def filter
|
||||
session[:q_filters] = params[:filters]
|
||||
prepare_quantities
|
||||
render :toggle
|
||||
end
|
||||
|
||||
def move
|
||||
direction = params[:direction].to_sym
|
||||
case direction
|
||||
|
@ -9,8 +9,9 @@
|
||||
</div>
|
||||
<% end %>
|
||||
<p><%= f.text_field :name, size: 25, required: true %></p>
|
||||
<p><%= f.text_field :description, size: 200 %></p>
|
||||
<p><%= f.text_field :formula, size: 200, placeholder: t('.formula_placeholder') %></p>
|
||||
<p><%= f.text_field :description, style: "width: 100%;" %></p>
|
||||
<p><%= f.text_field :formula, placeholder: t('.formula_placeholder'),
|
||||
style: "width: 100%;" %></p>
|
||||
<p><%= f.check_box :primary %></p>
|
||||
</div>
|
||||
|
||||
|
81
app/views/quantities/_index.html.erb
Normal file
81
app/views/quantities/_index.html.erb
Normal file
@ -0,0 +1,81 @@
|
||||
<%= render :partial => 'quantities/filters',
|
||||
:locals => {:url => filter_project_quantities_path(@project)} %>
|
||||
|
||||
<% if @quantities.any? { |q| q.persisted? } %>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= l(:field_name) %></th>
|
||||
<th><%= l(:field_order) %></th>
|
||||
<th><%= l(:field_domain) %></th>
|
||||
<th><%= l(:field_description) %></th>
|
||||
<th><%= l(:field_action) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% Quantity.each_with_level(@quantities) do |q, level| %>
|
||||
<%
|
||||
next if q.new_record?
|
||||
quantity_class = "quantity"
|
||||
quantity_class += " project idnt idnt-#{level+1}"
|
||||
quantity_class += " primary" if q.primary
|
||||
%>
|
||||
<tr id="quantity-<%= q.id %>" class="<%= quantity_class %>">
|
||||
<td class="name">
|
||||
<%= link_to '', toggle_quantity_path(q), {
|
||||
remote: true,
|
||||
method: :post,
|
||||
class: "icon #{q.primary ? "icon-fav" : "icon-fav-off"}"
|
||||
}
|
||||
%>
|
||||
<%= q.name %>
|
||||
</td>
|
||||
<td class="order">
|
||||
<% [:up, :down, :left, :right].each do |direction| %>
|
||||
<%=
|
||||
if q.movable?(direction)
|
||||
link_to '', move_quantity_path(q, direction), {
|
||||
remote: true,
|
||||
method: :post,
|
||||
class: "icon icon-move-#{direction}"
|
||||
}
|
||||
else
|
||||
link_to '', '', {class: "icon"}
|
||||
end
|
||||
%>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="domain"><%= q.domain %></td>
|
||||
<td class="description"><%= q.description %></td>
|
||||
<td class="action">
|
||||
<%=
|
||||
link_to l(:button_edit), edit_quantity_path(q), {
|
||||
remote: true,
|
||||
class: "icon icon-edit"
|
||||
}
|
||||
%>
|
||||
<%= delete_link quantity_path(q), {remote: true, data: {}} %>
|
||||
</td>
|
||||
</tr>
|
||||
<% next unless (action_name == "edit") && (q == @quantity) %>
|
||||
<tr>
|
||||
<td class="form" colspan="6">
|
||||
<div id="edit-quantity">
|
||||
<%= labelled_form_for @quantity, url: quantity_path(@quantity), method: :patch,
|
||||
remote: true, html: {id: 'quantity-edit-form'} do |f| %>
|
||||
|
||||
<%= render :partial => 'quantities/form', :locals => { :f => f } %>
|
||||
<%= submit_tag l(:button_save) %>
|
||||
<%=
|
||||
link_to l(:button_cancel), "#", :onclick => '$("#edit-quantity").hide()'
|
||||
%>
|
||||
<% end %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
@ -1,60 +0,0 @@
|
||||
<%= render :partial => 'quantities/filters',
|
||||
:locals => {:url => filter_project_quantities_path(@project)} %>
|
||||
|
||||
<% if @quantities.any? { |q| q.persisted? } %>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= l(:field_name) %></th>
|
||||
<th><%= l(:field_order) %></th>
|
||||
<th><%= l(:field_domain) %></th>
|
||||
<th><%= l(:field_description) %></th>
|
||||
<th><%= l(:field_action) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% Quantity.each_with_level(@quantities) do |q, level| %>
|
||||
<%
|
||||
next if q.new_record?
|
||||
quantity_class = "quantity"
|
||||
quantity_class += " project idnt idnt-#{level+1}"
|
||||
quantity_class += " primary" if q.primary
|
||||
quantity_class += " anchor" if @anchor == q.id
|
||||
%>
|
||||
<tr id="quantity-<%= q.id %>" class="<%= quantity_class %>">
|
||||
<td class="name">
|
||||
<%= link_to '', toggle_quantity_path(q), {
|
||||
remote: true,
|
||||
method: :post,
|
||||
class: "icon #{q.primary ? "icon-fav" : "icon-fav-off"}"
|
||||
}
|
||||
%>
|
||||
<%= q.name %>
|
||||
</td>
|
||||
<td class="order">
|
||||
<% [:up, :down, :left, :right].each do |direction| %>
|
||||
<%=
|
||||
if q.movable?(direction)
|
||||
link_to '', move_quantity_path(q, direction), {
|
||||
remote: true,
|
||||
method: :post,
|
||||
class: "icon icon-move-#{direction}"
|
||||
}
|
||||
else
|
||||
link_to '', '', {class: "icon"}
|
||||
end
|
||||
%>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="domain"><%= q.domain %></td>
|
||||
<td class="description"><%= q.description %></td>
|
||||
<td class="action">
|
||||
<%= delete_link quantity_path(q), {remote: true, data: {}} %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
@ -5,7 +5,7 @@
|
||||
<div class="contextual">
|
||||
<% if User.current.allowed_to?(:manage_common, @project) %>
|
||||
<%= link_to t(".link_new_quantity"), '#', :class => 'icon icon-add',
|
||||
:onclick => '$("#add-quantity").show(); $("#quantity_name").focus(); return false;' %>
|
||||
:onclick => '$("#add-quantity").toggle(); $("#quantity_name").focus(); return false;' %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@ -24,5 +24,5 @@
|
||||
|
||||
<h2><%= t ".heading" %></h2>
|
||||
<div id='quantities'>
|
||||
<%= render :partial => 'quantities/list' %>
|
||||
<%= render :partial => 'quantities/index' %>
|
||||
</div>
|
||||
|
@ -1,3 +1,3 @@
|
||||
$('div[id^=flash_]').remove();
|
||||
$('#content').prepend('<%= escape_javascript(render_flash_messages) %>');
|
||||
$('#quantities').html('<%= escape_javascript(render :partial => 'quantities/list') %>');
|
||||
$('#quantities').html('<%= escape_javascript(render :partial => 'quantities/index') %>');
|
||||
|
@ -17,6 +17,10 @@ table.list td.value {
|
||||
white-space: nowrap;
|
||||
max-width: 1px;
|
||||
}
|
||||
table.list td.form {
|
||||
padding-right: 2px;
|
||||
text-align: left;
|
||||
}
|
||||
fieldset#filters table.filter td {padding-left: 8px;}
|
||||
|
||||
.icon-move-left { background-image: url(../images/1leftarrow.png); }
|
||||
|
@ -10,17 +10,21 @@ resources :projects do
|
||||
post 'toggle', on: :member
|
||||
end
|
||||
resources :ingredients, :only => [:index, :create, :destroy] do
|
||||
get 'nutrients', on: :collection
|
||||
post 'toggle_nutrient_column', on: :collection
|
||||
post 'toggle', on: :member
|
||||
get 'filter', on: :collection
|
||||
get 'filter_nutrients', on: :collection
|
||||
post 'import', on: :collection
|
||||
collection do
|
||||
get 'nutrients'
|
||||
get 'filter'
|
||||
get 'filter_nutrients'
|
||||
post 'toggle_nutrient_column'
|
||||
post 'import'
|
||||
end
|
||||
end
|
||||
resources :sources, :only => [:index, :create, :destroy]
|
||||
resources :quantities, :only => [:index, :create, :destroy] do
|
||||
post 'toggle', on: :member
|
||||
post 'move/:direction', to: 'quantities#move', as: :move, on: :member
|
||||
resources :quantities, :only => [:index, :create, :edit, :update, :destroy] do
|
||||
member do
|
||||
post 'toggle'
|
||||
post 'move/:direction', to: 'quantities#move', as: :move
|
||||
end
|
||||
get 'filter', on: :collection
|
||||
end
|
||||
resources :units, :only => [:index, :create, :destroy]
|
||||
|
2
init.rb
2
init.rb
@ -27,7 +27,7 @@ Redmine::Plugin.register :body_tracking do
|
||||
:measurements => [:create, :destroy, :toggle],
|
||||
:ingredients => [:create, :destroy, :toggle, :import, :toggle_nutrient_column],
|
||||
:sources => [:create, :destroy],
|
||||
:quantities => [:create, :destroy, :toggle, :move],
|
||||
:quantities => [:create, :edit, :update, :destroy, :toggle, :move],
|
||||
:units => [:create, :destroy],
|
||||
}, require: :loggedin
|
||||
end
|
||||
|
Reference in New Issue
Block a user