Refactor default change and project callbacks
Reuse the same callback implementation for both types, passing in a default target to redirect to if no message is returned. Change-Id: I5a9dfde5e81d8c5c6a76fe082905dbf09fb944fb
This commit is contained in:
@@ -21,7 +21,6 @@ import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.rpc.NativeString;
|
||||
import com.google.gerrit.client.rpc.RestApi;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.user.client.Window;
|
||||
@@ -29,24 +28,15 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
class DefaultActions {
|
||||
static void invoke(ChangeInfo change, ActionInfo action, RestApi api) {
|
||||
final Change.Id id = change.legacy_id();
|
||||
AsyncCallback<JavaScriptObject> cb = new GerritCallback<JavaScriptObject>() {
|
||||
@Override
|
||||
public void onSuccess(JavaScriptObject msg) {
|
||||
if (NativeString.is(msg)) {
|
||||
NativeString str = (NativeString) msg;
|
||||
if (!str.asString().isEmpty()) {
|
||||
Window.alert(str.asString());
|
||||
}
|
||||
}
|
||||
Gerrit.display(PageLinks.toChange(id));
|
||||
}
|
||||
};
|
||||
invoke(action, api, cb);
|
||||
invoke(action, api, callback(PageLinks.toChange(change.legacy_id())));
|
||||
}
|
||||
|
||||
static void invoke(final Project.NameKey project, ActionInfo action, RestApi api) {
|
||||
AsyncCallback<JavaScriptObject> cb = new GerritCallback<JavaScriptObject>() {
|
||||
static void invoke(Project.NameKey project, ActionInfo action, RestApi api) {
|
||||
invoke(action, api, callback(PageLinks.toProject(project)));
|
||||
}
|
||||
|
||||
private static AsyncCallback<JavaScriptObject> callback(final String target) {
|
||||
return new GerritCallback<JavaScriptObject>() {
|
||||
@Override
|
||||
public void onSuccess(JavaScriptObject msg) {
|
||||
if (NativeString.is(msg)) {
|
||||
@@ -55,10 +45,9 @@ class DefaultActions {
|
||||
Window.alert(str.asString());
|
||||
}
|
||||
}
|
||||
Gerrit.display(PageLinks.toProject(project));
|
||||
Gerrit.display(target);
|
||||
}
|
||||
};
|
||||
invoke(action, api, cb);
|
||||
}
|
||||
|
||||
private static void invoke(ActionInfo action, RestApi api,
|
||||
|
||||
Reference in New Issue
Block a user