I18n and refactoring

This commit is contained in:
Bing Xie
2016-08-24 10:43:50 +10:00
parent ed1f05e674
commit e5d7b545c9
5 changed files with 25 additions and 14 deletions

View File

@@ -11,12 +11,12 @@ angular.module("admin.customers").directive 'editAddressDialog', ($compile, $tem
scope.updateAddress = ->
scope.edit_address_form.$setPristine()
if scope.edit_address_form.$valid
Customers.update(scope.address, scope.customer, scope.current_address).$promise.then (data) ->
Customers.update(scope.address, scope.customer, scope.addressType).$promise.then (data) ->
scope.customer = data
template.dialog('close')
StatusMessage.display('success', "Address updated successfully.")
StatusMessage.display('success', t('admin.customers.index.update_address_success'))
else
scope.errors.push("Sorry! Please input all of the required fields!")
scope.errors.push(t('admin.customers.index.update_address_error'))
template = $compile($templateCache.get('admin/edit_address_dialog.html'))(scope)
@@ -24,10 +24,10 @@ angular.module("admin.customers").directive 'editAddressDialog', ($compile, $tem
element.bind 'click', (e) ->
if e.target.id == 'bill-address-link'
scope.current_address = 'bill_address'
scope.addressType = 'bill_address'
else
scope.current_address = 'ship_address'
scope.address = scope.customer[scope.current_address]
scope.addressType = 'ship_address'
scope.address = scope.customer[scope.addressType]
template.dialog('open')
scope.$apply()

View File

@@ -26,10 +26,10 @@ angular.module("admin.customers").factory "Customers", ($q, InfoDialog, RequestM
RequestMonitor.load(request.$promise)
request.$promise
update: (address, customer, current_address) ->
update: (address, customer, addressType) ->
params =
id: customer.id
customer:
"#{current_address}_attributes": address
"#{addressType}_attributes": address
CustomerResource.update params

View File

@@ -1,8 +1,9 @@
#edit-address-dialog
%h2 {{ current_address === 'bill_address' ? 'Edit Billing Address' : 'Edit Shipping Address'}}
%h2 {{ addressType === 'bill_address' ? "#{t('admin.customers.index.edit_bill_address')}" : "#{t('admin.customers.index.edit_ship_address')}" }}
%form{ name: 'edit_address_form', novalidate: true, ng: { submit: 'updateAddress()'}}
.row
Required fields are denoted with an asterisk (
= t('admin.customers.index.required_fileds')
(
%span.required *
)
.error{ ng: { repeat: "error in errors", bind: "error" } }
@@ -43,14 +44,16 @@
%span.required *
%td
%select{name: 'country', required: true, ng: {model: 'address.country_id', options: 'country.id as country.name for country in availableCountries'}}
%option{value: ''} Select Country
%option{value: ''}
= t('admin.customers.index.select_country')
%tr
%td
= t('spree.state')
%span.required *
%td
%select{name: 'state', required: true, ng: {model: 'address.state_id', options: 'state.id as state.name for state in states'}}
%option{value: ''} Select State
%option{value: ''}
= t('admin.customers.index.select_state')
.text-center
%input.button.red.icon-plus{ type: 'submit', value: 'Update Address'}