Skip to content

Commit

Permalink
Simplify new image "inline" form
Browse files Browse the repository at this point in the history
There's no need to do ajax here, we can render the form when we load the
page.
  • Loading branch information
jhawthorn committed Nov 22, 2017
1 parent b8a6335 commit 8fa3f8c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
11 changes: 1 addition & 10 deletions backend/app/assets/javascripts/spree/backend/images/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@ Spree.ready(function() {
$('#new_image_link').click(function(event) {
event.preventDefault();

$('.no-objects-found').hide();

$(this).hide();
Spree.ajax({
type: 'GET',
url: this.href,
success: function(r) {
$('#images').html(r);
$('select.select2').select2();
}
});
$('#new_image').show();
});
});
12 changes: 12 additions & 0 deletions backend/app/views/spree/admin/images/_new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%= form_for [:admin, product, image], html: { multipart: true } do |f| %>
<fieldset data-hook="new_image">
<legend align="center"><%= t('spree.new_image') %></legend>

<%= render partial: 'form', locals: { f: f } %>

<div class="form-buttons filter-actions actions" data-hook="buttons">
<%= button t('spree.actions.update') %>
<%= link_to t('spree.actions.cancel'), admin_product_images_url(@product), id: 'cancel_link', class: 'button' %>
</div>
</fieldset>
<% end %>
4 changes: 3 additions & 1 deletion backend/app/views/spree/admin/images/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<% end %>
<% end %>

<div id="images" data-hook></div>
<div id="new_image" class="hidden">
<%= render 'new', product: @product, image: Spree::Image.new(viewable: @product) %>
</div>

<fieldset>
<legend align="center"><%= t(".upload_images") %></legend>
Expand Down
13 changes: 1 addition & 12 deletions backend/app/views/spree/admin/images/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
<%= form_for [:admin, @product, @image], html: { multipart: true } do |f| %>
<fieldset data-hook="new_image">
<legend align="center"><%= t('spree.new_image') %></legend>

<%= render partial: 'form', locals: { f: f } %>

<div class="form-buttons filter-actions actions" data-hook="buttons">
<%= button t('spree.actions.update') %>
<%= link_to t('spree.actions.cancel'), admin_product_images_url(@product), id: 'cancel_link', class: 'button' %>
</div>
</fieldset>
<% end %>
<%= render 'new', product: @product, image: @image %>

0 comments on commit 8fa3f8c

Please sign in to comment.