1.1 --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Tue Aug 11 14:26:49 2009 +0200
1.2 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Tue Aug 11 14:51:47 2009 +0200
1.3 @@ -45,7 +45,12 @@
1.4 import javax.ws.rs.GET;
1.5 import javax.ws.rs.Path;
1.6 import javax.ws.rs.PathParam;
1.7 +import javax.ws.rs.QueryParam;
1.8 +import javax.ws.rs.core.CacheControl;
1.9 +import javax.ws.rs.core.Context;
1.10 +import javax.ws.rs.core.HttpHeaders;
1.11 import javax.ws.rs.core.MediaType;
1.12 +import javax.ws.rs.core.Request;
1.13 import org.codehaus.jettison.json.JSONArray;
1.14 import org.codehaus.jettison.json.JSONException;
1.15 import org.codehaus.jettison.json.JSONObject;
1.16 @@ -55,15 +60,22 @@
1.17 * @author Jaroslav Tulach <jtulach@netbeans.org>
1.18 */
1.19 @Path("/")
1.20 -@Singleton
1.21 public final class UI {
1.22 private static WebResource base;
1.23 +
1.24 + @Context
1.25 + private Request request;
1.26 + @Context
1.27 + private HttpHeaders headers;
1.28 +
1.29 public UI() {
1.30 }
1.31
1.32 @GET
1.33 - @Path("/")
1.34 public Viewable welcome() throws JSONException {
1.35 + if (headers.getCookies().containsKey("login")) {
1.36 + }
1.37 +
1.38 Object obj = getJson(base.path("games"));
1.39 return new Viewable("index.fmt", obj);
1.40 }
1.41 @@ -72,9 +84,22 @@
1.42 @Path("games/{id}")
1.43 public Viewable board(@PathParam("id") String id) throws JSONException {
1.44 Object obj = convert(base.path("games").path(id).accept(MediaType.TEXT_PLAIN_TYPE).get(String.class));
1.45 + return new Viewable("game.fmt", obj);
1.46 + }
1.47
1.48 - System.err.println("obj: " + obj);
1.49 - return new Viewable("game.fmt", obj);
1.50 + @GET
1.51 + @Path("games/create")
1.52 + public Viewable create(
1.53 + @QueryParam("white") String white,
1.54 + @QueryParam("black") String black
1.55 + ) throws JSONException {
1.56 + Object obj = convert(
1.57 + base.path("games").queryParam("white", white).
1.58 + queryParam("black", black).post(JSONObject.class)
1.59 + );
1.60 + Map<?,?> map = (Map<?,?>)obj;
1.61 + String id = (String)map.get("id");
1.62 + return board(id);
1.63 }
1.64
1.65
2.1 --- a/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Tue Aug 11 14:26:49 2009 +0200
2.2 +++ b/freemarkerdor/src/main/resources/cz/xelfi/quoridor/freemarkerdor/UI/index.fmt Tue Aug 11 14:51:47 2009 +0200
2.3 @@ -12,5 +12,10 @@
2.4 <li>${item.white} vs. ${item.black} <a href="games/${item.id}">board</a></li>
2.5 </#list>
2.6 </ol>
2.7 + <form action="games/create">
2.8 + White: <input type="text" name="white" value="" />
2.9 + Black: <input type="text" name="black" value="" />
2.10 + <input type="submit" value="Create!" />
2.11 + </form>
2.12 </body>
2.13 </html>
2.14 \ No newline at end of file