Adding user autocomplete directive to speed up specification of owner for enterprises

This commit is contained in:
Rob H
2014-08-29 23:37:25 +10:00
parent 73a32fdaf1
commit 13d814ff23
7 changed files with 32 additions and 12 deletions

View File

@@ -22,5 +22,6 @@
//= require ./payment_methods/payment_methods
//= require ./products/products
//= require ./shipping_methods/shipping_methods
//= require ./users/users
//= require_tree .

View File

@@ -1 +1 @@
angular.module("admin.enterprises", ["admin.payment_methods", "admin.shipping_methods"])
angular.module("admin.enterprises", ["admin.payment_methods", "admin.shipping_methods", "admin.users"])

View File

@@ -0,0 +1,19 @@
angular.module("admin.users").directive "ofnUserAutocomplete", ($http) ->
link: (scope,element,attrs) ->
setTimeout ->
element.select2
multiple: false
initSelection: (element, callback) ->
$http.get( Spree.url(Spree.routes.user_search, { ids: element.val() }) ).success (data) ->
callback(data[0]) if data.length > 0
ajax:
url: Spree.routes.user_search
datatype: 'json'
data:(term, page) ->
{ q: term }
results: (data, page) ->
{ results: data }
formatResult: (user) ->
user.email
formatSelection: (user) ->
user.email

View File

@@ -0,0 +1 @@
angular.module("admin.users", [])

View File

@@ -23,11 +23,11 @@
- if spree_current_user.admin?
.row
.three.columns.alpha
%label Owner
=f.label :owner_id, 'Owner'
.with-tip{'data-powertip' => "The primary user responsible for this enterprise."}
%a What's this?
.eight.columns
= f.collection_select :owner_id, Spree::User.all, :id, :email, {}, :class => "select2 fullwidth"
= f.hidden_field :owner_id, class: "select2 fullwidth", 'ofn-user-autocomplete' => true
.row
.three.columns.alpha

View File

@@ -64,7 +64,7 @@ feature %q{
page.should have_content e.name
end
scenario "creating a new enterprise" do
scenario "creating a new enterprise", js:true do
eg1 = create(:enterprise_group, name: 'eg1')
eg2 = create(:enterprise_group, name: 'eg2')
payment_method = create(:payment_method)
@@ -73,8 +73,7 @@ feature %q{
# Navigating
admin = quick_login_as_admin
visit '/admin/enterprises'
click_link 'New Enterprise'
visit '/admin/enterprises/new'
# Checking shipping and payment method sidebars work
uncheck 'enterprise_is_primary_producer'
@@ -84,11 +83,11 @@ feature %q{
# Filling in details
fill_in 'enterprise_name', :with => 'Eaterprises'
select admin.email, from: 'enterprise_own/er_id'
select2_search admin.email, from: 'Owner'
choose 'Full'
check "enterprise_payment_method_ids_#{payment_method.id}"
check "enterprise_shipping_method_ids_#{shipping_method.id}"
select eg1.name, from: 'enterprise_group_ids'
select2_search eg1.name, from: 'Groups'
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'
@@ -102,8 +101,8 @@ feature %q{
fill_in 'enterprise_address_attributes_address1', :with => '35 Ballantyne St'
fill_in 'enterprise_address_attributes_city', :with => 'Thornbury'
fill_in 'enterprise_address_attributes_zipcode', :with => '3072'
select('Australia', :from => 'enterprise_address_attributes_country_id')
select('Victoria', :from => 'enterprise_address_attributes_state_id')
select2_search 'Australia', :from => 'Country'
select2_search 'Victoria', :from => 'State'
fill_in 'enterprise_description', :with => 'Connecting farmers and eaters'
fill_in 'enterprise_long_description', :with => 'Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro.'

View File

@@ -6,7 +6,7 @@ module AuthenticationWorkflow
def quick_login_as_admin
admin_role = Spree::Role.find_or_create_by_name!('admin')
admin_user = create(:user,
admin_user = create(:user,
:password => 'passw0rd',
:password_confirmation => 'passw0rd',
:remember_me => false,
@@ -25,7 +25,7 @@ module AuthenticationWorkflow
def login_to_admin_section
admin_role = Spree::Role.find_or_create_by_name!('admin')
admin_user = create(:user,
admin_user = create(:user,
:password => 'passw0rd',
:password_confirmation => 'passw0rd',
:remember_me => false,