From e5d7b545c93cf9584e94673d7e90a00ba39844f7 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 24 Aug 2016 10:43:50 +1000 Subject: [PATCH] I18n and refactoring --- .../directives/edit_address_dialog.js.coffee | 12 ++++++------ .../admin/customers/services/customers.js.coffee | 4 ++-- .../templates/admin/edit_address_dialog.html.haml | 11 +++++++---- app/views/admin/customers/index.html.haml | 4 ++-- config/locales/en.yml | 8 ++++++++ 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/admin/customers/directives/edit_address_dialog.js.coffee b/app/assets/javascripts/admin/customers/directives/edit_address_dialog.js.coffee index c81f187ef3..5fb55eaeba 100644 --- a/app/assets/javascripts/admin/customers/directives/edit_address_dialog.js.coffee +++ b/app/assets/javascripts/admin/customers/directives/edit_address_dialog.js.coffee @@ -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() diff --git a/app/assets/javascripts/admin/customers/services/customers.js.coffee b/app/assets/javascripts/admin/customers/services/customers.js.coffee index 90833cd5a1..f4c6f6f3cd 100644 --- a/app/assets/javascripts/admin/customers/services/customers.js.coffee +++ b/app/assets/javascripts/admin/customers/services/customers.js.coffee @@ -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 diff --git a/app/assets/javascripts/templates/admin/edit_address_dialog.html.haml b/app/assets/javascripts/templates/admin/edit_address_dialog.html.haml index 05010a8708..351a267bd3 100644 --- a/app/assets/javascripts/templates/admin/edit_address_dialog.html.haml +++ b/app/assets/javascripts/templates/admin/edit_address_dialog.html.haml @@ -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'} diff --git a/app/views/admin/customers/index.html.haml b/app/views/admin/customers/index.html.haml index d6156fd22d..7e08c2e4b3 100644 --- a/app/views/admin/customers/index.html.haml +++ b/app/views/admin/customers/index.html.haml @@ -86,9 +86,9 @@ .tag_watcher{ 'obj-for-update' => "customer", "attr-for-update" => "tag_list"} %tags_with_translation{ object: 'customer', 'find-tags' => 'findTags(query)' } %td.bill_address{ 'ng-show' => 'columns.bill_address.visible' } - %a{ id: 'bill-address-link', href: '#', "ng-bind" => "customer.bill_address ? customer.bill_address.address1 : 'Edit' | limitTo: 15", 'edit-address-dialog' => true } + %a{ id: 'bill-address-link', href: '#', "ng-bind" => "customer.bill_address ? customer.bill_address.address1 : '#{t('admin.customers.index.edit')}' | limitTo: 15", 'edit-address-dialog' => true } %td.ship_address{ 'ng-show' => 'columns.ship_address.visible' } - %a{ id: 'ship-address-link', href: '#', "ng-bind" => "customer.ship_address ? customer.ship_address.address1 : 'Edit' | limitTo: 15", 'edit-address-dialog' => true } + %a{ id: 'ship-address-link', href: '#', "ng-bind" => "customer.ship_address ? customer.ship_address.address1 : '#{t('admin.customers.index.edit')}' | limitTo: 15", 'edit-address-dialog' => true } %td.actions %a{ 'ng-click' => "deleteCustomer(customer)", :class => "delete-customer icon-trash no-text" } diff --git a/config/locales/en.yml b/config/locales/en.yml index bff650be2b..b74f62ed8c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -120,6 +120,14 @@ en: duplicate_code: "This code is used already." bill_address: "Billing Address" ship_address: "Shipping Address" + update_address_success: 'Address updated successfully.' + update_address_error: 'Sorry! Please input all of the required fields!' + edit_bill_address: 'Edit Billing Address' + edit_ship_address: 'Edit Shipping Address' + required_fileds: 'Required fields are denoted with an asterisk ' + select_country: 'Select Country' + select_state: 'Select State' + edit: 'Edit' products: bulk_edit: