Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/controllers/donation_sites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@ def create
redirect_to donation_sites_path,
notice: "Donation site #{@donation_site.name} added!"
end
format.js
else
format.html do
flash.now[:error] = "Something didn't work quite right -- try again?"
render action: :new
end
format.js { render template: "donation_sites/new_modal" }
end
end
end

def new
@donation_site = current_organization.donation_sites.new
respond_to do |format|
format.html
format.js { render template: "donation_sites/new_modal" }
end
end

def edit
Expand Down
18 changes: 17 additions & 1 deletion app/javascript/utils/donations.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ $(function() {
const product_drive_participant_id = "#donation_product_drive_participant_id";
const product_drive_id = "#donation_product_drive_id"
const manufacturer_id = "#donation_manufacturer_id";
const donation_site_id="#donation_donation_site_id"

const donation_site_container_id = "div.donation_donation_site";
const product_drive_container_id = "div.donation_product_drive";
Expand All @@ -17,8 +18,8 @@ $(function() {

const create_new_product_drive_text = "---Create new Product Drive---";
const create_new_product_drive_participant_text = "---Create new Participant---";

const create_new_manufacturer_text = "---Create new Manufacturer---";
const create_new_donation_site_text = "---Create New Donation Site---";

$(product_drive_id).append(

Expand All @@ -32,6 +33,10 @@ $(function() {
`<option value="">${create_new_manufacturer_text}</option>`
);

$(donation_site_id).append(
`<option value="">${create_new_donation_site_text}</option>`
)

$(document).on("change", product_drive_id, function(evt) {
const selection = $(product_drive_id + " option")
.filter(":selected")
Expand Down Expand Up @@ -61,6 +66,17 @@ $(function() {
}
});

$(document).on("change", donation_site_id, function(evt) {
const selection = $(donation_site_id + " option")
.filter(":selected")
.text();

if (selection === create_new_donation_site_text) {
document.getElementById("new_donation_site").click()
}
});


function handleSourceSelection() {
const selection = $(control_id + " option")
.filter(":selected")
Expand Down
4 changes: 2 additions & 2 deletions app/views/donation_sites/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= simple_form_for form, html: {role: "form"} do |f| %>
<%= simple_form_for form, remote: request.xhr?, html: {role: "form"} do |f| %>
<section class="content">
<div class="container-fluid">
<div class="row">
Expand Down Expand Up @@ -37,7 +37,7 @@
</div>
<!-- /.card-body -->
<div class="card-footer">
<%= submit_button %>
<%= submit_button({id: "donation-site-submit"}) %>
</div>
<% end %>
</div>
Expand Down
27 changes: 27 additions & 0 deletions app/views/donation_sites/_new_modal.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div class="modal-dialog">

<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="mainModalLabel">
New Donation Site
</h4>
<button type="button" class="close" data-bs-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
<% flash.each do |key, value| %>
<div class="<%= flash_class(key) %> alert-dismissible">
<a href="#" class="close btn-close" data-bs-dismiss="alert" aria-label="close" style="text-decoration: none;"><%= fa_icon('times') %></a>
<%= value %>
</div>
<% end %>

<%= render partial: "form", object: @donation_site %>

</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-bs-dismiss="modal">Close</button>
</div>
</div>

</div>
6 changes: 6 additions & 0 deletions app/views/donation_sites/create.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% flash.discard %>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using JS ERB is a really old pattern that we'd prefer not using. Turbo and Stimulus are more modern ways of achieving the same goal. Can you look into those approaches? We use them elsewhere in the app.

$("#modal_new").modal("hide");
$("#donation_donation_site_id").empty();
$("#donation_donation_site_id").html('<%= j options_from_collection_for_select(current_organization.donation_sites, :id, :name) %>');
$("#donation_donation_site_id").append('<option value="">---Create New Donation Site---</option>');
$("#donation_donation_site_id").val('<%= @donation_site[:id] %>');
2 changes: 2 additions & 0 deletions app/views/donation_sites/new_modal.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$("#modal_new").html("<%= j (render "donation_sites/new_modal") %>");
$("#modal_new").modal("show");
1 change: 1 addition & 0 deletions app/views/donations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<%= link_to "Add product drive", new_product_drive_path, {:remote => true, "data-bs-target" => "#modal-window", id: "new_product_drive", "style" => "display: none;"} %>
<%= link_to "Add product drive participant", new_product_drive_participant_path, {:remote => true, "data-bs-target" => "#modal-window", id: "new_participant", "style" => "display: none;"} %>
<%= link_to "Add manufacturer", new_manufacturer_path, {:remote => true, "data-bs-target" => "#modal-window", id: "new_manufacturer", "style" => "display: none;"} %>
<%= link_to "Add donation site", new_donation_site_path, {:remote => true, "data-bs-target" => "#modal-window", id: "new_donation_site", "style" => "display: none;"} %>
</div><!-- /.box -->
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/manufacturers/_new_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-bs-dismiss="modal">&times;</button>
<h4 class="modal-title" id="mainModalLabel">
New Manufacturer
</h4>
<button type="button" class="close" data-bs-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
<% flash.each do |key, value| %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/product_drives/_new_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-bs-dismiss="modal">&times;</button>
<h4 class="modal-title" id="mainModalLabel">
New Product Drive
</h4>
<button type="button" class="close" data-bs-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
<% flash.each do |key, value| %>
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide/bank/essentials_donations.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ For Product Drive, Manufacturer, or Donation Site, you will further specify the
If you specify Product drive, you'll also need to specify the particular drive and participant for the Donation -- but you can enter them "on the fly", here. You can view summaries for the Product Drives in [Product Drives](product_drives.md), and manage the contact info for a Product Drive Participant under [Community -- Product Drive Participants](community_product_drive_participants.md).
##### *Donation Site
Donation Site is meant to capture the concept of any place you have a more-or-less permanent place people can drop off donations at, such as your main office, or community locations such as fire halls, etc.
You can see the Donations for each Donation Site and manage their contact information under [Community -- Donation Sites](community_donation_sites.md). Unlike Product Drives, you can't create a new Donation Site 'on the fly' through the fields here
You can see the Donations for each Donation Site and manage their contact information under [Community -- Donation Sites](community_donation_sites.md). Like Product Drives, you can create a new Donation Site 'on the fly' through the fields here too.
##### *Manufacturer
This is for the donations that come straight from a Manufacturer. You can view a breakdown of the Donations for each Manufacturer under [Community -- Manufacturers](community_manufacturers.md)
##### *Misc. Donation
Expand Down
13 changes: 13 additions & 0 deletions spec/system/donation_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@
select "drivenametest", from: "donation_product_drive_id"
end

it "Allows User to create a Donation Site from donation" do
select Donation::SOURCES[:donation_site], from: "donation_source"
select "---Create New Donation Site---", from: "donation_donation_site_id"

find(".modal-content")
expect(page).to have_content("New Donation Site")

fill_in "donation_site_name", with: "donationsitetest"
fill_in "donation_site_address", with: "1500 Remount Road, Front Royal, VA 22630"
click_on "donation-site-submit"
select "donationsitetest", from: "donation_donation_site_id"
end

it "Allows User to create a Product Drive Participant from donation" do
select Donation::SOURCES[:product_drive], from: "donation_source"
select "---Create new Participant---", from: "donation_product_drive_participant_id"
Expand Down