Skip to content

Commit

Permalink
gwt: Transmit locale information to services.py to receive translated…
Browse files Browse the repository at this point in the history
… info.
  • Loading branch information
calin-iorgulescu committed Jan 13, 2015
1 parent 74ddbc4 commit 23d0e36
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@
import com.google.gwt.http.client.Response;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.http.client.URL;
import com.google.gwt.i18n.client.LocaleInfo;

public class Delegate<T> {

public static final int requestTimeoutMillis = 10000; /* 10 seconds */

private HandlerManager eventBus;
private RequestBuilder rb;
private boolean isGet;
private boolean isGet, attachLocale;
private String url;

public Delegate(HandlerManager eventBus, String url, boolean isGet) {
public Delegate(HandlerManager eventBus, String url, boolean isGet, boolean attachLocale) {
this.eventBus = eventBus;
this.isGet = isGet;
this.attachLocale = attachLocale;
this.url = url;
/**
* We reconstruct the entire RequestBuilder for GET requests when
Expand All @@ -54,6 +56,13 @@ private String packParameters(HashMap<String, String> params) {
result.append('&');
}
}

if (attachLocale) {
result.append('&');
result.append(URL.encodeComponent("locale", true) + "=" +
URL.encodeComponent(LocaleInfo.getCurrentLocale().getLocaleName(), true));
}

return result.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ public HTTPService(HandlerManager eventBus) {
}

public void getCourses(final AsyncCallback<Course[]> callback) {
Delegate<Course[]> delegate = new Delegate<Course[]>(eventBus, GET_COURSES_URL, true);
Delegate<Course[]> delegate = new Delegate<Course[]>(eventBus, GET_COURSES_URL, true, false);
delegate.sendRequest(callback, new CoursesListDecoder(), null);
}

public void getAssignments(String courseId, final AsyncCallback<Assignment[]> callback) {
Delegate<Assignment[]> delegate =
new Delegate<Assignment[]>(eventBus, GET_ASSIGNMENTS_URL, true);
new Delegate<Assignment[]>(eventBus, GET_ASSIGNMENTS_URL, true, false);
HashMap<String, String> params = new HashMap<String, String>();
params.put("courseId", courseId);
delegate.sendRequest(callback, new AssignmentsListDecoder(), params);
Expand All @@ -75,7 +75,7 @@ public void getAssignments(String courseId, final AsyncCallback<Assignment[]> ca
public void getResults(String courseId, String assignmentId,
final AsyncCallback<EvaluationResult[]> callback) {
Delegate<EvaluationResult[]> delegate =
new Delegate<EvaluationResult[]>(eventBus, GET_RESULTS_URL, true);
new Delegate<EvaluationResult[]>(eventBus, GET_RESULTS_URL, true, true);
HashMap<String, String> params = new HashMap<String, String>();
params.put("courseId", courseId);
params.put("assignmentId", assignmentId);
Expand All @@ -85,7 +85,7 @@ public void getResults(String courseId, String assignmentId,
public void getUploadedMd5(String courseId, String assignmentId,
final AsyncCallback<Md5Status> callback) {
Delegate<Md5Status> delegate =
new Delegate<Md5Status>(eventBus, GET_UPLOADED_MD5_URL, true);
new Delegate<Md5Status>(eventBus, GET_UPLOADED_MD5_URL, true, false);
HashMap<String, String> params = new HashMap<String, String>();
params.put("courseId", courseId);
params.put("assignmentId", assignmentId);
Expand All @@ -95,7 +95,7 @@ public void getUploadedMd5(String courseId, String assignmentId,
public void getStorageDirContents(String courseId, String assignmentId,
final AsyncCallback<FileList> callback) {
Delegate<FileList> delegate =
new Delegate<FileList>(eventBus, GET_STORAGE_FILE_LIST_URL, true);
new Delegate<FileList>(eventBus, GET_STORAGE_FILE_LIST_URL, true, false);
HashMap<String, String> params = new HashMap<String, String>();
params.put("courseId", courseId);
params.put("assignmentId", assignmentId);
Expand All @@ -105,7 +105,7 @@ public void getStorageDirContents(String courseId, String assignmentId,
public void getUserResults(String courseId, String assignmentId, String username,
final AsyncCallback<EvaluationResult[]> callback) {
Delegate<EvaluationResult[]> delegate =
new Delegate<EvaluationResult[]>(eventBus, GET_USER_RESULTS_URL, true);
new Delegate<EvaluationResult[]>(eventBus, GET_USER_RESULTS_URL, true, true);
HashMap<String, String> params = new HashMap<String, String>();
params.put("courseId", courseId);
params.put("assignmentId", assignmentId);
Expand All @@ -115,7 +115,7 @@ public void getUserResults(String courseId, String assignmentId, String username

public void getAllResults(String courseId, final AsyncCallback<StudentInfo[]> callback) {
Delegate<StudentInfo[]> delegate =
new Delegate<StudentInfo[]>(eventBus, GET_ALL_RESULTS_URL, true);
new Delegate<StudentInfo[]>(eventBus, GET_ALL_RESULTS_URL, true, false);
HashMap<String, String> params = new HashMap<String, String>();
params.put("courseId", courseId);
delegate.sendRequest(callback, new StatisticsDecoder(), params);
Expand All @@ -124,15 +124,15 @@ public void getAllResults(String courseId, final AsyncCallback<StudentInfo[]> ca
public void performAuthentication(String username, String password,
final AsyncCallback<AuthenticationResponse> callback) {
Delegate<AuthenticationResponse> delegate =
new Delegate<AuthenticationResponse>(eventBus, PERFORM_AUTHENTICATION_URL, false);
new Delegate<AuthenticationResponse>(eventBus, PERFORM_AUTHENTICATION_URL, false, true);
HashMap<String, String> params = new HashMap<String, String>();
params.put("username", username);
params.put("password", password);
delegate.sendRequest(callback, new AuthenticationResponseDecoder(), params);
}

public void sendLogoutRequest(final AsyncCallback<Boolean> callback) {
Delegate<Boolean> delegate = new Delegate<Boolean>(eventBus, LOGOUT_URL, true);
Delegate<Boolean> delegate = new Delegate<Boolean>(eventBus, LOGOUT_URL, true, false);
delegate.sendRequest(callback, new NullDecoder(), null);
}

Expand Down

0 comments on commit 23d0e36

Please sign in to comment.