From 353d6fbc5fa3aadeacce6d411036a74bcb5b2e65 Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Wed, 24 Jul 2019 16:36:15 +0200 Subject: [PATCH 01/10] Import variants/index from spree_backend to ofn and convert to Haml --- .../replace_options_text.html.haml.deface | 3 -- .../spree/admin/variants/index.html.haml | 54 +++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) delete mode 100644 app/overrides/spree/admin/variants/index/replace_options_text.html.haml.deface create mode 100644 app/views/spree/admin/variants/index.html.haml diff --git a/app/overrides/spree/admin/variants/index/replace_options_text.html.haml.deface b/app/overrides/spree/admin/variants/index/replace_options_text.html.haml.deface deleted file mode 100644 index 5b76f19fa6..0000000000 --- a/app/overrides/spree/admin/variants/index/replace_options_text.html.haml.deface +++ /dev/null @@ -1,3 +0,0 @@ -/ replace "code[erb-loud]:contains('variant.options_text')" - -= variant.full_name diff --git a/app/views/spree/admin/variants/index.html.haml b/app/views/spree/admin/variants/index.html.haml new file mode 100644 index 0000000000..a676e92de3 --- /dev/null +++ b/app/views/spree/admin/variants/index.html.haml @@ -0,0 +1,54 @@ += render partial: 'spree/admin/shared/product_sub_menu' + += render partial: 'spree/admin/shared/product_tabs', locals: {current: 'Variants'} + +#new_variant +- if @variants.any? + %table.index.sortable{"data-sortable-link" => update_positions_admin_product_variants_path(@product)} + %colgroup + %col{style: "width: 5%"}/ + %col{style: "width: 25%"}/ + %col{style: "width: 20%"}/ + %col{style: "width: 20%"}/ + %col{style: "width: 15%"}/ + %col{style: "width: 15%"}/ + %thead{"data-hook" => "variants_header"} + %tr + %th{colspan: "2"}= Spree.t(:options) + %th= Spree.t(:price) + %th= Spree.t(:sku) + %th.actions + %tbody + - @variants.each do |variant| + %tr{id: spree_dom_id(variant), "data-hook" => "variants_row", class: cycle('odd', 'even'), style: "#{"color:red;" if variant.deleted? }" } + %td.no-border + %span.handle + %td= variant.full_name + %td.align-center= variant.display_price.to_html + %td.align-center= variant.sku + %td.actions + = link_to_edit(variant, no_text: true) unless variant.deleted? + = link_to_delete(variant, no_text: true) unless variant.deleted? + - unless @product.has_variants? + %tr + %td{colspan: "5"}= Spree.t(:none) + +- else + .alpha.twelve.columns.no-objects-found + = Spree.t(:no_results) + \. + +- if @product.empty_option_values? + %p.first_add_option_types.no-objects-found{"data-hook" => "first_add_option_types"} + = Spree.t(:to_add_variants_you_must_first_define) + = link_to Spree.t(:option_types), admin_product_url(@product) + = Spree.t(:and) + = link_to Spree.t(:option_values), admin_option_types_url + +- else + - content_for :page_actions do + %ul.inline-menu{"data-hook" => "toolbar"} + %li#new_var_link{"data-hook" => ""} + = link_to_with_icon('icon-plus', Spree.t(:new_variant), new_admin_product_variant_url(@product), remote: true, 'data-update' => 'new_variant', class: 'button') + + %li= link_to_with_icon('icon-filter', @deleted.blank? ? Spree.t(:show_deleted) : Spree.t(:show_active), admin_product_variants_url(@product, deleted: @deleted.blank? ? "on" : "off"), class: 'button') From 986837d60126b93c7a76ddb35e405bac5aeabd86 Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Thu, 25 Jul 2019 11:07:35 +0200 Subject: [PATCH 02/10] Import variants/_form.html.erb from spree_backend to ofn and de-deface it --- .../admin/variants/_form/add_angular.deface | 2 - ...nit_value_and_description.html.haml.deface | 25 ----- .../add_stock_management.html.haml.deface | 11 -- .../hide_unit_option_types.html.haml.deface | 10 -- .../_form/on_demand_script.html.haml.deface | 33 ------ .../_form/on_demand_tooltip.html.haml.deface | 3 - .../_form/replace_weight.html.haml.deface | 14 --- .../spree/admin/variants/_form.html.haml | 104 ++++++++++++++++++ 8 files changed, 104 insertions(+), 98 deletions(-) delete mode 100644 app/overrides/spree/admin/variants/_form/add_angular.deface delete mode 100644 app/overrides/spree/admin/variants/_form/add_display_name_unit_value_and_description.html.haml.deface delete mode 100644 app/overrides/spree/admin/variants/_form/add_stock_management.html.haml.deface delete mode 100644 app/overrides/spree/admin/variants/_form/hide_unit_option_types.html.haml.deface delete mode 100644 app/overrides/spree/admin/variants/_form/on_demand_script.html.haml.deface delete mode 100644 app/overrides/spree/admin/variants/_form/on_demand_tooltip.html.haml.deface delete mode 100644 app/overrides/spree/admin/variants/_form/replace_weight.html.haml.deface create mode 100644 app/views/spree/admin/variants/_form.html.haml diff --git a/app/overrides/spree/admin/variants/_form/add_angular.deface b/app/overrides/spree/admin/variants/_form/add_angular.deface deleted file mode 100644 index 507e821e9c..0000000000 --- a/app/overrides/spree/admin/variants/_form/add_angular.deface +++ /dev/null @@ -1,2 +0,0 @@ -add_to_attributes '[data-hook="admin_variant_form_fields"]' -attributes 'ng-app' => 'admin.products' \ No newline at end of file diff --git a/app/overrides/spree/admin/variants/_form/add_display_name_unit_value_and_description.html.haml.deface b/app/overrides/spree/admin/variants/_form/add_display_name_unit_value_and_description.html.haml.deface deleted file mode 100644 index 34e1bafe5c..0000000000 --- a/app/overrides/spree/admin/variants/_form/add_display_name_unit_value_and_description.html.haml.deface +++ /dev/null @@ -1,25 +0,0 @@ -/ insert_top "[data-hook='admin_variant_form_fields']" - -.field - = f.label :display_name, t(:display_name) - = f.text_field :display_name, class: "fullwidth" -.field - = f.label :display_as, t(:display_as) - = f.text_field :display_as, class: "fullwidth" - -- if product_has_variant_unit_option_type?(@product) - - if @product.variant_unit != 'items' - .field{"data-hook" => "unit_value", 'ng-controller' => 'variantUnitsCtrl'} - = f.label :unit_value, "#{t('admin.'+@product.variant_unit)} ({{unitName(#{@product.variant_unit_scale}, '#{@product.variant_unit}')}})" - = hidden_field_tag 'product_variant_unit_scale', @product.variant_unit_scale - = text_field_tag :unit_value_human, nil, {class: "fullwidth", 'ng-model' => 'unit_value_human', 'ng-change' => 'updateValue()'} - = f.text_field :unit_value, {hidden: true, 'ng-value' => 'unit_value'} - - .field{"data-hook" => "unit_description"} - = f.label :unit_description, t(:spree_admin_unit_description) - = f.text_field :unit_description, class: "fullwidth", placeholder: t('admin.products.unit_name_placeholder') - - :javascript - angular.element(document.getElementById("new_variant")).ready(function() { - angular.bootstrap(document.getElementById("new_variant"), ['admin.products']); - }); diff --git a/app/overrides/spree/admin/variants/_form/add_stock_management.html.haml.deface b/app/overrides/spree/admin/variants/_form/add_stock_management.html.haml.deface deleted file mode 100644 index e899da406c..0000000000 --- a/app/overrides/spree/admin/variants/_form/add_stock_management.html.haml.deface +++ /dev/null @@ -1,11 +0,0 @@ -/ insert_bottom "[data-hook='admin_variant_form_fields']" - -- if Spree::Config[:track_inventory_levels] - .field.checkbox - %label - = f.check_box :on_demand - = t(:on_demand) - .field - = f.label :on_hand, t(:on_hand) - .fullwidth - = f.text_field :on_hand diff --git a/app/overrides/spree/admin/variants/_form/hide_unit_option_types.html.haml.deface b/app/overrides/spree/admin/variants/_form/hide_unit_option_types.html.haml.deface deleted file mode 100644 index a8dee8c022..0000000000 --- a/app/overrides/spree/admin/variants/_form/hide_unit_option_types.html.haml.deface +++ /dev/null @@ -1,10 +0,0 @@ -/ replace "[data-hook='presentation']" - -- unless variant_unit_option_type?(option_type) - .field{"data-hook" => "presentation"} - = label :new_variant, option_type.presentation - - if @variant.new_record? - = select(:new_variant, option_type.presentation, option_type.option_values.collect {|ov| [ ov.presentation, ov.id ] }, {}, {:class => 'select2 fullwidth'}) - - else - - if opt = @variant.option_values.detect {|o| o.option_type == option_type }.try(:presentation) - = text_field(:new_variant, option_type.presentation, :value => opt, :disabled => 'disabled', :class => 'fullwidth') diff --git a/app/overrides/spree/admin/variants/_form/on_demand_script.html.haml.deface b/app/overrides/spree/admin/variants/_form/on_demand_script.html.haml.deface deleted file mode 100644 index b90731813b..0000000000 --- a/app/overrides/spree/admin/variants/_form/on_demand_script.html.haml.deface +++ /dev/null @@ -1,33 +0,0 @@ -/ insert_bottom "[data-hook='admin_variant_form_fields']" -:javascript - - $(document).ready(function() { - - var on_demand = $('input#variant_on_demand'); - var on_hand = $('input#variant_on_hand'); - - disableOnHandIfOnDemand = function() { - on_demand_checked = on_demand.attr('checked') - if ( on_demand_checked == undefined ) - on_demand_checked = false; - - on_hand.attr('disabled', on_demand_checked); - if(on_demand_checked) { - on_hand.attr('data-stock', on_hand.val()); - on_hand.val(t('admin.products.variants.infinity')); - } - } - - disableOnHandIfOnDemand(); - - on_demand.change(function(){ - disableOnHandIfOnDemand(); - if(!this.checked) { - if(on_hand.attr('data-stock') !== undefined) { - on_hand.val(on_hand.attr('data-stock')); - } else { - on_hand.val("0"); - } - } - }); - }); diff --git a/app/overrides/spree/admin/variants/_form/on_demand_tooltip.html.haml.deface b/app/overrides/spree/admin/variants/_form/on_demand_tooltip.html.haml.deface deleted file mode 100644 index abcea6cec6..0000000000 --- a/app/overrides/spree/admin/variants/_form/on_demand_tooltip.html.haml.deface +++ /dev/null @@ -1,3 +0,0 @@ -/ insert_bottom "[data-hook='on_demand']" -%div{'ofn-with-tip' => t('admin.products.variants.to_order_tip')} - %a= t('admin.whats_this') diff --git a/app/overrides/spree/admin/variants/_form/replace_weight.html.haml.deface b/app/overrides/spree/admin/variants/_form/replace_weight.html.haml.deface deleted file mode 100644 index 0618c3bab5..0000000000 --- a/app/overrides/spree/admin/variants/_form/replace_weight.html.haml.deface +++ /dev/null @@ -1,14 +0,0 @@ -/ replace "[data-hook='admin_variant_form_additional_fields']" - -.right.six.columns.omega.label-block{"data-hook" => "admin_variant_form_additional_fields"} - - if @product.variant_unit != 'weight' - .field{"data-hook" => 'weight'} - = f.label 'weight', t('weight')+' (kg)' - - value = number_with_precision(@variant.weight, :precision => 2) - = f.text_field 'weight', :value => value, :class => 'fullwidth' - - - [:height, :width, :depth].each do |field| - .field{"data-hook" => field} - = f.label field, t(field) - - value = number_with_precision(@variant.send(field), :precision => 2) - = f.text_field field, :value => value, :class => 'fullwidth' diff --git a/app/views/spree/admin/variants/_form.html.haml b/app/views/spree/admin/variants/_form.html.haml new file mode 100644 index 0000000000..236aa4579e --- /dev/null +++ b/app/views/spree/admin/variants/_form.html.haml @@ -0,0 +1,104 @@ +.label-block.left.six.columns.alpha{'ng-app' => 'admin.products'} + .field + = f.label :display_name, t(:display_name) + = f.text_field :display_name, class: "fullwidth" + .field + = f.label :display_as, t(:display_as) + = f.text_field :display_as, class: "fullwidth" + + - if product_has_variant_unit_option_type?(@product) + - if @product.variant_unit != 'items' + .field{'ng-controller' => 'variantUnitsCtrl'} + = f.label :unit_value, "#{t('admin.'+@product.variant_unit)} ({{unitName(#{@product.variant_unit_scale}, '#{@product.variant_unit}')}})" + = hidden_field_tag 'product_variant_unit_scale', @product.variant_unit_scale + = text_field_tag :unit_value_human, nil, {class: "fullwidth", 'ng-model' => 'unit_value_human', 'ng-change' => 'updateValue()'} + = f.text_field :unit_value, {hidden: true, 'ng-value' => 'unit_value'} + + .field + = f.label :unit_description, t(:spree_admin_unit_description) + = f.text_field :unit_description, class: "fullwidth", placeholder: t('admin.products.unit_name_placeholder') + + %div + - @product.option_types.each do |option_type| + - unless variant_unit_option_type?(option_type) + .field{"data-hook" => "presentation"} + = label :new_variant, option_type.presentation + - if @variant.new_record? + = select(:new_variant, option_type.presentation, option_type.option_values.collect {|ov| [ ov.presentation, ov.id ] }, {}, {class: 'select2 fullwidth'}) + - else + - if opt = @variant.option_values.detect {|o| o.option_type == option_type }.try(:presentation) + = text_field(:new_variant, option_type.presentation, value: opt, disabled: 'disabled', class: 'fullwidth') + .field + = f.label :sku, Spree.t(:sku) + = f.text_field :sku, class: 'fullwidth' + .field + = f.label :price, Spree.t(:price) + = f.text_field :price, value: number_to_currency(@variant.price, unit: ''), class: 'fullwidth' + .field + = f.label :cost_price, Spree.t(:cost_price) + = f.text_field :cost_price, value: number_to_currency(@variant.cost_price, unit: ''), class: 'fullwidth' + + - if Spree::Config[:track_inventory_levels] + .field.checkbox + %label + = f.check_box :on_demand + = t(:on_demand) + %div{'ofn-with-tip' => t('admin.products.variants.to_order_tip')} + %a= t('admin.whats_this') + .field + = f.label :on_hand, t(:on_hand) + .fullwidth + = f.text_field :on_hand + +.right.six.columns.omega.label-block + - if @product.variant_unit != 'weight' + .field{"data-hook" => 'weight'} + = f.label 'weight', t('weight')+' (kg)' + - value = number_with_precision(@variant.weight, precision: 2) + = f.text_field 'weight', value: value, class: 'fullwidth' + + - [:height, :width, :depth].each do |field| + .field + = f.label field, t(field) + - value = number_with_precision(@variant.send(field), precision: 2) + = f.text_field field, value: value, class: 'fullwidth' + +.clear + + +:javascript + angular.element(document.getElementById("new_variant")).ready(function() { + angular.bootstrap(document.getElementById("new_variant"), ['admin.products']); + }); + + $(document).ready(function() { + + var on_demand = $('input#variant_on_demand'); + var on_hand = $('input#variant_on_hand'); + + disableOnHandIfOnDemand = function() { + on_demand_checked = on_demand.attr('checked') + if ( on_demand_checked == undefined ) + on_demand_checked = false; + + on_hand.attr('disabled', on_demand_checked); + if(on_demand_checked) { + on_hand.attr('data-stock', on_hand.val()); + on_hand.val(t('admin.products.variants.infinity')); + } + } + + disableOnHandIfOnDemand(); + + on_demand.change(function(){ + disableOnHandIfOnDemand(); + if(!this.checked) { + if(on_hand.attr('data-stock') !== undefined) { + on_hand.val(on_hand.attr('data-stock')); + } else { + on_hand.val("0"); + } + } + }); + }); + From a11562e4ddc7301129efc9ab5720a05c2988b168 Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Thu, 25 Jul 2019 12:05:50 +0200 Subject: [PATCH 03/10] Fix incorrect indentation in variants table --- app/views/spree/admin/variants/index.html.haml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/views/spree/admin/variants/index.html.haml b/app/views/spree/admin/variants/index.html.haml index a676e92de3..72f35ac13e 100644 --- a/app/views/spree/admin/variants/index.html.haml +++ b/app/views/spree/admin/variants/index.html.haml @@ -21,14 +21,14 @@ %tbody - @variants.each do |variant| %tr{id: spree_dom_id(variant), "data-hook" => "variants_row", class: cycle('odd', 'even'), style: "#{"color:red;" if variant.deleted? }" } - %td.no-border - %span.handle - %td= variant.full_name - %td.align-center= variant.display_price.to_html - %td.align-center= variant.sku - %td.actions - = link_to_edit(variant, no_text: true) unless variant.deleted? - = link_to_delete(variant, no_text: true) unless variant.deleted? + %td.no-border + %span.handle + %td= variant.full_name + %td.align-center= variant.display_price.to_html + %td.align-center= variant.sku + %td.actions + = link_to_edit(variant, no_text: true) unless variant.deleted? + = link_to_delete(variant, no_text: true) unless variant.deleted? - unless @product.has_variants? %tr %td{colspan: "5"}= Spree.t(:none) From ec6f6056a88a99331e4d07441bfd78825ed2a46e Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Thu, 25 Jul 2019 14:34:06 +0200 Subject: [PATCH 04/10] Remove data-hooks --- app/views/spree/admin/variants/_form.html.haml | 4 ++-- app/views/spree/admin/variants/index.html.haml | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/spree/admin/variants/_form.html.haml b/app/views/spree/admin/variants/_form.html.haml index 236aa4579e..6f96acb020 100644 --- a/app/views/spree/admin/variants/_form.html.haml +++ b/app/views/spree/admin/variants/_form.html.haml @@ -21,7 +21,7 @@ %div - @product.option_types.each do |option_type| - unless variant_unit_option_type?(option_type) - .field{"data-hook" => "presentation"} + .field = label :new_variant, option_type.presentation - if @variant.new_record? = select(:new_variant, option_type.presentation, option_type.option_values.collect {|ov| [ ov.presentation, ov.id ] }, {}, {class: 'select2 fullwidth'}) @@ -52,7 +52,7 @@ .right.six.columns.omega.label-block - if @product.variant_unit != 'weight' - .field{"data-hook" => 'weight'} + .field = f.label 'weight', t('weight')+' (kg)' - value = number_with_precision(@variant.weight, precision: 2) = f.text_field 'weight', value: value, class: 'fullwidth' diff --git a/app/views/spree/admin/variants/index.html.haml b/app/views/spree/admin/variants/index.html.haml index 72f35ac13e..d5aa3a499b 100644 --- a/app/views/spree/admin/variants/index.html.haml +++ b/app/views/spree/admin/variants/index.html.haml @@ -12,7 +12,7 @@ %col{style: "width: 20%"}/ %col{style: "width: 15%"}/ %col{style: "width: 15%"}/ - %thead{"data-hook" => "variants_header"} + %thead %tr %th{colspan: "2"}= Spree.t(:options) %th= Spree.t(:price) @@ -20,7 +20,7 @@ %th.actions %tbody - @variants.each do |variant| - %tr{id: spree_dom_id(variant), "data-hook" => "variants_row", class: cycle('odd', 'even'), style: "#{"color:red;" if variant.deleted? }" } + %tr{id: spree_dom_id(variant), class: cycle('odd', 'even'), style: "#{"color:red;" if variant.deleted? }" } %td.no-border %span.handle %td= variant.full_name @@ -39,7 +39,7 @@ \. - if @product.empty_option_values? - %p.first_add_option_types.no-objects-found{"data-hook" => "first_add_option_types"} + %p.first_add_option_types.no-objects-found = Spree.t(:to_add_variants_you_must_first_define) = link_to Spree.t(:option_types), admin_product_url(@product) = Spree.t(:and) @@ -47,8 +47,8 @@ - else - content_for :page_actions do - %ul.inline-menu{"data-hook" => "toolbar"} - %li#new_var_link{"data-hook" => ""} + %ul.inline-menu + %li#new_var_link = link_to_with_icon('icon-plus', Spree.t(:new_variant), new_admin_product_variant_url(@product), remote: true, 'data-update' => 'new_variant', class: 'button') %li= link_to_with_icon('icon-filter', @deleted.blank? ? Spree.t(:show_deleted) : Spree.t(:show_active), admin_product_variants_url(@product, deleted: @deleted.blank? ? "on" : "off"), class: 'button') From 07ccbf7f98dd1fd93b2fe00b39365dd2a32a3b4c Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Wed, 31 Jul 2019 16:55:47 +0200 Subject: [PATCH 05/10] Import variants/edit.html.erb from spree_backend --- app/views/spree/admin/variants/edit.html.erb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 app/views/spree/admin/variants/edit.html.erb diff --git a/app/views/spree/admin/variants/edit.html.erb b/app/views/spree/admin/variants/edit.html.erb new file mode 100644 index 0000000000..b4466bc6c5 --- /dev/null +++ b/app/views/spree/admin/variants/edit.html.erb @@ -0,0 +1,15 @@ +<%= render :partial => 'spree/admin/shared/product_sub_menu' %> + +<%= render :partial => 'spree/admin/shared/product_tabs', :locals => { :current => 'Variants' } %> + +<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @variant } %> + +<%= form_for [:admin, @product, @variant] do |f| %> +
+
+ <%= render :partial => 'form', :locals => { :f => f } %> +
+ + <%= render :partial => 'spree/admin/shared/edit_resource_links' %> +
+<% end %> From f3b1a5dd352121bc8a5fcefc00b5d55fdcf05a31 Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Wed, 31 Jul 2019 16:59:26 +0200 Subject: [PATCH 06/10] Convert variants/edit from erb to haml --- app/views/spree/admin/variants/edit.html.erb | 15 --------------- app/views/spree/admin/variants/edit.html.haml | 11 +++++++++++ 2 files changed, 11 insertions(+), 15 deletions(-) delete mode 100644 app/views/spree/admin/variants/edit.html.erb create mode 100644 app/views/spree/admin/variants/edit.html.haml diff --git a/app/views/spree/admin/variants/edit.html.erb b/app/views/spree/admin/variants/edit.html.erb deleted file mode 100644 index b4466bc6c5..0000000000 --- a/app/views/spree/admin/variants/edit.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -<%= render :partial => 'spree/admin/shared/product_sub_menu' %> - -<%= render :partial => 'spree/admin/shared/product_tabs', :locals => { :current => 'Variants' } %> - -<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @variant } %> - -<%= form_for [:admin, @product, @variant] do |f| %> -
-
- <%= render :partial => 'form', :locals => { :f => f } %> -
- - <%= render :partial => 'spree/admin/shared/edit_resource_links' %> -
-<% end %> diff --git a/app/views/spree/admin/variants/edit.html.haml b/app/views/spree/admin/variants/edit.html.haml new file mode 100644 index 0000000000..057c8a9d10 --- /dev/null +++ b/app/views/spree/admin/variants/edit.html.haml @@ -0,0 +1,11 @@ += render partial: 'spree/admin/shared/product_sub_menu' + += render partial: 'spree/admin/shared/product_tabs', locals: { current: 'Variants' } + += render partial: 'spree/shared/error_messages', locals: { target: @variant } + += form_for [:admin, @product, @variant] do |f| + %fieldset.no-border-top + %div + = render partial: 'form', locals: { f: f } + = render partial: 'spree/admin/shared/edit_resource_links' From 5faf33fabea6b4d3067d85f309910b8629c14124 Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Thu, 1 Aug 2019 10:50:13 +0200 Subject: [PATCH 07/10] Import variants/new.html.erb from spree_backend --- app/views/spree/admin/variants/new.html.erb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 app/views/spree/admin/variants/new.html.erb diff --git a/app/views/spree/admin/variants/new.html.erb b/app/views/spree/admin/variants/new.html.erb new file mode 100644 index 0000000000..875fdfa0b1 --- /dev/null +++ b/app/views/spree/admin/variants/new.html.erb @@ -0,0 +1,9 @@ +<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @variant } %> + +<%= form_for [:admin, @product, @variant] do |f| %> +
+ <%= Spree.t(:new_variant) %> + <%= render :partial => 'form', :locals => { :f => f } %> + <%= render :partial => 'spree/admin/shared/new_resource_links' %> +
+<% end %> From 60bdde634932cd7e42a1749f6ca62c042dd4d2e2 Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Thu, 1 Aug 2019 11:23:44 +0200 Subject: [PATCH 08/10] Convert variants/new from erb to haml and import new.js.erb --- app/views/spree/admin/variants/new.html.erb | 9 --------- app/views/spree/admin/variants/new.html.haml | 7 +++++++ app/views/spree/admin/variants/new.js.erb | 3 +++ 3 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 app/views/spree/admin/variants/new.html.erb create mode 100644 app/views/spree/admin/variants/new.html.haml create mode 100644 app/views/spree/admin/variants/new.js.erb diff --git a/app/views/spree/admin/variants/new.html.erb b/app/views/spree/admin/variants/new.html.erb deleted file mode 100644 index 875fdfa0b1..0000000000 --- a/app/views/spree/admin/variants/new.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @variant } %> - -<%= form_for [:admin, @product, @variant] do |f| %> -
- <%= Spree.t(:new_variant) %> - <%= render :partial => 'form', :locals => { :f => f } %> - <%= render :partial => 'spree/admin/shared/new_resource_links' %> -
-<% end %> diff --git a/app/views/spree/admin/variants/new.html.haml b/app/views/spree/admin/variants/new.html.haml new file mode 100644 index 0000000000..9e9c6827e8 --- /dev/null +++ b/app/views/spree/admin/variants/new.html.haml @@ -0,0 +1,7 @@ += render partial: 'spree/shared/error_messages', locals: { target: @variant } + += form_for [:admin, @product, @variant] do |f| + %fieldset{'data-hook' => "admin_variant_new_form"} + %legend{align: "center"}= Spree.t(:new_variant) + = render partial: 'form', locals: { f: f } + = render partial: 'spree/admin/shared/new_resource_links' diff --git a/app/views/spree/admin/variants/new.js.erb b/app/views/spree/admin/variants/new.js.erb new file mode 100644 index 0000000000..9ddfd69970 --- /dev/null +++ b/app/views/spree/admin/variants/new.js.erb @@ -0,0 +1,3 @@ +$("#new_variant").html('<%= escape_javascript(render template: 'spree/admin/variants/new', formats: [:html], handlers: [:erb]) %>'); +$(".select2").select2(); +$("#new_var_link").hide(); From bf2c1a0c1deffa84f3e33cd1bbab6ac795df630c Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Fri, 9 Aug 2019 14:34:23 +0200 Subject: [PATCH 09/10] Add ng directive for setting on demand --- .../set_variant_on_demand.js.coffee | 21 +++++++ .../spree/admin/variants/_form.html.haml | 59 ++++--------------- 2 files changed, 32 insertions(+), 48 deletions(-) create mode 100644 app/assets/javascripts/admin/products/directives/set_variant_on_demand.js.coffee diff --git a/app/assets/javascripts/admin/products/directives/set_variant_on_demand.js.coffee b/app/assets/javascripts/admin/products/directives/set_variant_on_demand.js.coffee new file mode 100644 index 0000000000..8cbd03b4d0 --- /dev/null +++ b/app/assets/javascripts/admin/products/directives/set_variant_on_demand.js.coffee @@ -0,0 +1,21 @@ +angular.module("admin.products").directive "setOnDemand", -> + link: (scope, element, attr) -> + onHand = element.context.querySelector("#variant_on_hand") + onDemand = element.context.querySelector("#variant_on_demand") + + if onDemand.checked + onHand.disabled = 'disabled' + onHand.dataStock = onHand.value + onHand.value = t('admin.products.variants.infinity') + + onDemand.addEventListener 'change', (event) -> + if onDemand.checked + onHand.disabled = 'disabled' + onHand.dataStock = onHand.value + onHand.value = t('admin.products.variants.infinity') + else + onHand.removeAttribute('disabled') + onHand.value = onHand.dataStock + + + diff --git a/app/views/spree/admin/variants/_form.html.haml b/app/views/spree/admin/variants/_form.html.haml index 6f96acb020..00c4b01bfe 100644 --- a/app/views/spree/admin/variants/_form.html.haml +++ b/app/views/spree/admin/variants/_form.html.haml @@ -39,16 +39,17 @@ = f.text_field :cost_price, value: number_to_currency(@variant.cost_price, unit: ''), class: 'fullwidth' - if Spree::Config[:track_inventory_levels] - .field.checkbox - %label - = f.check_box :on_demand - = t(:on_demand) - %div{'ofn-with-tip' => t('admin.products.variants.to_order_tip')} - %a= t('admin.whats_this') - .field - = f.label :on_hand, t(:on_hand) - .fullwidth - = f.text_field :on_hand + %div{ 'set-on-demand' => '' } + .field.checkbox + %label + = f.check_box :on_demand + = t(:on_demand) + %div{'ofn-with-tip' => t('admin.products.variants.to_order_tip')} + %a= t('admin.whats_this') + .field + = f.label :on_hand, t(:on_hand) + .fullwidth + = f.text_field :on_hand .right.six.columns.omega.label-block - if @product.variant_unit != 'weight' @@ -64,41 +65,3 @@ = f.text_field field, value: value, class: 'fullwidth' .clear - - -:javascript - angular.element(document.getElementById("new_variant")).ready(function() { - angular.bootstrap(document.getElementById("new_variant"), ['admin.products']); - }); - - $(document).ready(function() { - - var on_demand = $('input#variant_on_demand'); - var on_hand = $('input#variant_on_hand'); - - disableOnHandIfOnDemand = function() { - on_demand_checked = on_demand.attr('checked') - if ( on_demand_checked == undefined ) - on_demand_checked = false; - - on_hand.attr('disabled', on_demand_checked); - if(on_demand_checked) { - on_hand.attr('data-stock', on_hand.val()); - on_hand.val(t('admin.products.variants.infinity')); - } - } - - disableOnHandIfOnDemand(); - - on_demand.change(function(){ - disableOnHandIfOnDemand(); - if(!this.checked) { - if(on_hand.attr('data-stock') !== undefined) { - on_hand.val(on_hand.attr('data-stock')); - } else { - on_hand.val("0"); - } - } - }); - }); - From 1217811402c7a4d36b2ceca29a8c629929bcfbe1 Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Tue, 13 Aug 2019 11:03:04 +0200 Subject: [PATCH 10/10] Refactor and remove empty lines --- .../directives/set_variant_on_demand.js.coffee | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/admin/products/directives/set_variant_on_demand.js.coffee b/app/assets/javascripts/admin/products/directives/set_variant_on_demand.js.coffee index 8cbd03b4d0..d554a194a4 100644 --- a/app/assets/javascripts/admin/products/directives/set_variant_on_demand.js.coffee +++ b/app/assets/javascripts/admin/products/directives/set_variant_on_demand.js.coffee @@ -3,19 +3,17 @@ angular.module("admin.products").directive "setOnDemand", -> onHand = element.context.querySelector("#variant_on_hand") onDemand = element.context.querySelector("#variant_on_demand") - if onDemand.checked - onHand.disabled = 'disabled' - onHand.dataStock = onHand.value - onHand.value = t('admin.products.variants.infinity') - - onDemand.addEventListener 'change', (event) -> + disableOnHandIfOnDemand = -> if onDemand.checked onHand.disabled = 'disabled' onHand.dataStock = onHand.value onHand.value = t('admin.products.variants.infinity') - else + + disableOnHandIfOnDemand() + + onDemand.addEventListener 'change', (event) -> + disableOnHandIfOnDemand() + + if !onDemand.checked onHand.removeAttribute('disabled') onHand.value = onHand.dataStock - - -