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..d554a194a4 --- /dev/null +++ b/app/assets/javascripts/admin/products/directives/set_variant_on_demand.js.coffee @@ -0,0 +1,19 @@ +angular.module("admin.products").directive "setOnDemand", -> + link: (scope, element, attr) -> + onHand = element.context.querySelector("#variant_on_hand") + onDemand = element.context.querySelector("#variant_on_demand") + + disableOnHandIfOnDemand = -> + if onDemand.checked + onHand.disabled = 'disabled' + onHand.dataStock = onHand.value + onHand.value = t('admin.products.variants.infinity') + + disableOnHandIfOnDemand() + + onDemand.addEventListener 'change', (event) -> + disableOnHandIfOnDemand() + + if !onDemand.checked + onHand.removeAttribute('disabled') + onHand.value = onHand.dataStock 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/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/_form.html.haml b/app/views/spree/admin/variants/_form.html.haml new file mode 100644 index 0000000000..00c4b01bfe --- /dev/null +++ b/app/views/spree/admin/variants/_form.html.haml @@ -0,0 +1,67 @@ +.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 + = 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] + %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' + .field + = 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 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' 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..d5aa3a499b --- /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 + %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), 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 + = 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 + %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') 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();