From 7cdfb4bab22ac927dfe16be6c100c74a69e2890e Mon Sep 17 00:00:00 2001 From: Rob H Date: Thu, 15 May 2014 14:52:19 +1000 Subject: [PATCH] Add methods and fees to sidebar on enterprise edit page --- .../stylesheets/admin/sidebar-item.css.sass | 63 +++++++++++++++++++ .../admin/enterprises_controller.rb | 7 +++ .../admin/enterprise_fees/index.html.haml | 1 + app/views/admin/enterprises/_form.html.haml | 28 ++++----- .../admin/enterprises/_sidebar.html.haml | 59 +++++++++++++++++ app/views/admin/enterprises/edit.html.erb | 6 -- app/views/admin/enterprises/edit.html.haml | 13 ++++ app/views/admin/enterprises/new.html.erb | 7 --- app/views/admin/enterprises/new.html.haml | 13 ++++ spec/features/admin/enterprises_spec.rb | 24 +++++++ 10 files changed, 194 insertions(+), 27 deletions(-) create mode 100644 app/assets/stylesheets/admin/sidebar-item.css.sass create mode 100644 app/views/admin/enterprises/_sidebar.html.haml delete mode 100644 app/views/admin/enterprises/edit.html.erb create mode 100644 app/views/admin/enterprises/edit.html.haml delete mode 100644 app/views/admin/enterprises/new.html.erb create mode 100644 app/views/admin/enterprises/new.html.haml diff --git a/app/assets/stylesheets/admin/sidebar-item.css.sass b/app/assets/stylesheets/admin/sidebar-item.css.sass new file mode 100644 index 0000000000..73a0b349a3 --- /dev/null +++ b/app/assets/stylesheets/admin/sidebar-item.css.sass @@ -0,0 +1,63 @@ +div.sidebar_item + margin-bottom: 30px + + .centered + text-align: center + + div.header + font-size: 105% + color: #fff + padding: 10px 0px + position: relative + &.blue + background-color: #5498da + &.red + background-color: #DA5354 + + .list + //max-height: 150px + overflow-y: auto + + .list-item + border: solid #5498da + border-width: 0px 1px 0px 1px + span.alpha + font-weight: bold + margin-left: -3px + padding: 10px 2px 10px 5% + overflow: hidden + max-width: 160px + text-overflow: ellipsis + span.omega + padding: 8px 13px 8px 0px + margin-right: -3px + text-align: right + .icon-remove-sign + color: #DA5354 + font-size: 18px + &.red + color: #DA5354 + border: solid #DA5354 + border-width: 0px 3px 0px 3px + &.even + background-color: #fff + &.odd + background-color: #eff5fc + &.even, &.odd + &:hover + color: #ffffff + background-color: #9fc820 + + a.button + color: #fff + padding: 15px 15px + font-weight: bold + text-align: center + border-radius: 0px + &.blue + background-color: #5498da + &.red + background-color: #DA5354 + &:hover + background-color: #9fc820 + \ No newline at end of file diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 023a8afddb..5f4d64a99f 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -2,6 +2,7 @@ module Admin class EnterprisesController < ResourceController before_filter :load_enterprise_set, :only => :index before_filter :load_countries, :except => :index + before_filter :load_methods_and_fees, :only => [:new, :edit] create.after :grant_management helper 'spree/products' @@ -41,5 +42,11 @@ module Admin def collection_actions [:index, :bulk_update] end + + def load_methods_and_fees + @payment_methods = Spree::PaymentMethod.managed_by(spree_current_user).sort_by!{ |pm| [(@enterprise.payment_methods.include? pm) ? 0 : 1, pm.name] } + @shipping_methods = Spree::ShippingMethod.managed_by(spree_current_user).sort_by!{ |sm| [(@enterprise.shipping_methods.include? sm) ? 0 : 1, sm.name] } + @enterprise_fees = EnterpriseFee.managed_by(spree_current_user).for_enterprise(@enterprise).order(:fee_type, :name).all + end end end diff --git a/app/views/admin/enterprise_fees/index.html.haml b/app/views/admin/enterprise_fees/index.html.haml index d3e9a0b88c..b254f03698 100644 --- a/app/views/admin/enterprise_fees/index.html.haml +++ b/app/views/admin/enterprise_fees/index.html.haml @@ -21,6 +21,7 @@ %th Calculator values %th.actions %tbody + - binding.pry = enterprise_fee_set_form.ng_fields_for :collection do |f| %tr{'ng-repeat' => 'enterprise_fee in enterprise_fees | filter:query'} %td diff --git a/app/views/admin/enterprises/_form.html.haml b/app/views/admin/enterprises/_form.html.haml index ff5b995af0..fcb53b66f2 100644 --- a/app/views/admin/enterprises/_form.html.haml +++ b/app/views/admin/enterprises/_form.html.haml @@ -1,9 +1,6 @@ - content_for :head do = render 'shared/cms_elrte_head' -- content_for :page_title do - New Enterprise - - content_for :page_actions do %li= button_link_to "Back to enterprises list", main_app.admin_enterprises_path, icon: 'icon-arrow-left' @@ -39,7 +36,7 @@ = f.label :visible, 'Visible in search?' = f.fields_for :address do |af| - %fieldset.no-border-bottom + %fieldset.twelve.columns.alpha.no-border-bottom %legend Address .row .alpha.six.columns @@ -64,13 +61,16 @@ .omega.four.columns = af.text_field :zipcode .row - .alpha.two.columns   - .omega.three.columns - = af.collection_select(:state_id, af.object.country.states, :id, :name) - .row - .alpha.two.columns   - .omega.three.columns - = af.collection_select(:country_id, available_countries, :id, :name) + .six.columns.alpha + .alpha.two.columns + = af.label :state_id, 'State' + .omega.four.columns + = af.collection_select :state_id, af.object.country.states, :id, :name, {}, :class => "select2 fullwidth" + .six.columns.omega + .alpha.two.columns + = af.label :countryid, 'Country' + .four.columns.omega + = af.collection_select :country_id, available_countries, :id, :name, {}, :class => "select2 fullwidth" .row .alpha.six.columns %fieldset.no-border-bottom @@ -119,7 +119,7 @@ = f.label :twitter .omega.four.columns = f.text_field :twitter - %fieldset.no-border-bottom + %fieldset.twelve.columns.alpha.no-border-bottom %legend About Us .row .alpha.two.columns @@ -131,7 +131,7 @@ = f.label :long_description, 'About Us' %br Tell us about yourself. This information appears on your public profile (under "About Us") - .omega.eight.columns + .omega.ten.columns = f.text_area :long_description, class: 'rich_text', placeholder: 'Tell us about yourself. This information appears on your public profile (under "About Us")' .row .alpha.two.columns @@ -140,7 +140,7 @@ %em (Hub only) %br Explain your distribution offer/s - this information appears on your public profile (under "How does it work?") - .omega.eight.columns + .omega.ten.columns = f.text_area :distributor_info, class: 'rich_text', placeholder: 'Hub only: Explain your distribution offer/s - this is more detailed information that the user can access by clicking on "How does it work?"' / TODO: editor breaks scrolling with arrow keys .row diff --git a/app/views/admin/enterprises/_sidebar.html.haml b/app/views/admin/enterprises/_sidebar.html.haml new file mode 100644 index 0000000000..578612ec6f --- /dev/null +++ b/app/views/admin/enterprises/_sidebar.html.haml @@ -0,0 +1,59 @@ +.sidebar_item.four.columns.alpha#payment_methods + .four.columns.alpha.header{ class: "#{@payment_methods.count > 0 ? "blue" : "red"}" } + %span.four.columns.alpha.centered Payment Methods + - if @payment_methods.count > 0 + .four.columns.alpha.list + - @payment_methods.each do |payment_method| + %a.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{edit_admin_payment_method_path(payment_method)}" } + %span.three.columns.alpha + = payment_method.name + %span.one.column.omega + = f.check_box :payment_method_ids, { :multiple => true }, payment_method.id, nil + - else + .four.columns.alpha.list-item.red + %span.three.columns.alpha None Available + %span.one.column.omega + %span.icon-remove-sign + %a.four.columns.alpha.button{ href: "#{new_admin_payment_method_path}", class: "#{@payment_methods.count > 0 ? "blue" : "red"}" } + CREATE NEW + %span.icon-arrow-right + +.sidebar_item.four.columns.alpha#shipping_methods + .four.columns.alpha.header{ class: "#{@shipping_methods.count > 0 ? "blue" : "red"}" } + %span.four.columns.alpha.centered Shipping Methods + - if @shipping_methods.count > 0 + .four.columns.alpha.list + - @shipping_methods.each do |shipping_method| + %a.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{edit_admin_shipping_method_path(shipping_method)}" } + %span.three.columns.alpha + = shipping_method.name + %span.one.column.omega + = f.check_box :shipping_method_ids, { :multiple => true }, shipping_method.id, nil + - else + .four.columns.alpha.list-item.red + %span.three.columns.alpha None Available + %span.one.column.omega + %span.icon-remove-sign + %a.four.columns.alpha.button{ href: "#{new_admin_shipping_method_path}", class: "#{@payment_methods.count > 0 ? "blue" : "red"}" } + CREATE NEW + %span.icon-arrow-right + +.sidebar_item.four.columns.alpha#enterprise_fees + .four.columns.alpha.header{ class: "#{@enterprise_fees.count > 0 ? "blue" : "red"}" } + %span.four.columns.alpha.centered Enterprise Fees + - if @enterprise_fees.count > 0 + .four.columns.alpha.list + - @enterprise_fees.each do |enterprise_fee| + %a.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.admin_enterprise_fees_path}" } + %span.three.columns.alpha + = enterprise_fee.name + %span.one.column.omega +   + - else + .four.columns.alpha.list-item.red + %span.three.columns.alpha None Available + %span.one.column.omega + %span.icon-remove-sign + %a.four.columns.alpha.button{ href: "#{main_app.admin_enterprise_fees_path}", class: "#{@enterprise_fees.count > 0 ? "blue" : "red"}" } + CREATE NEW + %span.icon-arrow-right \ No newline at end of file diff --git a/app/views/admin/enterprises/edit.html.erb b/app/views/admin/enterprises/edit.html.erb deleted file mode 100644 index f4302f4ef9..0000000000 --- a/app/views/admin/enterprises/edit.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @enterprise } %> - -<%= form_for [main_app, :admin, @enterprise] do |f| %> - <%= render :partial => 'form', :locals => { :f => f } %> - <%= render :partial => 'spree/admin/shared/edit_resource_links' %> -<% end %> diff --git a/app/views/admin/enterprises/edit.html.haml b/app/views/admin/enterprises/edit.html.haml new file mode 100644 index 0000000000..7ca168b2c4 --- /dev/null +++ b/app/views/admin/enterprises/edit.html.haml @@ -0,0 +1,13 @@ += render :partial => 'spree/shared/error_messages', :locals => { :target => @enterprise } + +- content_for :page_title do + Editing: + = @enterprise.name + += form_for [main_app, :admin, @enterprise] do |f| + .twelve.columns.alpha + = render :partial => 'form', :locals => { :f => f } + .four.columns.omega + = render :partial => 'sidebar', :locals => { :f => f } + .twelve.columns.alpha + = render :partial => 'spree/admin/shared/edit_resource_links' diff --git a/app/views/admin/enterprises/new.html.erb b/app/views/admin/enterprises/new.html.erb deleted file mode 100644 index 890c6009cd..0000000000 --- a/app/views/admin/enterprises/new.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @enterprise } %> - -<%= form_for [main_app, :admin, @enterprise] do |f| %> - <%= render :partial => 'form', :locals => { :f => f } %> - - <%= render :partial => 'spree/admin/shared/new_resource_links' %> -<% end %> diff --git a/app/views/admin/enterprises/new.html.haml b/app/views/admin/enterprises/new.html.haml new file mode 100644 index 0000000000..4d1ae72c8e --- /dev/null +++ b/app/views/admin/enterprises/new.html.haml @@ -0,0 +1,13 @@ += render :partial => 'spree/shared/error_messages', :locals => { :target => @enterprise } + +- content_for :page_title do + New Enterprise + += form_for [main_app, :admin, @enterprise] do |f| + .twelve.columns.alpha + = render :partial => 'form', :locals => { :f => f } + .four.columns.omega + = render :partial => 'sidebar', :locals => { :f => f } + .twelve.columns.alpha + -# Save, Save & Close and Cancel button + = render :partial => 'spree/admin/shared/new_resource_links' diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index cf177b4be9..f6d5e32fec 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -46,6 +46,9 @@ feature %q{ scenario "creating a new enterprise" do eg1 = create(:enterprise_group, name: 'eg1') eg2 = create(:enterprise_group, name: 'eg2') + payment_method = create(:payment_method) + shipping_method = create(:shipping_method) + enterprise_fee = create(:enterprise_fee) login_to_admin_section @@ -62,6 +65,12 @@ feature %q{ select eg1.name, from: 'enterprise_group_ids' + page.should_not have_checked_field "enterprise_payment_method_ids_#{payment_method.id}" + page.should_not have_checked_field "enterprise_shipping_method_ids_#{shipping_method.id}" + + check "enterprise_payment_method_ids_#{payment_method.id}" + check "enterprise_shipping_method_ids_#{shipping_method.id}" + fill_in 'enterprise_contact', :with => 'Kirsten or Ren' fill_in 'enterprise_phone', :with => '0413 897 321' fill_in 'enterprise_email', :with => 'info@eaterprises.com.au' @@ -84,6 +93,9 @@ feature %q{ @enterprise = create(:enterprise) eg1 = create(:enterprise_group, name: 'eg1') eg2 = create(:enterprise_group, name: 'eg2') + payment_method = create(:payment_method, distributors: []) + shipping_method = create(:shipping_method, distributors: []) + enterprise_fee = create(:enterprise_fee, enterprise: @enterprise ) login_to_admin_section @@ -99,6 +111,12 @@ feature %q{ select eg1.name, from: 'enterprise_group_ids' + page.should_not have_checked_field "enterprise_payment_method_ids_#{payment_method.id}" + page.should_not have_checked_field "enterprise_shipping_method_ids_#{shipping_method.id}" + + check "enterprise_payment_method_ids_#{payment_method.id}" + check "enterprise_shipping_method_ids_#{shipping_method.id}" + fill_in 'enterprise_contact', :with => 'Kirsten or Ren' fill_in 'enterprise_phone', :with => '0413 897 321' fill_in 'enterprise_email', :with => 'info@eaterprises.com.au' @@ -117,6 +135,12 @@ feature %q{ flash_message.should == 'Enterprise "Eaterprises" has been successfully updated!' page.should have_selector '#listing_enterprises a', text: 'Eaterprises' + + click_link 'Edit Profile' + + page.should have_checked_field "enterprise_payment_method_ids_#{payment_method.id}" + page.should have_checked_field "enterprise_shipping_method_ids_#{shipping_method.id}" + page.should have_selector "a.list-item", text: enterprise_fee.name end context 'as an Enterprise user' do