Adding actions dropdown to admin order view/pages

This commit is contained in:
Rob Harrington
2015-12-11 22:20:59 +11:00
parent ae0ad73b4a
commit e6a51bb49d
12 changed files with 91 additions and 15 deletions

View File

@@ -0,0 +1,5 @@
angular.module("admin.dropdown").directive "linksDropdown", ($window)->
restrict: "C"
scope:
links: "="
templateUrl: "admin/links_dropdown.html"

View File

@@ -1 +1 @@
angular.module("admin.dropdown", [])
angular.module("admin.dropdown", ['templates'])

View File

@@ -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 }}

View File

@@ -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;

View File

@@ -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

View File

@@ -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'])

View File

@@ -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) }

View File

@@ -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) }

View File

@@ -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'])

View File

@@ -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"

View File

@@ -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

View File

@@ -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'