From e6a51bb49d1a1715316d48e75f416804c02950b5 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 11 Dec 2015 22:20:59 +1100 Subject: [PATCH] Adding actions dropdown to admin order view/pages --- .../directives/links_dropdown.js.coffee | 5 ++++ .../admin/dropdown/dropdown.js.coffee | 2 +- .../templates/admin/links_dropdown.html.haml | 10 ++++++++ .../admin/openfoodnetwork.css.scss | 12 ++++++++- .../spree/admin/orders_helper_decorator.rb | 25 +++++++++++++++++++ .../edit/add_action_dropdown.html.haml.deface | 6 +++++ .../edit/add_invoice_button.html.haml.deface | 6 ----- .../edit/add_ship_button.html.haml.deface | 3 --- .../show/add_action_dropdown.html.haml.deface | 6 +++++ .../show/add_print_button.html.haml.deface | 3 --- config/locales/en.yml | 9 ++++++- spec/features/admin/orders_spec.rb | 19 ++++++++++++++ 12 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 app/assets/javascripts/admin/dropdown/directives/links_dropdown.js.coffee create mode 100644 app/assets/javascripts/templates/admin/links_dropdown.html.haml create mode 100644 app/helpers/spree/admin/orders_helper_decorator.rb create mode 100644 app/overrides/spree/admin/orders/edit/add_action_dropdown.html.haml.deface delete mode 100644 app/overrides/spree/admin/orders/edit/add_invoice_button.html.haml.deface delete mode 100644 app/overrides/spree/admin/orders/edit/add_ship_button.html.haml.deface create mode 100644 app/overrides/spree/admin/orders/show/add_action_dropdown.html.haml.deface delete mode 100644 app/overrides/spree/admin/orders/show/add_print_button.html.haml.deface diff --git a/app/assets/javascripts/admin/dropdown/directives/links_dropdown.js.coffee b/app/assets/javascripts/admin/dropdown/directives/links_dropdown.js.coffee new file mode 100644 index 0000000000..a58688a542 --- /dev/null +++ b/app/assets/javascripts/admin/dropdown/directives/links_dropdown.js.coffee @@ -0,0 +1,5 @@ + angular.module("admin.dropdown").directive "linksDropdown", ($window)-> + restrict: "C" + scope: + links: "=" + templateUrl: "admin/links_dropdown.html" diff --git a/app/assets/javascripts/admin/dropdown/dropdown.js.coffee b/app/assets/javascripts/admin/dropdown/dropdown.js.coffee index ae6118390f..b9c28652f0 100644 --- a/app/assets/javascripts/admin/dropdown/dropdown.js.coffee +++ b/app/assets/javascripts/admin/dropdown/dropdown.js.coffee @@ -1 +1 @@ -angular.module("admin.dropdown", []) +angular.module("admin.dropdown", ['templates']) diff --git a/app/assets/javascripts/templates/admin/links_dropdown.html.haml b/app/assets/javascripts/templates/admin/links_dropdown.html.haml new file mode 100644 index 0000000000..4f85ed1319 --- /dev/null +++ b/app/assets/javascripts/templates/admin/links_dropdown.html.haml @@ -0,0 +1,10 @@ +.ofn_drop_down{ "ofn-drop-down" => true } + %span + %i.icon-check + Actions + %i{ 'ng-class' => "expanded && 'icon-caret-up' || !expanded && 'icon-caret-down'" } + %div.menu{ 'ng-show' => "expanded", style: 'width: 200px' } + %a.menu_item{ 'ng-repeat' => "link in links", href: '{{link.url}}', target: "{{link.target || '_self'}}", data: { method: "{{ link.method || 'get' }}", confirm: "{{link.confirm}}" }, style: 'display: inline-block; width: 100%' } + %span{ :style => 'text-align: center; display: inline-block; width: 20%'} + %i{ ng: { class: "link.icon" } } + %span{ style: "display: inline-block; width: auto"} {{ link.name }} diff --git a/app/assets/stylesheets/admin/openfoodnetwork.css.scss b/app/assets/stylesheets/admin/openfoodnetwork.css.scss index 083c657b94..c43b4098e7 100644 --- a/app/assets/stylesheets/admin/openfoodnetwork.css.scss +++ b/app/assets/stylesheets/admin/openfoodnetwork.css.scss @@ -180,8 +180,16 @@ table#listing_enterprise_groups { } } +#content-header .ofn_drop_down { + border: none; + background-color: #5498da; + color: #fff; + float: none; + margin-left: 3px; +} + .ofn_drop_down { - padding: 7px 15px; + padding: 6px 15px; border-radius: 3px; border: 1px solid #d4d4d4; background-color: #f5f5f5; @@ -198,6 +206,7 @@ table#listing_enterprise_groups { text-align: center; > span { + width: auto; text-transform: uppercase; font-size: 85%; font-weight: 600; @@ -213,6 +222,7 @@ table#listing_enterprise_groups { border: 1px solid #adadad; background-color: #ffffff; box-shadow: 1px 3px 10px #888888; + z-index: 100; .menu_item { margin: 0px; diff --git a/app/helpers/spree/admin/orders_helper_decorator.rb b/app/helpers/spree/admin/orders_helper_decorator.rb new file mode 100644 index 0000000000..23443cc400 --- /dev/null +++ b/app/helpers/spree/admin/orders_helper_decorator.rb @@ -0,0 +1,25 @@ +module Spree + module Admin + module OrdersHelper + def order_links(order) + links = [] + links << { name: t(:view_order), url: admin_order_path(order), icon: 'icon-eye-open' } unless action_name == "show" + links << { name: t(:edit_order), url: edit_admin_order_path(order), icon: 'icon-edit' } unless action_name == "edit" + if @order.complete? + links << { name: t(:resend_confirmation), url: resend_admin_order_path(order), icon: 'icon-email', method: 'post', confirm: t(:confirm_resend_order_confirmation) } + if @order.distributor.can_invoice? + links << { name: t(:send_invoice), url: invoice_admin_order_path(order), icon: 'icon-email', confirm: t(:confirm_send_invoice) } + else + links << { name: t(:send_invoice), url: "#", icon: 'icon-email', confirm: t(:must_have_valid_business_number, enterprise_name: order.distributor.name) } + end + links << { name: t(:print_invoice), url: print_admin_order_path(order), icon: 'icon-print', target: "_blank" } + end + if @order.ready_to_ship? + links << { name: t(:ship_order), url: fire_admin_order_path(@order, :e => 'ship'), method: 'put', icon: 'icon-truck', confirm: t(:are_you_sure) } + end + links << { name: t(:cancel_order), url: fire_admin_order_path(@order.number, { :e => 'cancel' }), icon: 'icon-trash', confirm: t(:are_you_sure) } if order.can_cancel? + links + end + end + end +end diff --git a/app/overrides/spree/admin/orders/edit/add_action_dropdown.html.haml.deface b/app/overrides/spree/admin/orders/edit/add_action_dropdown.html.haml.deface new file mode 100644 index 0000000000..58b13a3b32 --- /dev/null +++ b/app/overrides/spree/admin/orders/edit/add_action_dropdown.html.haml.deface @@ -0,0 +1,6 @@ +/ insert_after "code[erb-loud]:contains('button_link_to t(:resend)')" + +%li.links-dropdown#links-dropdown{ links: order_links(@order).to_json } + +:coffee + angular.bootstrap(document.getElementById("links-dropdown"),['admin.dropdown']) diff --git a/app/overrides/spree/admin/orders/edit/add_invoice_button.html.haml.deface b/app/overrides/spree/admin/orders/edit/add_invoice_button.html.haml.deface deleted file mode 100644 index 11b4334cfc..0000000000 --- a/app/overrides/spree/admin/orders/edit/add_invoice_button.html.haml.deface +++ /dev/null @@ -1,6 +0,0 @@ -/ insert_after "code[erb-loud]:contains('button_link_to t(:resend)')" -- if @order.complete? - - if @order.distributor.can_invoice? - %li= button_link_to t(:invoice), invoice_admin_order_url(@order), :icon => 'icon-email', :data => { :confirm => t(:confirm_send_invoice) } - - else - %li= button_link_to t(:invoice), "#", :icon => 'icon-email', :data => { :confirm => t(:must_have_valid_business_number, enterprise_name: @order.distributor.name) } diff --git a/app/overrides/spree/admin/orders/edit/add_ship_button.html.haml.deface b/app/overrides/spree/admin/orders/edit/add_ship_button.html.haml.deface deleted file mode 100644 index 47fbdea70a..0000000000 --- a/app/overrides/spree/admin/orders/edit/add_ship_button.html.haml.deface +++ /dev/null @@ -1,3 +0,0 @@ -/ insert_before "code[erb-loud]:contains('button_link_to t(:resend)')" -- if @order.ready_to_ship? - %li= button_link_to t(:ship), fire_admin_order_url(@order, :e => 'ship'), :method => :put, :data => { :confirm => t(:are_you_sure) } diff --git a/app/overrides/spree/admin/orders/show/add_action_dropdown.html.haml.deface b/app/overrides/spree/admin/orders/show/add_action_dropdown.html.haml.deface new file mode 100644 index 0000000000..8c2ed40c26 --- /dev/null +++ b/app/overrides/spree/admin/orders/show/add_action_dropdown.html.haml.deface @@ -0,0 +1,6 @@ +/ insert_after "code[erb-loud]:contains('button_link_to t(:edit)')" + +%li.links-dropdown#links-dropdown{ links: order_links(@order).to_json } + +:coffee + angular.bootstrap(document.getElementById("links-dropdown"),['admin.dropdown']) diff --git a/app/overrides/spree/admin/orders/show/add_print_button.html.haml.deface b/app/overrides/spree/admin/orders/show/add_print_button.html.haml.deface deleted file mode 100644 index e48ad372e9..0000000000 --- a/app/overrides/spree/admin/orders/show/add_print_button.html.haml.deface +++ /dev/null @@ -1,3 +0,0 @@ -/ insert_after "code[erb-loud]:contains('button_link_to t(:edit)')" -- if @order.complete? - %li= button_link_to t(:print), print_admin_order_url(@order), :method => :get, :icon => 'icon-print', :target => "_blank" diff --git a/config/locales/en.yml b/config/locales/en.yml index ec2c6382ad..368ae4b273 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -20,8 +20,15 @@ en: producers: Aussie Producers producers_join: Australian producers are now welcome to join the Open Food Network. charges_sales_tax: Charges GST? - print: "Print" + print_invoice: "Print Invoice" + send_invoice: "Send Invoice" + resend_confirmation: "Resend Confirmation" + view_order: "View Order" + edit_order: "Edit Order" + ship_order: "Ship Order" + cancel_order: "Cancel Order" confirm_send_invoice: "An invoice for this order will be sent to the customer. Are you sure you want to continue?" + confirm_resend_order_confirmation: "Are you sure you want to resend the order confirmation email?" must_have_valid_business_number: "%{enterprise_name} must have a valid ABN before invoices can be sent." # Printable Invoice Columns diff --git a/spec/features/admin/orders_spec.rb b/spec/features/admin/orders_spec.rb index 29afad24d2..ce0dea54c8 100644 --- a/spec/features/admin/orders_spec.rb +++ b/spec/features/admin/orders_spec.rb @@ -185,6 +185,25 @@ feature %q{ login_to_admin_as @enterprise_user end + context "viewing the edit page" do + before { Rails.application.routes.default_url_options[:host] = "test.host" } + it "shows the dropdown menu" do + distributor1.update_attribute(:abn, '12345678') + order = create(:completed_order_with_totals, distributor: distributor1) + visit spree.admin_order_path(order) + + find("#links-dropdown .ofn_drop_down").click + within "#links-dropdown" do + expect(page).to have_link "Edit", href: spree.edit_admin_order_path(order) + expect(page).to have_link "Resend Confirmation", href: spree.resend_admin_order_path(order) + expect(page).to have_link "Send Invoice", href: spree.invoice_admin_order_path(order) + expect(page).to have_link "Print Invoice", href: spree.print_admin_order_path(order) + # expect(page).to have_link "Ship Order", href: spree.fire_admin_order_path(order, :e => 'ship') + expect(page).to have_link "Cancel Order", href: spree.fire_admin_order_path(order, :e => 'cancel') + end + end + end + scenario "creating an order with distributor and order cycle" do visit '/admin/orders' click_link 'New Order'