diff --git a/app/assets/javascripts/admin/checkouts/edit_override.js b/app/assets/javascripts/admin/checkouts/edit_override.js deleted file mode 100644 index 08072d3cd7..0000000000 --- a/app/assets/javascripts/admin/checkouts/edit_override.js +++ /dev/null @@ -1,53 +0,0 @@ -$(document).ready(function() { - if ($("#customer_search_override").length > 0) { - $("#customer_search_override").select2({ - placeholder: Spree.translations.choose_a_customer, - ajax: { - url: '/admin/search/customers.json', // modified - datatype: 'json', - data: function(term, page) { - return { q: term, distributor_id: $('#distributor_id').val() } // modified - }, - results: function(data, page) { - return { results: data } - } - }, - dropdownCssClass: 'customer_search', - formatResult: formatCustomerResult, - formatSelection: function (customer) { - _.each(['bill_address', 'ship_address'], function(address) { - var data = customer[address]; - address_parts = ['firstname', 'lastname', - 'company', 'address1', - 'address2', 'city', - 'zipcode', 'phone'] - var attribute_wrapper = '#order_' + address + '_attributes_' - if(data != undefined) { - _.each(address_parts, function(part) { - $(attribute_wrapper + part).val(data[part]); - }) - - $(attribute_wrapper + 'state_id').select2("val", data['state_id']); - $(attribute_wrapper + 'country_id').select2("val", data['country_id']); - } - else { - _.each(address_parts, function(part) { - $(attribute_wrapper + part).val(""); - }) - - $(attribute_wrapper + 'state_id').select2("val", ''); - $(attribute_wrapper + 'country_id').select2("val", ''); - } - }); - - $('#order_email').val(customer.email); - $('#user_id').val(customer.user_id); // modified - $('#guest_checkout_true').prop("checked", false); - $('#guest_checkout_false').prop("checked", true); - $('#guest_checkout_false').prop("disabled", false); - - return customer.email; - } - }) - } -}) diff --git a/app/assets/javascripts/admin/orders/directives/customer_search_override.js.coffee b/app/assets/javascripts/admin/orders/directives/customer_search_override.js.coffee new file mode 100644 index 0000000000..b091342f96 --- /dev/null +++ b/app/assets/javascripts/admin/orders/directives/customer_search_override.js.coffee @@ -0,0 +1,61 @@ +angular.module("admin.orders").directive 'customerSearchOverride', -> + restrict: 'C' + link: (scope, element, attr) -> + console.log('customerSearchOverride C') + formatCustomerResult = (customer) -> + customerTemplate + customer: customer + bill_address: customer.bill_address + ship_address: customer.ship_address + + element.select2 + placeholder: Spree.translations.choose_a_customer + ajax: + url: '/admin/search/customers.json' + datatype: 'json' + data: (term, page) -> + { + q: term + distributor_id: $('#distributor_id').val() # modified + } + results: (data, page) -> + { results: data } + dropdownCssClass: 'customer_search' + formatResult: formatCustomerResult + formatSelection: (customer) -> + _.each [ + 'bill_address' + 'ship_address' + ], (address) -> + data = customer[address] + address_parts = [ + 'firstname' + 'lastname' + 'company' + 'address1' + 'address2' + 'city' + 'zipcode' + 'phone' + ] + attribute_wrapper = '#order_' + address + '_attributes_' + if data # modified + console.log('xiebing') + _.each address_parts, (part) -> + $(attribute_wrapper + part).val data[part] + return + $(attribute_wrapper + 'state_id').select2 'val', data['state_id'] + $(attribute_wrapper + 'country_id').select2 'val', data['country_id'] + else + _.each address_parts, (part) -> + $(attribute_wrapper + part).val '' + return + $(attribute_wrapper + 'state_id').select2 'val', '' + $(attribute_wrapper + 'country_id').select2 'val', '' + return + $('#order_email').val customer.email + $('#user_id').val customer.user_id # modified + $('#guest_checkout_true').prop 'checked', false + $('#guest_checkout_false').prop 'checked', true + $('#guest_checkout_false').prop 'disabled', false + customer.email diff --git a/app/overrides/spree/admin/orders/customer_details/edit/replace_customer_search.html.haml.deface b/app/overrides/spree/admin/orders/customer_details/edit/replace_customer_search.html.haml.deface index d253348656..db8cebfb0e 100644 --- a/app/overrides/spree/admin/orders/customer_details/edit/replace_customer_search.html.haml.deface +++ b/app/overrides/spree/admin/orders/customer_details/edit/replace_customer_search.html.haml.deface @@ -1,5 +1,8 @@ / replace "code[erb-loud]:contains('hidden_field_tag :customer_search')" -= hidden_field_tag :customer_search_override, nil, :class => 'fullwidth title' +- content_for :app_wrapper_attrs do + = 'ng-app=admin.orders' + += hidden_field_tag :customer_search_override, nil, :class => 'fullwidth title customer-search-override' = hidden_field_tag :distributor_id, @order.distributor_id