-
-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from rubyforgood/new-distributions
New distributions
- Loading branch information
Showing
7 changed files
with
122 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,26 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ | ||
|
||
$ -> | ||
$(document).on "change", "select#distribution_storage_location_id", -> | ||
control = $("select#distribution_storage_location_id") | ||
$.ajax | ||
url: control.data("storage-location-inventory-path").replace(":id", control.val()) | ||
dataType: "json" | ||
success: (data) -> | ||
options = "" | ||
$.each data, (index) -> | ||
options += "<option value=\"" + data[index].item_id + "\">" + data[index].item_name + "</option>\n" | ||
$("#transfer_line_items select").find('option').remove().end().append(options) | ||
|
||
$(document).on "cocoon:after-insert", "form#new_distribution", (e, insertedItem) -> | ||
control = $("select#distribution_storage_location_id") | ||
$.ajax | ||
url: control.data("storage-location-inventory-path").replace(":id", control.val()) | ||
dataType: "json" | ||
success: (data) -> | ||
options = "" | ||
$.each data, (index) -> | ||
options += "<option value=\"" + data[index].item_id + "\">" + data[index].item_name + "</option>\n" | ||
$("select", insertedItem).find('option').remove().end().append(options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div class="nested-fields"> | ||
<div class="row"> | ||
<div class="small-3 small-offset-3 columns"> | ||
<%= f.input_field :item_id, collection: @items, prompt: "Choose an item" %> | ||
</div> | ||
<div class="small-2 columns"> | ||
<%= f.input_field :quantity, placeholder: "Quantity" %> | ||
</div> | ||
|
||
<%= link_to_remove_association "X", f, class: "button tiny alert float-left" %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,46 @@ | ||
<h1>Distributions#new</h1> | ||
<p>Find me in app/views/distributions/new.html.erb</p> | ||
<h1>Create a new distribution</h1> | ||
|
||
<%= simple_form_for @distribution, wrapper: :horizontal_form do |f| %> | ||
<%= f.association :partner, | ||
label: "Partner", | ||
error: "Which partner is this distribution going to?" | ||
%> | ||
<%= f.association :storage_location, | ||
collection: @storage_locations, | ||
label: "From storage location", | ||
error: "Which location are you moving inventory from?", | ||
input_html: { | ||
data: { | ||
storage_location_inventory_path: inventory_storage_location_path( | ||
organization_id: current_organization, | ||
id: ":id", | ||
format: :json | ||
) | ||
} | ||
} | ||
%> | ||
<%= f.input :comment, | ||
label: "Comment" %> | ||
<%= f.simple_fields_for :line_items do |item| %> | ||
<div id="transfer_line_items"> | ||
<%= render 'line_item_fields', f: item %> | ||
</div> | ||
<div class="row links"> | ||
<div class="small-offset-3 small-9 columns"> | ||
<%= link_to_add_association "add line item", f, :line_items, | ||
data: { | ||
association_insertion_node: "#transfer_line_items", | ||
association_insertion_method: "append" | ||
} | ||
%> | ||
</div> | ||
</div> | ||
<% end %> | ||
<%= f.button :submit %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,23 @@ | ||
RSpec.describe "distributions/new.html.erb", type: :view do | ||
before(:each) do | ||
@organization = create(:organization) | ||
@storage_location = create(:storage_location, organization_id: @organization.id) | ||
@partner = create(:partner, organization_id: @organization.id) | ||
|
||
assign(:distribution, Distribution.new) | ||
assign(:storage_locations, [@storage_location]) | ||
assign(:partner, @partner) | ||
assign(:organization_id, @organization.id) | ||
|
||
RSpec.describe "distributions/new.html.erb", type: :view do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
render | ||
end | ||
|
||
it "Asks for storage location and partner", :focus do | ||
expect(rendered).to have_xpath("//form/div/select[@name='distribution[storage_location_id]']") | ||
expect(rendered).to have_xpath("//form/div/select[@name='distribution[partner_id]']") | ||
end | ||
|
||
xit "shows fields for the user to add items to this distribution" do | ||
# TODO: How should this work? | ||
end | ||
end |