From b8a6335cde5fb91e79a5aa9ec7db994c012ff373 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Tue, 21 Nov 2017 15:51:16 -0800 Subject: [PATCH 1/2] Rewrite images/index.coffee as plain JS --- .../javascripts/spree/backend/images/index.js | 17 +++++++++++++++++ .../spree/backend/images/index.js.coffee | 13 ------------- 2 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 backend/app/assets/javascripts/spree/backend/images/index.js delete mode 100644 backend/app/assets/javascripts/spree/backend/images/index.js.coffee diff --git a/backend/app/assets/javascripts/spree/backend/images/index.js b/backend/app/assets/javascripts/spree/backend/images/index.js new file mode 100644 index 00000000000..c8b7c597374 --- /dev/null +++ b/backend/app/assets/javascripts/spree/backend/images/index.js @@ -0,0 +1,17 @@ +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(); + } + }); + }); +}); diff --git a/backend/app/assets/javascripts/spree/backend/images/index.js.coffee b/backend/app/assets/javascripts/spree/backend/images/index.js.coffee deleted file mode 100644 index d65f065b881..00000000000 --- a/backend/app/assets/javascripts/spree/backend/images/index.js.coffee +++ /dev/null @@ -1,13 +0,0 @@ -Spree.ready -> - ($ '#new_image_link').click (event) -> - event.preventDefault() - - ($ '.no-objects-found').hide() - - ($ this).hide() - Spree.ajax - type: 'GET' - url: @href - success: (r) -> - ($ '#images').html r - ($ 'select.select2').select2() From 8fa3f8cdaff8e87b9042c5851375ec5ebd0f5068 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Tue, 21 Nov 2017 15:55:46 -0800 Subject: [PATCH 2/2] Simplify new image "inline" form There's no need to do ajax here, we can render the form when we load the page. --- .../javascripts/spree/backend/images/index.js | 11 +---------- backend/app/views/spree/admin/images/_new.html.erb | 12 ++++++++++++ backend/app/views/spree/admin/images/index.html.erb | 4 +++- backend/app/views/spree/admin/images/new.html.erb | 13 +------------ 4 files changed, 17 insertions(+), 23 deletions(-) create mode 100644 backend/app/views/spree/admin/images/_new.html.erb diff --git a/backend/app/assets/javascripts/spree/backend/images/index.js b/backend/app/assets/javascripts/spree/backend/images/index.js index c8b7c597374..b2848583113 100644 --- a/backend/app/assets/javascripts/spree/backend/images/index.js +++ b/backend/app/assets/javascripts/spree/backend/images/index.js @@ -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(); }); }); diff --git a/backend/app/views/spree/admin/images/_new.html.erb b/backend/app/views/spree/admin/images/_new.html.erb new file mode 100644 index 00000000000..4a88ec3784d --- /dev/null +++ b/backend/app/views/spree/admin/images/_new.html.erb @@ -0,0 +1,12 @@ +<%= form_for [:admin, product, image], html: { multipart: true } do |f| %> +
+ <%= t('spree.new_image') %> + + <%= render partial: 'form', locals: { f: f } %> + +
+ <%= button t('spree.actions.update') %> + <%= link_to t('spree.actions.cancel'), admin_product_images_url(@product), id: 'cancel_link', class: 'button' %> +
+
+<% end %> diff --git a/backend/app/views/spree/admin/images/index.html.erb b/backend/app/views/spree/admin/images/index.html.erb index 421d15e9a83..4e8d76e5bce 100644 --- a/backend/app/views/spree/admin/images/index.html.erb +++ b/backend/app/views/spree/admin/images/index.html.erb @@ -9,7 +9,9 @@ <% end %> <% end %> -
+
<%= t(".upload_images") %> diff --git a/backend/app/views/spree/admin/images/new.html.erb b/backend/app/views/spree/admin/images/new.html.erb index d366d28747c..4c20f368393 100644 --- a/backend/app/views/spree/admin/images/new.html.erb +++ b/backend/app/views/spree/admin/images/new.html.erb @@ -1,12 +1 @@ -<%= form_for [:admin, @product, @image], html: { multipart: true } do |f| %> -
- <%= t('spree.new_image') %> - - <%= render partial: 'form', locals: { f: f } %> - -
- <%= button t('spree.actions.update') %> - <%= link_to t('spree.actions.cancel'), admin_product_images_url(@product), id: 'cancel_link', class: 'button' %> -
-
-<% end %> +<%= render 'new', product: @product, image: @image %>