Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4396 packs 1 add custom request units at organizational level #4415

2 changes: 1 addition & 1 deletion app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def organization_params
:enable_individual_requests, :enable_quantity_based_requests,
:ytd_on_distribution_printout, :one_step_partner_invite,
:hide_value_columns_on_receipt, :hide_package_column_on_receipt,
partner_form_fields: []
partner_form_fields: [], request_units_attributes: [:id, :name]
)
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def flipper_id

has_one_attached :logo

accepts_nested_attributes_for :users, :account_request
accepts_nested_attributes_for :users, :account_request, :request_units

include Geocodable

Expand Down
1 change: 1 addition & 0 deletions app/models/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
#
class Unit < ApplicationRecord
belongs_to :organization
validates_uniqueness_of :name, scope: :organization
end
1 change: 1 addition & 0 deletions app/services/organization_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def update(organization, params)
if params.has_key?("partner_form_fields")
params["partner_form_fields"].delete_if { |field| field == "" }
end
organization.request_units.destroy_all
result = organization.update(params)
return false unless result
update_partner_flags(organization)
Expand Down
16 changes: 16 additions & 0 deletions app/views/organizations/_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@
<%= humanize_boolean(@organization.distribute_monthly) %>
</p>
</div>
<div class="mb-4">
<h3 class='font-bold'>Custom Request Units</h3>
<p>
<% if @organization.request_units.length > 0 %>
<% @organization.request_units.map do |unit| %>
<%= fa_icon "angle-right" %>
<span >
<%= unit.name.titlecase %>
</span> <br>
<% end %>
<% else %>
<%= fa_icon "angle-right" %>
<span> None </span>
<% end %>
</p>
</div>
<div class="mb-4">
<h3 class='font-bold'>Child Based Requests?</h3>
<p>
Expand Down
7 changes: 6 additions & 1 deletion app/views/organizations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
</div><!-- /.container-fluid -->
</section>

<%= simple_form_for current_organization, url: {controller: "organizations", action: "update"} do |f| %>
<%= simple_form_for current_organization,
data: { controller: "form-input" },
url: {controller: "organizations", action: "update"} do |f| %>
<section class="content">
<div class="container-fluid">
<div class="row">
Expand Down Expand Up @@ -100,6 +102,9 @@

<%= f.input :repackage_essentials, label: 'Does your bank repackage essentials?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>
<%= f.input :distribute_monthly, label: 'Does your bank distribute monthly?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>

<%= render 'units/request_units' , f: f %>

<%= f.input :enable_child_based_requests, label: 'Enable partners to make child-based requests?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>
<%= f.input :enable_individual_requests, label: 'Enable partners to make requests for individuals?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>
<%= f.input :enable_quantity_based_requests, label: 'Enable partners to make quantity-based requests?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>
Expand Down
15 changes: 15 additions & 0 deletions app/views/units/_request_units.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<table class='table'>
<thead>
<tr>
<th>Custom request units used (please use singular form -- e.g. pack, not packs)</th>
</tr>
</thead>
<tbody id='request-fields'>
<%= render 'units/unit_line_item' , f: f, object: :request_units %>
</tbody>
</table>
<div>
<%= add_element_button('Add Another Item', container_selector: '#request-fields' ) do %>
<%= render 'units/unit_line_item' , f: f, object: Unit.new %>
<% end %>
</div>
12 changes: 12 additions & 0 deletions app/views/units/_unit_line_item.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%= f.fields_for :request_units, defined?(object) ? object : nil do |field| %>
<tr data-form-input-target="removeContainer">
<td>
<!-- <%= f.input :whatever, label: "Whatever" , wrapper: :input_group do %> -->
<%= field.input_field :name, class: "form-control" %>
<!-- <% end %> -->
</td>
<td>
<%= remove_element_button "Remove" , container_selector: '#td-remove' %>
</td>
</tr>
<% end %>
Loading