From 986837d60126b93c7a76ddb35e405bac5aeabd86 Mon Sep 17 00:00:00 2001 From: Hugo Daniel Date: Thu, 25 Jul 2019 11:07:35 +0200 Subject: [PATCH] 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"); + } + } + }); + }); +