UiCommand: support confirmation message
For some commands, like "Delete-Project", a confirmation dialog must be shown. Add a support for it in UiCommand. If confirmation message is null or empty no confirmation dialog is shown. If user cancel confirmation dialog, no action is triggered. Change-Id: I2b1e4759b488a3b5079fdb54c6c862ab59397ddf
This commit is contained in:
parent
32259c663c
commit
130c551800
@ -21,4 +21,5 @@ public class UiCommandDetail {
|
||||
public String label;
|
||||
public String title;
|
||||
public boolean enabled;
|
||||
public String confirmationMessage;
|
||||
}
|
||||
|
@ -29,4 +29,5 @@ public interface UiCommand<R extends RestResource> extends RestView<R> {
|
||||
String getTitle(R resource);
|
||||
boolean isVisible(R resource);
|
||||
boolean isEnabled(R resource);
|
||||
String getConfirmationMessage(R resource);
|
||||
}
|
||||
|
@ -13,6 +13,8 @@
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.client.changes;
|
||||
import com.google.gerrit.client.ConfirmationCallback;
|
||||
import com.google.gerrit.client.ConfirmationDialog;
|
||||
import com.google.gerrit.client.Dispatcher;
|
||||
import com.google.gerrit.client.ErrorDialog;
|
||||
import com.google.gerrit.client.FormatUtil;
|
||||
@ -55,6 +57,7 @@ import com.google.gwt.user.client.ui.Image;
|
||||
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
|
||||
import com.google.gwt.user.client.ui.InlineLabel;
|
||||
import com.google.gwt.user.client.ui.Panel;
|
||||
import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
|
||||
import com.google.gwtjsonrpc.common.VoidResult;
|
||||
|
||||
import java.util.HashSet;
|
||||
@ -555,6 +558,24 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel
|
||||
b.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(final ClickEvent event) {
|
||||
if (cmd.confirmationMessage != null &&
|
||||
!cmd.confirmationMessage.isEmpty()) {
|
||||
ConfirmationDialog confirmationDialog = new ConfirmationDialog(
|
||||
cmd.title, new SafeHtmlBuilder().append(cmd.confirmationMessage),
|
||||
new ConfirmationCallback() {
|
||||
@Override
|
||||
public void onOk() {
|
||||
postProcessCommand(cmd, b);
|
||||
}
|
||||
});
|
||||
confirmationDialog.center();
|
||||
} else {
|
||||
postProcessCommand(cmd, b);
|
||||
}
|
||||
}
|
||||
|
||||
private void postProcessCommand(final UiCommandDetail cmd,
|
||||
final Button b) {
|
||||
b.setEnabled(false);
|
||||
AsyncCallback<NativeString> cb =
|
||||
new AsyncCallback<NativeString>() {
|
||||
|
@ -111,6 +111,7 @@ public class UiCommands {
|
||||
dsc.label = cmd.getLabel(resource);
|
||||
dsc.title = cmd.getTitle(resource);
|
||||
dsc.enabled = cmd.isEnabled(resource);
|
||||
dsc.confirmationMessage = cmd.getConfirmationMessage(resource);
|
||||
return dsc;
|
||||
}
|
||||
}),
|
||||
|
Loading…
Reference in New Issue
Block a user