OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/payments/contact_info_editor_view_controller.h
" | 5 #include "chrome/browser/ui/views/payments/contact_info_editor_view_controller.h
" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/ui/views/payments/validating_textfield.h" | 10 #include "chrome/browser/ui/views/payments/validating_textfield.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 *profile_to_edit_, state()->GetApplicationLocale()); | 75 *profile_to_edit_, state()->GetApplicationLocale()); |
76 } | 76 } |
77 | 77 |
78 return profile_to_edit_->GetInfo(autofill::AutofillType(type), | 78 return profile_to_edit_->GetInfo(autofill::AutofillType(type), |
79 state()->GetApplicationLocale()); | 79 state()->GetApplicationLocale()); |
80 } | 80 } |
81 | 81 |
82 bool ContactInfoEditorViewController::ValidateModelAndSave() { | 82 bool ContactInfoEditorViewController::ValidateModelAndSave() { |
83 // TODO(crbug.com/712224): Move this method and its helpers to a base class | 83 // TODO(crbug.com/712224): Move this method and its helpers to a base class |
84 // shared with the Shipping Address editor. | 84 // shared with the Shipping Address editor. |
85 if (!ValidateModel()) | 85 if (!ValidateInputFields()) |
86 return false; | 86 return false; |
87 | 87 |
88 if (profile_to_edit_) { | 88 if (profile_to_edit_) { |
89 PopulateProfile(profile_to_edit_); | 89 PopulateProfile(profile_to_edit_); |
90 state()->GetPersonalDataManager()->UpdateProfile(*profile_to_edit_); | 90 state()->GetPersonalDataManager()->UpdateProfile(*profile_to_edit_); |
91 state()->profile_comparator()->Invalidate(*profile_to_edit_); | 91 state()->profile_comparator()->Invalidate(*profile_to_edit_); |
92 std::move(on_edited_).Run(); | 92 std::move(on_edited_).Run(); |
93 on_added_.Reset(); | 93 on_added_.Reset(); |
94 } else { | 94 } else { |
95 std::unique_ptr<autofill::AutofillProfile> profile = | 95 std::unique_ptr<autofill::AutofillProfile> profile = |
(...skipping 22 matching lines...) Expand all Loading... |
118 | 118 |
119 base::string16 ContactInfoEditorViewController::GetSheetTitle() { | 119 base::string16 ContactInfoEditorViewController::GetSheetTitle() { |
120 // TODO(crbug.com/712074): Title should reflect the missing information, if | 120 // TODO(crbug.com/712074): Title should reflect the missing information, if |
121 // applicable. | 121 // applicable. |
122 return profile_to_edit_ ? l10n_util::GetStringUTF16( | 122 return profile_to_edit_ ? l10n_util::GetStringUTF16( |
123 IDS_PAYMENTS_EDIT_CONTACT_DETAILS_LABEL) | 123 IDS_PAYMENTS_EDIT_CONTACT_DETAILS_LABEL) |
124 : l10n_util::GetStringUTF16( | 124 : l10n_util::GetStringUTF16( |
125 IDS_PAYMENTS_ADD_CONTACT_DETAILS_LABEL); | 125 IDS_PAYMENTS_ADD_CONTACT_DETAILS_LABEL); |
126 } | 126 } |
127 | 127 |
128 bool ContactInfoEditorViewController::ValidateModel() { | |
129 for (const auto& field : text_fields()) { | |
130 // Force a blur, as validation only occurs after the first blur. | |
131 field.first->OnBlur(); | |
132 if (field.first->invalid()) | |
133 return false; | |
134 } | |
135 return true; | |
136 } | |
137 | |
138 void ContactInfoEditorViewController::PopulateProfile( | 128 void ContactInfoEditorViewController::PopulateProfile( |
139 autofill::AutofillProfile* profile) { | 129 autofill::AutofillProfile* profile) { |
140 for (const auto& field : text_fields()) { | 130 for (const auto& field : text_fields()) { |
141 profile->SetInfo(autofill::AutofillType(field.second.type), | 131 profile->SetInfo(autofill::AutofillType(field.second.type), |
142 field.first->text(), state()->GetApplicationLocale()); | 132 field.first->text(), state()->GetApplicationLocale()); |
143 } | 133 } |
144 profile->set_origin(autofill::kSettingsOrigin); | 134 profile->set_origin(autofill::kSettingsOrigin); |
145 } | 135 } |
146 | 136 |
147 bool ContactInfoEditorViewController::GetSheetId(DialogViewID* sheet_id) { | 137 bool ContactInfoEditorViewController::GetSheetId(DialogViewID* sheet_id) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 } | 239 } |
250 | 240 |
251 bool ContactInfoEditorViewController::ContactInfoValidationDelegate:: | 241 bool ContactInfoEditorViewController::ContactInfoValidationDelegate:: |
252 ComboboxValueChanged(views::Combobox* combobox) { | 242 ComboboxValueChanged(views::Combobox* combobox) { |
253 // This UI doesn't contain any comboboxes. | 243 // This UI doesn't contain any comboboxes. |
254 NOTREACHED(); | 244 NOTREACHED(); |
255 return true; | 245 return true; |
256 } | 246 } |
257 | 247 |
258 } // namespace payments | 248 } // namespace payments |
OLD | NEW |