Commit 67e7d0ae authored by siyua's avatar siyua Committed by Commit Bot

Disable the save button if all checkboxes are unchecked

In the migration dialog, previously the user could click the save button
if the user decided to upload no cards, in which case, we would
still send a no-op Rpc call to Payments.

This was not an ideal situation. Instead, we would disable the save
button and the user can click the cancel button to quit the flow.

Bug: 852904
Change-Id: I6a1e005a63b19046728568b4ce08755616361e08
Reviewed-on: https://chromium-review.googlesource.com/c/1255608
Commit-Queue: Siyu An <siyua@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596041}
parent c6b5fd71
...@@ -94,7 +94,7 @@ void LocalCardMigrationDialogView::OnMigrationFinished() { ...@@ -94,7 +94,7 @@ void LocalCardMigrationDialogView::OnMigrationFinished() {
} }
const std::vector<std::string> const std::vector<std::string>
LocalCardMigrationDialogView::GetSelectedCardGuids() { LocalCardMigrationDialogView::GetSelectedCardGuids() const {
std::vector<std::string> selected_cards; std::vector<std::string> selected_cards;
for (int index = 0; index < card_list_view_->child_count(); ++index) { for (int index = 0; index < card_list_view_->child_count(); ++index) {
MigratableCardView* card = MigratableCardView* card =
...@@ -142,7 +142,14 @@ base::string16 LocalCardMigrationDialogView::GetDialogButtonLabel( ...@@ -142,7 +142,14 @@ base::string16 LocalCardMigrationDialogView::GetDialogButtonLabel(
bool LocalCardMigrationDialogView::IsDialogButtonEnabled( bool LocalCardMigrationDialogView::IsDialogButtonEnabled(
ui::DialogButton button) const { ui::DialogButton button) const {
// The buttons will be disabled when card uploading is in progress. // The buttons will be disabled when card uploading is in progress.
return !migration_pending_; if (migration_pending_)
return false;
// If all checkboxes are unchecked, disable the save button.
if (button == ui::DIALOG_BUTTON_OK)
return !GetSelectedCardGuids().empty();
return true;
} }
bool LocalCardMigrationDialogView::Accept() { bool LocalCardMigrationDialogView::Accept() {
...@@ -182,6 +189,11 @@ void LocalCardMigrationDialogView::ButtonPressed(views::Button* sender, ...@@ -182,6 +189,11 @@ void LocalCardMigrationDialogView::ButtonPressed(views::Button* sender,
// dialog. // dialog.
if (sender == close_migration_dialog_button_) { if (sender == close_migration_dialog_button_) {
CloseDialog(); CloseDialog();
} else {
// Otherwise it is a checkbox just clicked. Enable/disable the save
// button if needed.
DCHECK_EQ(sender->GetClassName(), views::Checkbox::kViewClassName);
DialogModelChanged();
} }
} }
......
...@@ -77,7 +77,7 @@ class LocalCardMigrationDialogView : public LocalCardMigrationDialog, ...@@ -77,7 +77,7 @@ class LocalCardMigrationDialogView : public LocalCardMigrationDialog,
void SetMigrationIsPending(bool is_pending); void SetMigrationIsPending(bool is_pending);
void ShowCloseButton(); void ShowCloseButton();
void UpdateDialogToPendingView(); void UpdateDialogToPendingView();
const std::vector<std::string> GetSelectedCardGuids(); const std::vector<std::string> GetSelectedCardGuids() const;
LocalCardMigrationDialogController* controller_; LocalCardMigrationDialogController* controller_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment