diff options
author | georgey@chromium.org <georgey@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-08 21:49:55 +0000 |
---|---|---|
committer | georgey@chromium.org <georgey@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-08 21:49:55 +0000 |
commit | 0d5a3df2a5d0b89305bbad7c0efe8532e1cccb40 (patch) | |
tree | 71b7e6ac126d5511f658246efd03af5ef4cb8e2b | |
parent | 36410e3c67ddc66377f184449cdd1b4bddff75cb (diff) | |
download | chromium_src-0d5a3df2a5d0b89305bbad7c0efe8532e1cccb40.zip chromium_src-0d5a3df2a5d0b89305bbad7c0efe8532e1cccb40.tar.gz chromium_src-0d5a3df2a5d0b89305bbad7c0efe8532e1cccb40.tar.bz2 |
Changed validation based on the discussion
TEST="Save" is always enabled, if user changes address/CC label it changes to "Address"/"Credit Card" after saving
BUG=33026
Review URL: http://codereview.chromium.org/577037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38398 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/generated_resources.grd | 3 | ||||
-rw-r--r-- | chrome/browser/views/autofill_profiles_view_win.cc | 35 | ||||
-rw-r--r-- | chrome/browser/views/autofill_profiles_view_win.h | 6 |
3 files changed, 14 insertions, 30 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 329a033..6515bc3 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4874,6 +4874,9 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_AUTOFILL_NEW_CREDITCARD" desc="The profile label of a new credit card."> New credit card </message> + <message name="IDS_AUTOFILL_UNTITLED_LABEL" desc="The text substituted on empty label"> + Untitled + </message> <message name="IDS_CREDIT_CARD_NUMBER_PREVIEW_FORMAT" desc="Credit card preview format"> <ph name="OBFUSCATED_CC_NUMBER">$1<ex>************1234</ex> diff --git a/chrome/browser/views/autofill_profiles_view_win.cc b/chrome/browser/views/autofill_profiles_view_win.cc index 0784dce..be15e75 100644 --- a/chrome/browser/views/autofill_profiles_view_win.cc +++ b/chrome/browser/views/autofill_profiles_view_win.cc @@ -76,8 +76,7 @@ AutoFillProfilesView::AutoFillProfilesView( const std::vector<CreditCard*>& credit_cards) : observer_(observer), scroll_view_(NULL), - save_changes_(NULL), - data_valid_(true) { + save_changes_(NULL) { profiles_set_.reserve(profiles.size()); for (std::vector<AutoFillProfile*>::const_iterator address_it = profiles.begin(); @@ -124,7 +123,6 @@ void AutoFillProfilesView::AddClicked(EditableSetType item_type) { } else { NOTREACHED(); } - ValidateDataAndUpdateButtons(); scroll_view_->RebuildView(); } @@ -144,7 +142,6 @@ void AutoFillProfilesView::DeleteEditableSet( } else { credit_card_set_.erase(field_set_iterator); } - ValidateDataAndUpdateButtons(); scroll_view_->RebuildView(); } @@ -153,23 +150,19 @@ void AutoFillProfilesView::CollapseStateChanged( scroll_view_->RebuildView(); } -void AutoFillProfilesView::ValidateDataAndUpdateButtons() { - bool valid = true; +void AutoFillProfilesView::ValidateAndFixLabel() { + std::wstring unset_label(l10n_util::GetString(IDS_AUTOFILL_UNTITLED_LABEL)); for (std::vector<EditableSetInfo>::iterator it = profiles_set_.begin(); - it != profiles_set_.end() && valid; + it != profiles_set_.end(); ++it) { if (it->address.Label().empty()) - valid = false; + it->address.set_label(unset_label); } for (std::vector<EditableSetInfo>::iterator it = credit_card_set_.begin(); - it != credit_card_set_.end() && valid; + it != credit_card_set_.end(); ++it) { if (it->credit_card.Label().empty()) - valid = false; - } - if ((data_valid_ && !valid) || (!data_valid_ && valid)) { - data_valid_ = valid; - GetDialogClientView()->UpdateDialogButtons(); + it->credit_card.set_label(unset_label); } } @@ -219,7 +212,6 @@ bool AutoFillProfilesView::IsDialogButtonEnabled( MessageBoxFlags::DialogButton button) const { switch (button) { case MessageBoxFlags::DIALOGBUTTON_OK: - return data_valid(); case MessageBoxFlags::DIALOGBUTTON_CANCEL: return true; default: @@ -244,6 +236,7 @@ views::View* AutoFillProfilesView::GetContentsView() { bool AutoFillProfilesView::Accept() { DCHECK(observer_); + ValidateAndFixLabel(); std::vector<AutoFillProfile> profiles; profiles.reserve(profiles_set_.size()); std::vector<EditableSetInfo>::iterator it; @@ -283,7 +276,7 @@ void AutoFillProfilesView::Init() { views::GridLayout::USE_PREF, 0, 0); layout->StartRow(1, single_column_view_set_id); layout->AddView(scroll_view_); - ValidateDataAndUpdateButtons(); + ValidateAndFixLabel(); } ///////////////////////////////////////////////////////////////////////////// @@ -467,16 +460,11 @@ void AutoFillProfilesView::EditableSetViewContents::ContentsChanged( DCHECK(text_fields_[address_fields_[field].text_field]); if (text_fields_[address_fields_[field].text_field] == sender) { if (address_fields_[field].text_field == TEXT_LABEL) { - bool need_to_revalidate_buttons = - editable_fields_set_->address.Label().empty() || - new_contents.empty(); editable_fields_set_->address.set_label(new_contents); title_label_->SetText(new_contents); // One of the address labels changed - update combo boxes billing_model_->LabelChanged(); shipping_model_->LabelChanged(); - if (need_to_revalidate_buttons) - observer_->ValidateDataAndUpdateButtons(); } else { editable_fields_set_->address.SetInfo( AutoFillType(address_fields_[field].type), new_contents); @@ -489,13 +477,8 @@ void AutoFillProfilesView::EditableSetViewContents::ContentsChanged( DCHECK(text_fields_[credit_card_fields_[field].text_field]); if (text_fields_[credit_card_fields_[field].text_field] == sender) { if (credit_card_fields_[field].text_field == TEXT_LABEL) { - bool need_to_revalidate_buttons = - editable_fields_set_->address.Label().empty() || - new_contents.empty(); editable_fields_set_->credit_card.set_label(new_contents); title_label_->SetText(new_contents); - if (need_to_revalidate_buttons) - observer_->ValidateDataAndUpdateButtons(); } else { editable_fields_set_->credit_card.SetInfo( AutoFillType(credit_card_fields_[field].type), new_contents); diff --git a/chrome/browser/views/autofill_profiles_view_win.h b/chrome/browser/views/autofill_profiles_view_win.h index 6345869..eeb522d 100644 --- a/chrome/browser/views/autofill_profiles_view_win.h +++ b/chrome/browser/views/autofill_profiles_view_win.h @@ -73,9 +73,8 @@ class AutoFillProfilesView : public views::View, // being changed. void CollapseStateChanged( std::vector<EditableSetInfo>::iterator field_set_iterator); - // Validates data and sets data_valid_, to allow or deny save. - void ValidateDataAndUpdateButtons(); - bool data_valid() const { return data_valid_; } + // Validates data and fixes invalid data. + void ValidateAndFixLabel(); // views::View methods: virtual void Layout(); @@ -356,7 +355,6 @@ class AutoFillProfilesView : public views::View, AutoFillDialogObserver* observer_; std::vector<EditableSetInfo> profiles_set_; std::vector<EditableSetInfo> credit_card_set_; - bool data_valid_; views::Button* save_changes_; AutoFillScrollView* scroll_view_; |